Package org.geoserver.security

Examples of org.geoserver.security.GeoServerUserGroupService


//                XMLUserGroupService.DEFAULT_NAME);
//        GeoserverRoleService roleService = createRoleService(
//                XMLRoleService.DEFAULT_NAME);
//        getSecurityManager().setActiveRoleService(roleService);
//        getSecurityManager().setActiveUserGroupService(userService);
        GeoServerUserGroupService userService = getSecurityManager().loadUserGroupService(XMLUserGroupService.DEFAULT_NAME);
        GeoServerRoleService roleService =getSecurityManager().loadRoleService(XMLRoleService.DEFAULT_NAME);
       
        assertEquals(3,userService.getUsers().size());
        assertEquals(3,userService.getUserCount());
        assertEquals(0,userService.getUserGroups().size());
        assertEquals(0,userService.getGroupCount());
       
        assertEquals(9,roleService.getRoles().size());
       
        GeoServerUser admin = (GeoServerUser) userService.loadUserByUsername("admin");
        assertNotNull(admin);
        GeoServerMultiplexingPasswordEncoder enc= getEncoder(userService);
        assertTrue(enc.isPasswordValid(admin.getPassword(), "gs", null));
       
        assertTrue(admin.isEnabled());
       
        GeoServerUser wfs = (GeoServerUser) userService.loadUserByUsername("wfs");
        assertNotNull(wfs);
        assertTrue(enc.isPasswordValid(wfs.getPassword(), "webFeatureService", null));
        assertTrue(wfs.isEnabled());

        GeoServerUser disabledUser = (GeoServerUser) userService.loadUserByUsername("disabledUser");
        assertNotNull(disabledUser);
        assertTrue(enc.isPasswordValid(disabledUser.getPassword(), "nah", null));
        assertFalse(disabledUser.isEnabled());
       
        GeoServerRole role_admin = roleService.getRoleByName(XMLRoleService.DEFAULT_LOCAL_ADMIN_ROLE);
        assertNotNull(role_admin);
        GeoServerRole role_wfs_read = roleService.getRoleByName("ROLE_WFS_READ");
        assertNotNull(role_wfs_read);
        GeoServerRole role_wfs_write = roleService.getRoleByName("ROLE_WFS_WRITE");
        assertNotNull(role_wfs_write);
        GeoServerRole role_test = roleService.getRoleByName("ROLE_TEST");
        assertNotNull(role_test);
        assertNotNull(roleService.getRoleByName("NO_ONE"));
        assertNotNull(roleService.getRoleByName("TRUSTED_ROLE"));
        assertNotNull(roleService.getRoleByName("ROLE_SERVICE_1"));
        assertNotNull(roleService.getRoleByName("ROLE_SERVICE_2"));

       

        assertEquals(2,admin.getAuthorities().size());
        assertTrue(admin.getAuthorities().contains(role_admin));
        assertTrue(admin.getAuthorities().contains(GeoServerRole.ADMIN_ROLE));
       
        assertEquals(2,wfs.getAuthorities().size());
        assertTrue(wfs.getAuthorities().contains(role_wfs_read));
        assertTrue(wfs.getAuthorities().contains(role_wfs_write));

        assertEquals(1,disabledUser.getAuthorities().size());
        assertTrue(disabledUser.getAuthorities().contains(role_test));
       
        GeoServerSecurityManager securityManager = getSecurityManager();
        File userfile = new File(securityManager.getSecurityRoot(),"users.properties");
        assertFalse(userfile.exists());
        File userfileOld = new File(securityManager.getSecurityRoot(),"users.properties.old");
        assertTrue(userfileOld.exists());

        File roleXSD = new File(new File(securityManager.getRoleRoot(), roleService.getName()),
            XMLConstants.FILE_RR_SCHEMA);
        assertTrue(roleXSD.exists());

        File userXSD = new File (new File(securityManager.getUserGroupRoot(), userService.getName()),
            XMLConstants.FILE_UR_SCHEMA);
        assertTrue(userXSD.exists());
       
        /* does not work from the command line
         *
 
View Full Code Here


        ugConfig.setValidating(true);
        ugConfig.setPasswordEncoderName(getDigestPasswordEncoder().getName());
        ugConfig.setPasswordPolicyName(PasswordValidator.DEFAULT_NAME);
        getSecurityManager().saveUserGroupService(ugConfig/*,isNewUGService(serviceName)*/);
       
        GeoServerUserGroupService service = getSecurityManager().loadUserGroupService(serviceName);
        service.initializeFromConfig(ugConfig); // create files
        return service;               
    }
View Full Code Here

   
    @Test
    public void testCopyFrom() {
        try {
   
            GeoServerUserGroupService service1 = createUserGroupService("copyFrom");
            GeoServerUserGroupService service2 = createUserGroupService("copyTo");
            GeoServerUserGroupStore store1 = createStore(service1);
            GeoServerUserGroupStore store2 = createStore(service2);                       

           
            store1.clear();
View Full Code Here

    public void testDefault() {
        try {
//            GeoserverUserGroupService service = createUserGroupService(
//                    XMLUserGroupService.DEFAULT_NAME);
           
            GeoServerUserGroupService service =
                    getSecurityManager().loadUserGroupService(XMLUserGroupService.DEFAULT_NAME);
                       
            assertEquals(1, service.getUsers().size());
            assertEquals(1, service.getUserCount());
            assertEquals(0, service.getUserGroups().size());
            assertEquals(0, service.getGroupCount());
                       
            GeoServerUser admin= service.getUserByUsername(GeoServerUser.ADMIN_USERNAME);
            assertNotNull(admin);
            assertEquals(GeoServerUser.AdminEnabled,admin.isEnabled());
           
            GeoServerMultiplexingPasswordEncoder enc= getEncoder(service);
            assertTrue(enc.isPasswordValid(admin.getPassword(), GeoServerUser.DEFAULT_ADMIN_PASSWD,null));
            assertEquals(admin.getProperties().size(),0);
           
            assertEquals(0, service.getGroupsForUser(admin).size());
                       
        } catch (IOException ex) {
            Assert.fail(ex.getMessage());
        }               
    }
View Full Code Here

   
    @Test
    public void testLocking() throws Exception {
        File xmlFile = File.createTempFile("users", ".xml");
        FileUtils.copyURLToFile(getClass().getResource("usersTemplate.xml"),xmlFile);
        GeoServerUserGroupService service1 = 
            createUserGroupService("locking1",xmlFile.getCanonicalPath());
        GeoServerUserGroupService service2 = 
            createUserGroupService("locking2",xmlFile.getCanonicalPath());
        GeoServerUserGroupStore store1= createStore(service1);
        GeoServerUserGroupStore store2= createStore(service2);
       
       
View Full Code Here

    @Test
    public void testDynamicReload() throws Exception {
        File xmlFile = File.createTempFile("users", ".xml");
        FileUtils.copyURLToFile(getClass().getResource("usersTemplate.xml"),xmlFile);
        GeoServerUserGroupService service1 = 
            createUserGroupService("reload1",xmlFile.getCanonicalPath());
        GeoServerUserGroupService service2 = 
            createUserGroupService("reload2",xmlFile.getCanonicalPath());
       
        GeoServerUserGroupStore store1= createStore(service1);
       
       
        GeoServerUserGroup group = store1.createGroupObject("group",true);
       
        checkEmpty(service1);
        checkEmpty(service2);
       
        // prepare for syncing
       
        UserGroupLoadedListener listener = new UserGroupLoadedListener() {
           
            @Override
            public void usersAndGroupsChanged(UserGroupLoadedEvent event) {
                synchronized (this) {
                    this.notifyAll();
                }
            }
        };
           
        service2.registerUserGroupLoadedListener(listener);
       
        // modifiy store1
        store1.addGroup(group);
        store1.store();
        assertTrue(service1.getUserGroups().size()==1);
        assertTrue(service1.getGroupCount()==1);
       
     // increment lastmodified adding a second manually, the test is too fast
        xmlFile.setLastModified(xmlFile.lastModified()+2000)
       
        // wait for the listener to unlock when
        // service 2 triggers a load event
        synchronized (listener) {
            listener.wait();           
        }
       
        // here comes the magic !!!
        assertTrue(service2.getUserGroups().size()==1);
        assertTrue(service2.getGroupCount()==1);
    }
View Full Code Here

                return Arrays.asList(UserListProvider.USERNAME);
            }

            @Override
            protected List<GeoServerUser> getItems() {
                GeoServerUserGroupService ugService =
                        getUserGroupService(EditGroupPage.this.userGroupServiceName);
                try {
                    return new ArrayList<GeoServerUser>(ugService.getUsersForGroup(group));
                } catch (IOException e) {
                    throw new WicketRuntimeException(e);
                }
            }
        }).setFilterable(false));
View Full Code Here

        }
       
        GeoServerSecurityManager secMgr = createNiceMock(GeoServerSecurityManager.class);
        expect(secMgr.listAuthenticationProviders()).andReturn(new TreeSet<String>()).anyTimes();
       
        GeoServerUserGroupService ugService1 = createNiceMock(GeoServerUserGroupService.class);
        expect(ugService1.getName()).andReturn("test1").anyTimes();
        expect(secMgr.loadUserGroupService("test1")).andReturn(ugService1).anyTimes();

        GeoServerUserGroupService ugService2 = createNiceMock(GeoServerUserGroupService.class);
        expect(ugService2.getName()).andReturn("test2").anyTimes();
        expect(ugService2.getGroupCount()).andReturn(1).anyTimes();
        expect(secMgr.loadUserGroupService("test2")).andReturn(ugService2).anyTimes();

        GeoServerUserGroupService ugServiceModify = createNiceMock(GeoServerUserGroupService.class);
        expect(ugServiceModify.getName()).andReturn("testModify").anyTimes();
        expect(secMgr.loadUserGroupService("testModify")).andReturn(ugService2).anyTimes();
       
        expect(secMgr.listUserGroupServices()).andReturn(new TreeSet<String>(
                Arrays.asList("test1", "test2", "testModify"))).anyTimes();
View Full Code Here

    @Override
    protected List<GeoServerUserGroup> getItems() {
        SortedSet<GeoServerUserGroup> groups=null;
        try {
            GeoServerUserGroupService service = null;
            if (userGroupServiceName!=null) service =
                    getApplication().getSecurityManager().loadUserGroupService(userGroupServiceName);
           
            if (service==null)
                groups=new TreeSet<GeoServerUserGroup>();
            else
                groups=service.getUserGroups();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        List<GeoServerUserGroup> groupList = new ArrayList<GeoServerUserGroup>();
        groupList.addAll(groups);
View Full Code Here

            protected boolean onSubmit(AjaxRequestTarget target, Component contents) {

                GeoServerUserGroupStore ugStore=null;
                try {
                    GeoServerUserGroupService ugService =
                            GeoServerApplication.get().getSecurityManager()
                            .loadUserGroupService(userGroupsServiceName);
                    ugStore = new UserGroupStoreValidationWrapper(ugService.createStore());
                    for (GeoServerUserGroup group : removePanel.getRoots()) {                    
                         ugStore.removeGroup(group);
                    }
                    ugStore.store();
                } catch (IOException ex) {
View Full Code Here

TOP

Related Classes of org.geoserver.security.GeoServerUserGroupService

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.