TrustedUserAuthenticationFilter extends GenericFilterBean { @Override @SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST", justification = "The ServletRequest is cast to an HttpServletRequest which is always the case since all requests use the HTTP protocol.") public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { doHttpFilter((HttpServletRequest) servletRequest, (HttpServletResponse) servletResponse, filterChain); } TrustedUserAuthenticationFilter(AuthenticationManager authenticationManager, ApplicationUserBuilder applicationUserBuilder); @Override @SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST", justification = "The ServletRequest is cast to an HttpServletRequest which is always the case since all requests use the HTTP protocol.") void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain); void doHttpFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain);  }
@Test public void testTrustedUserFilter() throws Exception { Map<String, Object> overrideMap = new HashMap<>(); overrideMap.put(ConfigurationValue.SECURITY_ENABLED_SPEL_EXPRESSION.getKey(), "false"); modifyPropertySourceInEnvironment(overrideMap); try { invalidateApplicationUser(null); trustedUserAuthenticationFilter.init(new MockFilterConfig()); trustedUserAuthenticationFilter.doFilter(new MockHttpServletRequest(), new MockHttpServletResponse(), new MockFilterChain()); validateTrustedApplicationUser(); trustedUserAuthenticationFilter.doFilter(new MockHttpServletRequest(), new MockHttpServletResponse(), new MockFilterChain()); validateTrustedApplicationUser(); } finally { restorePropertySourceInEnvironment(); } }
@Test public void testTrustedUserFilterSecurityEnabled() throws Exception { Map<String, Object> overrideMap = new HashMap<>(); overrideMap.put(ConfigurationValue.SECURITY_ENABLED_SPEL_EXPRESSION.getKey(), "true"); modifyPropertySourceInEnvironment(overrideMap); try { invalidateApplicationUser(null); trustedUserAuthenticationFilter.init(new MockFilterConfig()); trustedUserAuthenticationFilter.doFilter(new MockHttpServletRequest(), new MockHttpServletResponse(), new MockFilterChain()); assertNoUserInContext(); } finally { restorePropertySourceInEnvironment(); } }
@Test public void testTrustedUserFilterNoSpel() throws Exception { Map<String, Object> overrideMap = new HashMap<>(); overrideMap.put(ConfigurationValue.SECURITY_ENABLED_SPEL_EXPRESSION.getKey(), ""); modifyPropertySourceInEnvironment(overrideMap); try { invalidateApplicationUser(null); trustedUserAuthenticationFilter.init(new MockFilterConfig()); trustedUserAuthenticationFilter.doFilter(new MockHttpServletRequest(), new MockHttpServletResponse(), new MockFilterChain()); assertNoUserInContext(); } finally { restorePropertySourceInEnvironment(); } }
@Test public void testTrustedUserFilterSwitchTrustedUser() throws Exception { Map<String, Object> overrideMap = getDefaultSecurityEnvironmentVariables(); overrideMap.put(ConfigurationValue.SECURITY_ENABLED_SPEL_EXPRESSION.getKey(), "false"); modifyPropertySourceInEnvironment(overrideMap); MockHttpServletRequest request = getRequestWithHeaders("testUser", "testFirstName", "testLastName", "testEmail", "testRole", "Wed, 11 Mar 2015 10:24:09"); invalidateApplicationUser(request); httpHeaderAuthenticationFilter.init(new MockFilterConfig()); httpHeaderAuthenticationFilter.doFilter(request, new MockHttpServletResponse(), new MockFilterChain()); assertNoUserInContext(); try { trustedUserAuthenticationFilter.init(new MockFilterConfig()); trustedUserAuthenticationFilter.doFilter(new MockHttpServletRequest(), new MockHttpServletResponse(), new MockFilterChain()); validateTrustedApplicationUser(); } finally { restorePropertySourceInEnvironment(); } }