Package org.geoserver.security

Examples of org.geoserver.security.GeoServerRoleStore


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


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

   
    protected void createServices() throws Exception{
       
        GeoServerRoleService rservice = createRoleService("rs1");
        GeoServerRoleStore rstore = rservice.createStore();
        GeoServerRole root, derived;
        rstore.addRole(root=rstore.createRoleObject(rootRole));
        rstore.addRole(derived=rstore.createRoleObject(derivedRole));
        rstore.setParentRole(derived, root);
        rstore.associateRoleToUser(derived, testUserName);
        rstore.associateRoleToUser(derived, "castest");
        rstore.store();
       
        SecurityManagerConfig mconfig = getSecurityManager().loadSecurityConfig();
        mconfig.setRoleServiceName("rs1");
        getSecurityManager().saveSecurityConfig(mconfig);
       
View Full Code Here

        ugStore.addUser(ugStore.createUserObject("cite_texas", "cite", true));
        ugStore.addUser(ugStore.createUserObject("cite_mosaic1", "cite", true));
        ugStore.addUser(ugStore.createUserObject("cite_mosaic2", "cite", true));
        ugStore.store();
       
        GeoServerRoleStore roleStore= getSecurityManager().getActiveRoleService().createStore();
        GeoServerRole role = roleStore.createRoleObject("ROLE_DUMMY");
        roleStore.addRole(role);
        roleStore.associateRoleToUser(role, "cite");
        roleStore.associateRoleToUser(role, "cite_noinfo");
        roleStore.associateRoleToUser(role, "cite_nostates");
        roleStore.associateRoleToUser(role, "cite_cite_texas");
        roleStore.associateRoleToUser(role, "cite_mosaic1");
        roleStore.associateRoleToUser(role, "cite_mosaic2");
        roleStore.store();
       
        prepare();
    }
View Full Code Here

        expect(ugConfig.getPasswordPolicyName()).andReturn(PasswordValidator.DEFAULT_NAME).anyTimes();
        expect(secMgr.loadUserGroupServiceConfig(XMLUserGroupService.DEFAULT_NAME))
            .andReturn(ugConfig).anyTimes();
   
        //default role store
        GeoServerRoleStore roleStore =
            createRoleStore(XMLRoleService.DEFAULT_NAME, secMgr);
        expect(secMgr.listRoleServices()).andReturn(
            new TreeSet<String>(Arrays.asList(XMLRoleService.DEFAULT_NAME))).anyTimes();
        expect(secMgr.getActiveRoleService()).andReturn(roleStore).anyTimes();
   
View Full Code Here

    }
   
    protected GeoServerRoleStore createRoleStore(String name, GeoServerSecurityManager secMgr, String... roleNames)
        throws IOException {
   
        GeoServerRoleStore roleStore = createNiceMock(GeoServerRoleStore.class);
        expect(roleStore.getSecurityManager()).andReturn(secMgr).anyTimes();
        expect(roleStore.getName()).andReturn(name).anyTimes();
   
        for (String roleName : roleNames) {
            expect(roleStore.getRoleByName(roleName)).andReturn(new GeoServerRole(roleName)).anyTimes();
        }
   
        for (GeoServerRole role : GeoServerRole.SystemRoles) {
            String roleName = role.getAuthority();
            expect(roleStore.createRoleObject(roleName)).andReturn(new GeoServerRole(roleName)).anyTimes();
        }
   
        expect(secMgr.loadRoleService(name)).andReturn(roleStore).anyTimes();
        return roleStore;
    }
View Full Code Here

        }
        ugStore.store();

        if (roles != null && !roles.isEmpty()) {
            GeoServerRoleService roleService = secMgr.getActiveRoleService();
            GeoServerRoleStore roleStore = roleService.createStore();
            for (String roleName : roles) {
                GeoServerRole role = roleStore.getRoleByName(roleName);
                if (role == null) {
                    role = roleStore.createRoleObject(roleName);
                    roleStore.addRole(role);
                }

                roleStore.associateRoleToUser(role, username);
            }

            roleStore.store();
        }
    }
View Full Code Here

        setMockCreator(new MockCreator() {
            @Override
            public GeoServerSecurityManager createSecurityManager(MockTestData testData) throws Exception {
                GeoServerSecurityManager secMgr = createMock(GeoServerSecurityManager.class);

                GeoServerRoleStore roleStore1 = createRoleStore("test", secMgr, "role1", "parent1");
                addRolesToCreate(roleStore1, "", "duplicated", "xxx");

                GeoServerRoleStore roleStore2 = createRoleStore("test1", secMgr, "duplicated");
               
                expect(secMgr.listRoleServices()).andReturn(
                    new TreeSet<String>(Arrays.asList("test", "test1"))).anyTimes();

                replay(roleStore1, roleStore2, secMgr);
                return secMgr;
            }
        });

        GeoServerSecurityManager secMgr = getSecurityManager();
        GeoServerRoleStore roleStore = (GeoServerRoleStore) secMgr.loadRoleService("test");

        RoleStoreValidationWrapper store = new RoleStoreValidationWrapper(roleStore);
        try {
            store.addRole(store.createRoleObject(""));
            fail("empty role name should throw exception");
        } catch (IOException ex) {
            assertSecurityException(ex, NAME_REQUIRED);
        }

        try {
            store.addRole(store.createRoleObject(""));
            fail("empty role name should throw exception");
        } catch (IOException ex) {
            assertSecurityException(ex, NAME_REQUIRED);
        }

        GeoServerRole role1 = store.getRoleByName("role1");

        try {
            store.addRole(role1);
            fail("already existing role name should throw exception");
        } catch (IOException ex) {
            assertSecurityException(ex, ALREADY_EXISTS, "role1");
        }
       
        for (GeoServerRole srole : GeoServerRole.SystemRoles) {
            try {
                store.addRole(store.createRoleObject(srole.getAuthority()));
                fail("reserved role name should throw exception");
            } catch (IOException ex) {
                assertSecurityException(ex, RESERVED_NAME, srole.getAuthority());
            }
        }

        GeoServerRoleStore roleStore1 = (GeoServerRoleStore) secMgr.loadRoleService("test1");
        RoleStoreValidationWrapper store1 = new RoleStoreValidationWrapper(roleStore1);

        try {
            store.addRole(store.createRoleObject("duplicated"));
            fail("reserved role name should throw exception");
View Full Code Here

        setMockCreator(new MockCreator() {
            @Override
            public GeoServerSecurityManager createSecurityManager( MockTestData testData) throws Exception {
                GeoServerSecurityManager secMgr = createNiceMock(GeoServerSecurityManager.class);

                GeoServerRoleStore roleStore = createRoleStore("test", secMgr, "role1", "parent1");
                expect(roleStore.removeRole(new GeoServerRole("unused"))).andReturn(true);

                DataAccessRule dataAccessRule = createNiceMock(DataAccessRule.class);
                expect(dataAccessRule.compareTo(dataAccessRule)).andReturn(0).anyTimes();
                expect(dataAccessRule.getKey()).andReturn("foo").anyTimes();
                expect(dataAccessRule.getRoles()).andReturn(new TreeSet<String>(Arrays.asList("role1"))).anyTimes();
View Full Code Here

                GeoServerUserGroupStore ugStore2 = createUserGroupStore("test2", secMgr);
                addUsers(ugStore1, "user2", "abc");
                addGroups(ugStore1, "group2");
               
                GeoServerRoleStore roleStore = createRoleStore("test", secMgr, "role1");
                expect(roleStore.getGroupNamesForRole(new GeoServerRole("role1"))).andReturn(
                    new TreeSet<String>(Arrays.asList("group1", "group2"))).anyTimes();
               
                replay(ugStore1, ugStore2, roleStore, secMgr);
                return secMgr;
            }
View Full Code Here

TOP

Related Classes of org.geoserver.security.GeoServerRoleStore

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.