@Test
public void testTrustedUserFilterSwitchTrustedUser() throws Exception
{

    // Override configuration.
    Map<String, Object> overrideMap = getDefaultSecurityEnvironmentVariables();
    overrideMap.put(ConfigurationValue.SECURITY_ENABLED_SPEL_EXPRESSION.getKey(), "false");
    modifyPropertySourceInEnvironment(overrideMap);
    // Create HttpHeader user in session.
    MockHttpServletRequest request =
        getRequestWithHeaders("testUser", "testFirstName", "testLastName", "testEmail", "testRole", "Wed, 11 Mar 2015 10:24:09");
    // Invalidate user session if exists.
    invalidateApplicationUser(request);
    httpHeaderAuthenticationFilter.init(new MockFilterConfig());
    httpHeaderAuthenticationFilter.doFilter(request, new MockHttpServletResponse(), new MockFilterChain());
    assertNoUserInContext();
    // Now apply the trusted user filter to ensure that user is switched to trusted user
    try
    {
        trustedUserAuthenticationFilter.init(new MockFilterConfig());
        trustedUserAuthenticationFilter.doFilter(new MockHttpServletRequest(), new MockHttpServletResponse(), new MockFilterChain());
        validateTrustedApplicationUser();
    }
    finally
    {
        // Restore the property sources so we don't affect other tests.
        restorePropertySourceInEnvironment();
    }
}