}
@Test
public void testLogout() throws Exception {
LogoutFilterChain logoutchain =
(LogoutFilterChain) getSecurityManager().getSecurityConfig().getFilterChain().getRequestChainByName("webLogout");
String casFilterName = "testCasFilter2";
CasAuthenticationFilterConfig config = new CasAuthenticationFilterConfig();
config.setClassName(GeoServerCasAuthenticationFilter.class.getName());
config.setCasServerUrlPrefix(casServerURLPrefix.toString());
config.setName(casFilterName);
config.setRoleSource(PreAuthenticatedUserNameRoleSource.UserGroupService);
config.setUserGroupServiceName("ug1");
config.setSingleSignOut(true);
getSecurityManager().saveFilter(config);
// put a CAS filter on an active chain
prepareFilterChain(pattern,casFilterName);
modifyChain(pattern, false, true, null);
SecurityContextHolder.getContext().setAuthentication(null);
getCache().removeAll();
// login
String username = "castest";
String password = username;
CasFormAuthenticationHelper helper = new CasFormAuthenticationHelper(casServerURLPrefix,
username, password);
helper.ssoLogin();
MockHttpServletRequest request = createRequest(pattern);
MockHttpServletResponse response = new MockHttpServletResponse();
MockFilterChain chain = new MockFilterChain();
loginUsingTicket(helper, request, response, chain);
assertEquals(HttpServletResponse.SC_OK, response.getErrorCode());
assertFalse(response.wasRedirectSent());
SecurityContext ctx = (SecurityContext) request.getSession(false).getAttribute(
HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY);
assertNotNull(ctx);
Authentication auth = ctx.getAuthentication();
assertNotNull(auth);
assertNull(SecurityContextHolder.getContext().getAuthentication());
MockHttpSession session = (MockHttpSession) request.getSession(false);
assertNotNull(session);
assertTrue(session.isValid());
// logout triggered by geoserver
request = createRequest(logoutchain.getPatterns().get(0));
//request.getSession().setAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY, ctx);
SecurityContextHolder.setContext(ctx);
response = new MockHttpServletResponse();
chain = new MockFilterChain();
//getProxy().doFilter(request, response, chain);