Package org.geoserver.security

Examples of org.geoserver.security.GeoServerAuthenticationProvider


   
    @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);
View Full Code Here


    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));
       
        // test invalid user
        token = new UsernamePasswordAuthenticationToken("abc","def");
        boolean fail = false;
        try {
            if (provider.authenticate(token)==null)
                fail = true;
        } catch (BadCredentialsException ex) {
            fail=true;
        } catch (UsernameNotFoundException ex) {
            fail=true;
View Full Code Here

    @Test
    public void testAuthentificationWithRoleAssociation() throws Exception {
        GeoServerRoleService roleService = createRoleService("jdbc3");
        JDBCConnectAuthProviderConfig config = createAuthConfg("jdbc3", null);
        getSecurityManager().saveAuthenticationProvider(config);
        GeoServerAuthenticationProvider provider = getSecurityManager().loadAuthenticationProvider("jdbc3");
       
       
        GeoServerRoleStore roleStore =  roleService.createStore();
        roleStore.addRole(GeoServerRole.ADMIN_ROLE);
        roleStore.associateRoleToUser(GeoServerRole.ADMIN_ROLE, "sa");
        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 invalid user
        token = new UsernamePasswordAuthenticationToken("abc","def");
        boolean fail = false;
        try {
            if (provider.authenticate(token)==null)
                fail=true;
        } catch (BadCredentialsException ex) {
            fail=true;
        } catch (UsernameNotFoundException ex) {
            fail=true;
View Full Code Here

        ugstore.addUser(u3);


        ugstore.store();
       
        GeoServerAuthenticationProvider prov = createAuthProvider(testProviderName, ugservice.getName());
        prepareAuthProviders(prov.getName());       
       
    }
View Full Code Here

        expect(authProviderConfig.getName()).andReturn(GeoServerAuthenticationProvider.DEFAULT_NAME).anyTimes();
        expect(authProviderConfig.getUserGroupServiceName()).andReturn(XMLUserGroupService.DEFAULT_NAME).anyTimes();
        expect(secMgr.loadAuthenticationProviderConfig(GeoServerAuthenticationProvider.DEFAULT_NAME))
            .andReturn(authProviderConfig).anyTimes();
       
        GeoServerAuthenticationProvider authProvider = createNiceMock(GeoServerAuthenticationProvider.class);
        expect(authProvider.getName()).andReturn(GeoServerAuthenticationProvider.DEFAULT_NAME).anyTimes();
        expect(secMgr.loadAuthenticationProvider(GeoServerAuthenticationProvider.DEFAULT_NAME))
            .andReturn(authProvider).anyTimes();
        expect(secMgr.listAuthenticationProviders()).andReturn(
            new TreeSet<String>(Arrays.asList(GeoServerAuthenticationProvider.DEFAULT_NAME))).anyTimes();
        expect(secMgr.getAuthenticationProviders()).andReturn(Arrays.asList(authProvider)).anyTimes();
View Full Code Here

TOP

Related Classes of org.geoserver.security.GeoServerAuthenticationProvider

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.