auth = ctx.getAuthentication();
assertNotNull(auth);
assertNull(SecurityContextHolder.getContext().getAuthentication());
checkForAuthenticatedRole(auth);
assertEquals(testUserName, auth.getPrincipal());
assertTrue(auth.getAuthorities().contains(new GeoServerRole(rootRole)));
assertTrue(auth.getAuthorities().contains(new GeoServerRole(derivedRole)));
}
// test root
request= createRequest("/foo/bar");
response= new MockHttpServletResponse();
chain = new MockFilterChain();
request.setUserPrincipal(new Principal() {
@Override
public String getName() {
return GeoServerUser.ROOT_USERNAME;
}
});
getProxy().doFilter(request, response, chain);
assertEquals(HttpServletResponse.SC_OK, response.getErrorCode());
ctx = (SecurityContext)request.getSession(true).getAttribute(
HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY);
assertNotNull(ctx);
auth = ctx.getAuthentication();
assertNotNull(auth);
assertNull(SecurityContextHolder.getContext().getAuthentication());
//checkForAuthenticatedRole(auth);
assertEquals(GeoServerUser.ROOT_USERNAME, auth.getPrincipal());
assertTrue(auth.getAuthorities().size()==1);
assertTrue(auth.getAuthorities().contains(GeoServerRole.ADMIN_ROLE));
config.setRoleServiceName(null);
getSecurityManager().saveFilter(config);
// test preauthenticated with active role service
request= createRequest("/foo/bar");
response= new MockHttpServletResponse();
chain = new MockFilterChain();
request.setUserPrincipal(new Principal() {
@Override
public String getName() {
return testUserName;
}
});
request.setUserInRole(derivedRole,true);
request.setUserInRole(rootRole,false);
getProxy().doFilter(request, response, chain);
assertEquals(HttpServletResponse.SC_OK, response.getErrorCode());
ctx = (SecurityContext)request.getSession(true).getAttribute(
HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY);
assertNotNull(ctx);
auth=ctx.getAuthentication();
assertNotNull(auth);
assertNull(SecurityContextHolder.getContext().getAuthentication());
checkForAuthenticatedRole(auth);
assertEquals(testUserName, auth.getPrincipal());
assertTrue(auth.getAuthorities().contains(new GeoServerRole(rootRole)));
assertTrue(auth.getAuthorities().contains(new GeoServerRole(derivedRole)));
// Test anonymous
insertAnonymousFilter();
request= createRequest("/foo/bar");
response= new MockHttpServletResponse();