}
@Test
public void testAuthentificationWithUserGroupService() throws Exception {
GeoServerRoleService roleService = createRoleService("jdbc2");
GeoServerUserGroupService ugService = createUserGroupService("jdbc2");
JDBCConnectAuthProviderConfig config = createAuthConfg("jdbc2", ugService.getName());
getSecurityManager().saveAuthenticationProvider(config);
GeoServerAuthenticationProvider provider = getSecurityManager().loadAuthenticationProvider("jdbc2");
GeoServerUserGroupStore ugStore = ugService.createStore();
GeoServerUser sa = ugStore.createUserObject("sa", "", true);
ugStore.addUser(sa);
ugStore.store();
GeoServerRoleStore roleStore = roleService.createStore();
roleStore.addRole(GeoServerRole.ADMIN_ROLE);
roleStore.associateRoleToUser(GeoServerRole.ADMIN_ROLE, sa.getUsername());
roleStore.store();
getSecurityManager().setActiveRoleService(roleService);
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken("sa","");
token.setDetails("details");
assertTrue(provider.supports(token.getClass()));
assertFalse(provider.supports(RememberMeAuthenticationToken.class));
Authentication auth = provider.authenticate(token);
assertNotNull(auth);
assertEquals("sa", auth.getPrincipal());
assertNull(auth.getCredentials());
assertEquals("details", auth.getDetails());
assertEquals(2, auth.getAuthorities().size());
checkForAuthenticatedRole(auth);
assertTrue(auth.getAuthorities().contains(GeoServerRole.ADMIN_ROLE));
// Test disabled user
ugStore = ugService.createStore();
sa.setEnabled(false);
ugStore.updateUser(sa);
ugStore.store();
assertNull(provider.authenticate(token));