public void testAuthentificationWithoutUserGroupService() throws Exception { JDBCConnectAuthProviderConfig config = createAuthConfg("jdbc1", null); getSecurityManager().saveAuthenticationProvider(config); GeoServerAuthenticationProvider provider = getSecurityManager().loadAuthenticationProvider("jdbc1"); 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(1,auth.getAuthorities().size()); checkForAuthenticatedRole(auth); token = new UsernamePasswordAuthenticationToken("abc","def"); boolean fail = false; try { if (provider.authenticate(token)==null) fail = true; } catch (BadCredentialsException ex) { fail=true; } assertTrue(fail); }
@Test public void testAuthentificationWithRoleAssociation() throws Exception { GeoServerRoleService roleService = createRoleService("jdbc3"); JDBCConnectAuthProviderConfig config = createAuthConfg("jdbc3", null); getSecurityManager().saveAuthenticationProvider(config); GeoServerAuthenticationProvider provider = getSecurityManager().loadAuthenticationProvider("jdbc3"); roleStore.associateRoleToUser(GeoServerRole.ADMIN_ROLE, "sa"); roleStore.store(); getSecurityManager().setActiveRoleService(roleService); assertEquals("details", auth.getDetails()); assertEquals(2, auth.getAuthorities().size()); checkForAuthenticatedRole(auth); assertTrue(auth.getAuthorities().contains(GeoServerRole.ADMIN_ROLE));
@Test public void testAuthentificationWithoutUserGroupService() throws Exception { JDBCConnectAuthProviderConfig config = createAuthConfg("jdbc1", null); getSecurityManager().saveAuthenticationProvider(config); GeoServerAuthenticationProvider provider = getSecurityManager().loadAuthenticationProvider("jdbc1"); UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken("sa", ""); token.setDetails("details"); assertTrue(provider.supports(token.getClass())); assertTrue(!provider.supports(RememberMeAuthenticationToken.class)); Authentication auth = provider.authenticate(token); assertNotNull(auth); assertEquals("sa", auth.getPrincipal()); assertNull(auth.getCredentials()); assertEquals("details", auth.getDetails()); assertEquals(1, auth.getAuthorities().size()); checkForAuthenticatedRole(auth); token = new UsernamePasswordAuthenticationToken("abc", "def"); boolean fail = false; try { if (provider.authenticate(token) == null) fail = true; } catch (BadCredentialsException ex) { fail = true; } assertTrue(fail); }
@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"); roleStore.associateRoleToUser(GeoServerRole.ADMIN_ROLE, sa.getUsername()); roleStore.store(); getSecurityManager().setActiveRoleService(roleService); assertEquals("details", auth.getDetails()); assertEquals(2, auth.getAuthorities().size()); checkForAuthenticatedRole(auth); assertTrue(auth.getAuthorities().contains(GeoServerRole.ADMIN_ROLE));
public void testAuthentificationWithRoleAssociation() throws Exception { GeoServerRoleService roleService = createRoleService("jdbc2"); JDBCConnectAuthProviderConfig config = createAuthConfg("jdbc2", null); getSecurityManager().saveAuthenticationProvider(config); GeoServerAuthenticationProvider provider = getSecurityManager().loadAuthenticationProvider("jdbc2"); roleStore.associateRoleToUser(GeoServerRole.ADMIN_ROLE, "sa"); roleStore.store(); getSecurityManager().setActiveRoleService(roleService); assertTrue(provider.supports(token.getClass())); assertFalse(provider.supports(RememberMeAuthenticationToken.class)); 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)); assertTrue(fail);
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"); roleStore.associateRoleToUser(GeoServerRole.ADMIN_ROLE, sa.getUsername()); roleStore.store(); getSecurityManager().setActiveRoleService(roleService); assertTrue(provider.supports(token.getClass())); assertFalse(provider.supports(RememberMeAuthenticationToken.class)); 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)); ugStore.store(); assertNull(provider.authenticate(token)); assertTrue(fail);