LdapRoleAuthenticationFilter extends OncePerRequestFilter { @Override protected boolean shouldNotFilter(final HttpServletRequest request) throws ServletException { final String servletPath = request.getServletPath(); return whiteListedPaths .stream() .anyMatch(servletPath::startsWith); } LdapRoleAuthenticationFilter(final LdapProperties ldapProperties);   }
@Test public void shouldInvokeFilterLogicWhenRequestIsForSecuredPath() throws ServletException { final LdapProperties ldapProperties = mockLdapPropertiesWithProtecedAndWhiteListedPath("/internal", "/internal/public"); final LdapRoleAuthenticationFilter filter = new LdapRoleAuthenticationFilter(ldapProperties); final HttpServletRequest request = mockRequestWithPath("/internal"); final boolean shouldInvokeFilterLogic = !filter.shouldNotFilter(request); assertTrue(shouldInvokeFilterLogic); }
@Test public void shouldNotInvokeFilterLogicWhenRequestIsForWhitelistedPath() throws ServletException { final LdapProperties ldapProperties = mockLdapPropertiesWithProtecedAndWhiteListedPath("/internal", "/internal/public"); final LdapRoleAuthenticationFilter filter = new LdapRoleAuthenticationFilter(ldapProperties); final HttpServletRequest request = mockRequestWithPath("/internal/public"); final boolean shouldInvokeFilterLogic = !filter.shouldNotFilter(request); assertFalse(shouldInvokeFilterLogic); }