Package org.geoserver.security.config

Examples of org.geoserver.security.config.SecurityUserGroupServiceConfig


        } catch (SecurityConfigException ex) {
            assertEquals(ex.getId(), USERGROUP_SERVICE_ALREADY_EXISTS_$1);
            assertEquals(ex.getArgs()[0],XMLUserGroupService.DEFAULT_NAME);
        }

        SecurityUserGroupServiceConfig ugConfig = 
                createUGConfig("default2", GeoServerUserGroupService.class,
                getPlainTextPasswordEncoder().getName(), PasswordValidator.DEFAULT_NAME);
        try {
            validator.validateModifiedUserGroupService(ugConfig,ugConfig);
            fail("unknown user group service should fail");
View Full Code Here


    }

    @Test
    public void testUserGroupConfig() throws IOException {
       
        SecurityUserGroupServiceConfig config = createUGConfig(XMLUserGroupService.DEFAULT_NAME,
            MemoryUserGroupService.class, getPlainTextPasswordEncoder().getName(),PasswordValidator.DEFAULT_NAME);

        SecurityConfigValidator validator = new SecurityConfigValidator(getSecurityManager());

        try {
            config.setName("default2");
            config.setPasswordEncoderName("xxx");
            validator.validateAddUserGroupService(config);
            fail("invalid config password encoder should fail");
            //getSecurityManager().saveUserGroupService(config);                        
        } catch (SecurityConfigException ex) {
            assertEquals( INVALID_CONFIG_PASSWORD_ENCODER_$1,ex.getId());
            assertEquals("xxx",ex.getArgs()[0]);
        }

        if (!getSecurityManager().isStrongEncryptionAvailable()) {
            config.setPasswordEncoderName(getStrongPBEPasswordEncoder().getName());
           
            try {
                validator.validateAddUserGroupService(config);
                fail("invalid strong password encoder should fail");
                //getSecurityManager().saveUserGroupService(config);
            } catch (SecurityConfigException ex){
                assertEquals(INVALID_STRONG_PASSWORD_ENCODER,ex.getId());
            }
        }

        try {
            config.setName("other");
            config.setPasswordEncoderName("xxx");
            validator.validateAddUserGroupService(config);
            fail("invalid config password encoder should fail");
            //getSecurityManager().saveUserGroupService(config);                        
        } catch (SecurityConfigException ex) {
            assertEquals( INVALID_CONFIG_PASSWORD_ENCODER_$1,ex.getId());
            assertEquals("xxx",ex.getArgs()[0]);
        }

        try {
            config.setName("default2");
            config.setPasswordEncoderName("");
            validator.validateAddUserGroupService(config);
            fail("no password encoder should fail");
            //getSecurityManager().saveUserGroupService(config);                        
        } catch (SecurityConfigException ex) {
            assertEquals( PASSWD_ENCODER_REQUIRED_$1,ex.getId());
            assertEquals("default2",ex.getArgs()[0]);
        }

        try {
            config.setName("default3");
            config.setPasswordEncoderName(null);
            //getSecurityManager().saveUserGroupService(config);
            validator.validateAddUserGroupService(config);
            fail("no password encoder should fail");
        } catch (SecurityConfigException ex) {
            assertEquals( PASSWD_ENCODER_REQUIRED_$1,ex.getId());
            assertEquals("default3", ex.getArgs()[0]);
        }

        config.setPasswordEncoderName(getPlainTextPasswordEncoder().getName());

        try {
            config.setName("default2");
            config.setPasswordPolicyName("default2");
            validator.validateAddUserGroupService(config);
            fail("unknown password policy should fail");
            //getSecurityManager().saveUserGroupService(config);                        
        } catch (SecurityConfigException ex) {
            assertEquals( PASSWD_POLICY_NOT_FOUND_$1,ex.getId());
            assertEquals("default2",ex.getArgs()[0]);
        }

        try {
            config.setName("default3");
            config.setPasswordPolicyName("default2");
            validator.validateAddUserGroupService(config);
            fail("unkonwn password policy encoder should fail");
            //getSecurityManager().saveUserGroupService(config);                        
        } catch (SecurityConfigException ex) {
            assertEquals( PASSWD_POLICY_NOT_FOUND_$1,ex.getId());
            assertEquals("default2",ex.getArgs()[0]);
        }
       
        try {
            config.setName("default2");
            config.setPasswordPolicyName("");
            //getSecurityManager().saveUserGroupService(config);
            validator.validateAddUserGroupService(config);
            fail("no password policy should fail");
        } catch (SecurityConfigException ex) {
            assertEquals( PASSWD_POLICY_REQUIRED_$1,ex.getId());
            assertEquals("default2",ex.getArgs()[0]);
        }

        try {
            config.setName("default3");
            config.setPasswordPolicyName(null);
            validator.validateAddUserGroupService(config);
            fail("invalidate password policy should fail");
            //getSecurityManager().saveUserGroupService(config);                        
        } catch (SecurityConfigException ex) {
            assertEquals( PASSWD_POLICY_REQUIRED_$1,ex.getId());
            assertEquals("default3",ex.getArgs()[0]);
        }

        try {
            config.setName(null);
            validator.validateRemoveUserGroupService(config);
            fail("no name should fail");
            getSecurityManager().removeUserGroupService(config);                        
        } catch (SecurityConfigException ex) {
            assertEquals( NAME_REQUIRED,ex.getId());
            assertEquals(0,ex.getArgs().length);
        }

        try {
            config.setName(XMLUserGroupService.DEFAULT_NAME);
            validator.validateRemoveUserGroupService(config);
            fail("active user group service should fail");
            //getSecurityManager().removeUserGroupService(config);                        
        } catch (SecurityConfigException ex) {
            assertEquals( USERGROUP_SERVICE_ACTIVE_$2,ex.getId());
View Full Code Here

        return createUserGroupService(name, getPBEPasswordEncoder().getName());

    }
   
    public GeoServerUserGroupService createUserGroupService(String name,String passwordEncoderName) throws Exception {
        SecurityUserGroupServiceConfig config =  getUserGroupConfg(name, passwordEncoderName);                
        getSecurityManager().saveUserGroupService(config/*,isNewUGService(name)*/);
        return getSecurityManager().loadUserGroupService(name);

    }
View Full Code Here

        GeoServerUserGroupStore ugStore =
            createUserGroupStore(XMLUserGroupService.DEFAULT_NAME, secMgr);
        expect(secMgr.listUserGroupServices()).andReturn(
            new TreeSet<String>(Arrays.asList(XMLUserGroupService.DEFAULT_NAME))).anyTimes();
   
        SecurityUserGroupServiceConfig ugConfig = createNiceMock(SecurityUserGroupServiceConfig.class);
        expect(ugConfig.getName()).andReturn(XMLUserGroupService.DEFAULT_NAME).anyTimes();
        expect(ugConfig.getPasswordPolicyName()).andReturn(PasswordValidator.DEFAULT_NAME).anyTimes();
        expect(secMgr.loadUserGroupServiceConfig(XMLUserGroupService.DEFAULT_NAME))
            .andReturn(ugConfig).anyTimes();
   
        //default role store
        GeoServerRoleStore roleStore =
View Full Code Here

            if (service.canCreateStore()) {
                GeoServerUserGroupStore store = service.createStore();
                store.clear();
                store.store();
            }
            SecurityUserGroupServiceConfig old =
                    securityManager.loadUserGroupServiceConfig(serviceName);
            securityManager.removeUserGroupService(old);

        }
View Full Code Here

    }
   
    @Test
    public void testPasswordRecoding() throws Exception{

        SecurityUserGroupServiceConfig config = getSecurityManager().loadUserGroupServiceConfig(service.getName());       
        config.setPasswordEncoderName(getPlainTextPasswordEncoder().getName());
        getSecurityManager().saveUserGroupService(config);
        service.initializeFromConfig(config);
        store=service.createStore();       
       
        store.addUser(store.createUserObject("u1", "p1", true));
        store.addUser(store.createUserObject("u2", "p2", true));
        store.store();
       
        Util.recodePasswords(service.createStore());
        // no recoding
        assertTrue(service.loadUserByUsername("u1").getPassword().startsWith(getPlainTextPasswordEncoder().getPrefix()));
        assertTrue(service.loadUserByUsername("u2").getPassword().startsWith(getPlainTextPasswordEncoder().getPrefix()));

       
        config.setPasswordEncoderName(getPBEPasswordEncoder().getName());
        getSecurityManager().saveUserGroupService(config);
        service.initializeFromConfig(config);
                       
        Util.recodePasswords(service.createStore());
        // recoding
        assertTrue(service.loadUserByUsername("u1").getPassword().startsWith(getPBEPasswordEncoder().getPrefix()));
        assertTrue(service.loadUserByUsername("u2").getPassword().startsWith(getPBEPasswordEncoder().getPrefix()));

        config.setPasswordEncoderName(getDigestPasswordEncoder().getName());       
        getSecurityManager().saveUserGroupService(config);
        service.initializeFromConfig(config);

        Util.recodePasswords(service.createStore());
        // recoding
        assertTrue(service.loadUserByUsername("u1").getPassword().startsWith(getDigestPasswordEncoder().getPrefix()));
        assertTrue(service.loadUserByUsername("u2").getPassword().startsWith(getDigestPasswordEncoder().getPrefix()));
       
        config.setPasswordEncoderName(getPBEPasswordEncoder().getName());
        getSecurityManager().saveUserGroupService(config);
        service.initializeFromConfig(config);

        Util.recodePasswords(service.createStore());
        // recoding has no effect
        assertTrue(service.loadUserByUsername("u1").getPassword().startsWith(getDigestPasswordEncoder().getPrefix()));
        assertTrue(service.loadUserByUsername("u2").getPassword().startsWith(getDigestPasswordEncoder().getPrefix()));

        // add a user with pbe encoding
        store = service.createStore();
        store.addUser(store.createUserObject("u3", "p3", true));
        store.store();
       
        assertTrue(service.loadUserByUsername("u1").getPassword().startsWith(getDigestPasswordEncoder().getPrefix()));
        assertTrue(service.loadUserByUsername("u2").getPassword().startsWith(getDigestPasswordEncoder().getPrefix()));
        assertTrue(service.loadUserByUsername("u3").getPassword().startsWith(getPBEPasswordEncoder().getPrefix()));

        config.setPasswordEncoderName(getEmptyEncoder().getName());
        getSecurityManager().saveUserGroupService(config);
        service.initializeFromConfig(config);
       
        Util.recodePasswords(service.createStore());
        // recode u3 to empty
        assertTrue(service.loadUserByUsername("u1").getPassword().startsWith(getDigestPasswordEncoder().getPrefix()));
        assertTrue(service.loadUserByUsername("u2").getPassword().startsWith(getDigestPasswordEncoder().getPrefix()));
        assertTrue(service.loadUserByUsername("u3").getPassword().startsWith(getEmptyEncoder().getPrefix()));

        config.setPasswordEncoderName(getPBEPasswordEncoder().getName());
        getSecurityManager().saveUserGroupService(config);
        service.initializeFromConfig(config);

        Util.recodePasswords(service.createStore());
        // recode has no effect
View Full Code Here

    static class UsersGroupsPanel extends ContentPanel<SecurityUserGroupServiceConfig> {

        public UsersGroupsPanel(String id, final IModel<SecurityUserGroupServiceConfig> model) {
            super(id, model);

            SecurityUserGroupServiceConfig config = model.getObject();
            add(new UserPanel("users", config.getName())
                .setHeaderVisible(true).setPagersVisible(false, true));
            add(new GroupPanel("groups", config.getName())
                .setHeaderVisible(true).setPagersVisible(false, true));
        }
View Full Code Here

                }
            }
        }));

        boolean canCreateStore=false;
        SecurityUserGroupServiceConfig config = model.getObject();
        try {
            GeoServerUserGroupService s =
                (GeoServerUserGroupService) Class.forName(config.getClassName()).newInstance();
            canCreateStore=s.canCreateStore();
        } catch (Exception e) {
            // do nothing
        }
View Full Code Here

    protected List<SecurityUserGroupServiceConfig> load() {
        GeoServerSecurityManager secMgr = GeoServerApplication.get().getSecurityManager();
        List<SecurityUserGroupServiceConfig> configs = new ArrayList();
        try {
            for (String ugServiceName : secMgr.listUserGroupServices()) {
                SecurityUserGroupServiceConfig config =
                        secMgr.loadUserGroupServiceConfig(ugServiceName);
                configs.add(config);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
View Full Code Here

     }

    @Override
    public void initializeFromConfig(SecurityNamedServiceConfig config) throws IOException {
        this.name=config.getName();
        SecurityUserGroupServiceConfig ugConfig =(SecurityUserGroupServiceConfig) config;       
        passwordEncoderName=ugConfig.getPasswordEncoderName();
        GeoServerPasswordEncoder enc = getSecurityManager().loadPasswordEncoder(passwordEncoderName);

        if (enc.getEncodingType()==PasswordEncodingType.ENCRYPT) {
            KeyStoreProvider prov = getSecurityManager().getKeyStoreProvider();
            String alias = prov.aliasForGroupService(name);
            if (prov.containsAlias(alias)==false) {
                prov.setUserGroupKey(name,
                    getSecurityManager().getRandomPassworddProvider().getRandomPasswordWithDefaultLength());
                prov.storeKeyStore();
            }
        }
        enc.initializeFor(this);
        passwordValidatorName=ugConfig.getPasswordPolicyName();
        toBeEncrypted = (((MemoryUserGroupServiceConfigImpl)config).getToBeEncrypted());
    }
View Full Code Here

TOP

Related Classes of org.geoserver.security.config.SecurityUserGroupServiceConfig

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.