Package org.geoserver.security.jdbc.config

Examples of org.geoserver.security.jdbc.config.JDBCUserGroupServiceConfig


   
   
   
    @Override
    protected SecurityNamedServiceConfig createNewConfigObject() {
        return new JDBCUserGroupServiceConfig();
    }
View Full Code Here


        return property != null && "false".equals(property.toLowerCase());                
    }
   
    protected static JDBCUserGroupServiceConfig createConfigObjectH2(String serviceName,
                    GeoServerSecurityManager securityManager) {
        JDBCUserGroupServiceConfig config = new JDBCUserGroupServiceConfig();          
        config.setName(serviceName);
        config.setConnectURL("jdbc:h2:target/h2/security");
        config.setDriverClassName("org.h2.Driver");
        config.setUserName("sa");
        config.setPassword("");                           
        config.setClassName(JDBCUserGroupService.class.getName());
        config.setPropertyFileNameDDL(JDBCUserGroupService.DEFAULT_DDL_FILE);
        config.setPropertyFileNameDML(JDBCUserGroupService.DEFAULT_DML_FILE);
        config.setCreatingTables(false);
        config.setPasswordEncoderName(
            securityManager.loadPasswordEncoder(GeoServerDigestPasswordEncoder.class).getName());
        config.setPasswordPolicyName(PasswordValidator.DEFAULT_NAME);
        return config;
       
    }
View Full Code Here

        return securityManager.loadUserGroupService(serviceName);
    }
   
   
    protected static JDBCUserGroupServiceConfig createConfigObjectH2Jndi( String serviceName ,GeoServerSecurityManager securityManager) {
        JDBCUserGroupServiceConfig config = new JDBCUserGroupServiceConfig();          
        config.setName(serviceName);
        config.setJndi(true);
        config.setJndiName("ds.h2");
        config.setClassName(JDBCUserGroupService.class.getName());
        config.setPropertyFileNameDDL(JDBCUserGroupService.DEFAULT_DDL_FILE);
        config.setPropertyFileNameDML(JDBCUserGroupService.DEFAULT_DML_FILE);
        config.setCreatingTables(false);
        config.setPasswordEncoderName(
            securityManager.loadPasswordEncoder(GeoServerDigestPasswordEncoder.class).getName());
        config.setPasswordPolicyName(PasswordValidator.DEFAULT_NAME);
        return config;
       
    }
View Full Code Here

        securityManager.saveRoleService(config);
        return securityManager.loadRoleService(fixtureId);
    }
   
    static protected JDBCUserGroupServiceConfig createConfigObject(String fixtureId,LiveDbmsDataSecurity data,GeoServerSecurityManager securityManager) throws Exception {
        JDBCUserGroupServiceConfig config = new
        JDBCUserGroupServiceConfig();
       
        Properties props=Util.loadUniversal(new FileInputStream(data.getFixture()));
   
        config.setName(fixtureId);       
        config.setConnectURL(props.getProperty("url"));
        config.setDriverClassName(props.getProperty("driver"));
        config.setUserName(props.getProperty("user")== null ? props.getProperty("username"): props.getProperty("user"));
        config.setPassword(props.getProperty("password"));                      
        config.setClassName(JDBCUserGroupService.class.getName());
        config.setCreatingTables(false);
        config.setPasswordEncoderName(
            securityManager.loadPasswordEncoder(GeoServerDigestPasswordEncoder.class).getName());
        config.setPasswordPolicyName(PasswordValidator.DEFAULT_NAME);
        if ("mysql".equals(fixtureId)) {
            config.setPropertyFileNameDDL("usersddl.mysql.xml");           
        } else {
            config.setPropertyFileNameDDL(JDBCUserGroupService.DEFAULT_DDL_FILE);
        }
        config.setPropertyFileNameDML(JDBCUserGroupService.DEFAULT_DML_FILE);
        return config;
       
    }
View Full Code Here

   
   
    @Override
    protected SecurityUserGroupServiceConfig createUGConfig(String name, Class<?> aClass,
            String encoder, String policyName) {
        JDBCUserGroupServiceConfig config = new JDBCUserGroupServiceConfig();
        config.setName(name);
        config.setClassName(aClass.getName());
        config.setPasswordEncoderName(encoder);
        config.setPasswordPolicyName(policyName);
        config.setCreatingTables(false);
        return config;
    }
View Full Code Here

    @Test
    public void testUserGroupConfig() throws IOException {

        super.testUserGroupConfig();
       
        JDBCUserGroupServiceConfig  config =
                (JDBCUserGroupServiceConfig)createUGConfig("jdbc", JDBCUserGroupService.class,
                getPlainTextPasswordEncoder().getName() ,PasswordValidator.DEFAULT_NAME);

        config.setDriverClassName("a.b.c");
        config.setUserName("user");
        config.setConnectURL("jdbc:connect");
        config.setPropertyFileNameDDL(JDBCUserGroupService.DEFAULT_DDL_FILE);
        config.setPropertyFileNameDML(JDBCUserGroupService.DEFAULT_DML_FILE);


        JDBCUserGroupServiceConfig  configJNDI = (JDBCUserGroupServiceConfig)
                createUGConfig("jdbc", JDBCUserGroupService.class,
                getPlainTextPasswordEncoder().getName(),PasswordValidator.DEFAULT_NAME);
        configJNDI.setJndi(true);                       
        configJNDI.setJndiName("jndi:connect");
        configJNDI.setPropertyFileNameDDL(JDBCUserGroupService.DEFAULT_DDL_FILE);
        configJNDI.setPropertyFileNameDML(JDBCUserGroupService.DEFAULT_DML_FILE);

        JdbcSecurityConfigValidator validator =
                new JdbcSecurityConfigValidator(getSecurityManager());
        try {           
            configJNDI.setJndiName("");
            //getSecurityManager().saveUserGroupService(configJNDI);
            validator.validateAddUserGroupService(configJNDI);
            fail();
        } catch (SecurityConfigException ex) {
            assertEquals(JNDINAME_REQUIRED, ex.getId());
            assertEquals(0, ex.getArgs().length);
        }

        try {           
            config.setDriverClassName("");
            //getSecurityManager().saveUserGroupService(config);
            validator.validateAddUserGroupService(config);
            fail();
        } catch (SecurityConfigException ex) {
            assertEquals( DRIVER_CLASSNAME_REQUIRED, ex.getId());
            assertEquals(0, ex.getArgs().length);
        }

        config.setDriverClassName("a.b.c");
        try {           
            config.setUserName("");
            //getSecurityManager().saveUserGroupService(config);
            validator.validateAddUserGroupService(config);
            fail();
        } catch (SecurityConfigException ex) {
            assertEquals( USERNAME_REQUIRED, ex.getId());
            assertEquals(0, ex.getArgs().length);
        }

        config.setUserName("user");
        try {           
            config.setConnectURL(null);
            //getSecurityManager().saveUserGroupService(config);
            validator.validateAddUserGroupService(config);
            fail();
        } catch (SecurityConfigException ex) {
            assertEquals( JDBCURL_REQUIRED, ex.getId());
            assertEquals(0, ex.getArgs().length);
        }
       
        config.setConnectURL("jdbc:connect");
        try {           
            //getSecurityManager().saveUserGroupService(config);
            validator.validateAddUserGroupService(config);
            fail();
        } catch (SecurityConfigException ex) {
            assertEquals( DRIVER_CLASS_NOT_FOUND_$1, ex.getId());
            assertEquals("a.b.c", ex.getArgs()[0]);
        }

        config.setDriverClassName("java.lang.String");
        config.setPropertyFileNameDDL(null);
        try {
            //getSecurityManager().saveUserGroupService(config);
            validator.validateAddUserGroupService(config);
        } catch (SecurityConfigException ex) {
            throw new IOException(ex);
        }

        GeoServerSecurityManager secMgr = createNiceMock(GeoServerSecurityManager.class);
        expect(secMgr.listUserGroupServices()).andReturn(
            new TreeSet<String>(Arrays.asList("default", "jdbc"))).anyTimes();
       
        GeoServerPlainTextPasswordEncoder pwEncoder = getPlainTextPasswordEncoder();
        expect(secMgr.loadPasswordEncoder(pwEncoder.getName())).andReturn(pwEncoder).anyTimes();
        expect(secMgr.listPasswordValidators()).andReturn(
            new TreeSet<String>(Arrays.asList(PasswordValidator.DEFAULT_NAME))).anyTimes();
        replay(secMgr);

        validator = new JdbcSecurityConfigValidator(secMgr);

        JDBCUserGroupServiceConfig oldConfig = new JDBCUserGroupServiceConfig(config);

        config.setPropertyFileNameDML(null);
        try {           
            //getSecurityManager().saveUserGroupService(config);
            validator.validateModifiedUserGroupService(config, oldConfig);
            fail();
        } catch (SecurityConfigException ex) {
            assertEquals( DML_FILE_REQUIRED, ex.getId());
            assertEquals(0, ex.getArgs().length);
        }

        config.setPropertyFileNameDDL(JDBCUserGroupService.DEFAULT_DDL_FILE);
        config.setPropertyFileNameDML(JDBCUserGroupService.DEFAULT_DML_FILE);
       
        // run only if a temp dir is availbale
        if (new JdbcSecurityConfigValidator(getSecurityManager()).getTempDir()!=null) {
            oldConfig = new JDBCUserGroupServiceConfig(config);
            String invalidPath="abc"+File.separator+"def.properties";
            config.setPropertyFileNameDDL(invalidPath);
            try {
                //getSecurityManager().saveUserGroupService(config);
                validator.validateModifiedUserGroupService(config, oldConfig);
                fail();
            } catch (SecurityConfigException ex) {
                assertEquals(DDL_FILE_INVALID, ex.getId());
                assertEquals(invalidPath,  ex.getArgs()[0]);
            }
        }
        config.setPropertyFileNameDDL(JDBCUserGroupService.DEFAULT_DDL_FILE);
        config.setPropertyFileNameDML(JDBCUserGroupService.DEFAULT_DML_FILE);
        // run only if a temp dir is availbale
        if (new JdbcSecurityConfigValidator(getSecurityManager()).getTempDir()!=null) {
            oldConfig = new JDBCUserGroupServiceConfig(config);
            String invalidPath="abc"+File.separator+"def.properties";
            config.setPropertyFileNameDML(invalidPath);
            try {
                //getSecurityManager().saveUserGroupService(config);
                validator.validateModifiedUserGroupService(config, oldConfig);
View Full Code Here

        passwordEncoderName=((SecurityUserGroupServiceConfig)config).getPasswordEncoderName();
        passwordValidatorName=((SecurityUserGroupServiceConfig)config).getPasswordPolicyName();
        initializeDSFromConfig(config);

        if (config instanceof JDBCUserGroupServiceConfig) {
            JDBCUserGroupServiceConfig jdbcConfig =
                (JDBCUserGroupServiceConfig) config;
           
            String fileNameDML =jdbcConfig.getPropertyFileNameDML();
            File file = checkORCreateJDBCPropertyFile(fileNameDML, getConfigRoot(), DEFAULT_DML_FILE);
            dmlProps = Util.loadUniversal(new FileInputStream(file));
           
            String fileNameDDL =jdbcConfig.getPropertyFileNameDDL();
            if (fileNameDDL!=null && fileNameDDL.length()> 0 ) {
                file = checkORCreateJDBCPropertyFile(fileNameDDL, getConfigRoot(), DEFAULT_DDL_FILE);
                ddlProps = Util.loadUniversal(new FileInputStream(file));
                createTablesIfRequired((JDBCSecurityServiceConfig)config);
            }
           
            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=jdbcConfig.getPasswordPolicyName();

        }
    }
View Full Code Here

    String base = "form:" + relBase;

    JDBCSecurityServiceConfig config;

    protected void setupPanel(final boolean jndi) {
        config = new JDBCUserGroupServiceConfig();
        config.setJndi(jndi);
        setupPanel(config);
    }
View Full Code Here

        assertEquals("jndiurl", config.getJndiName());
    }

    @Test
    public void testConnectionTestJNDI() throws Exception {
        JDBCUserGroupServiceConfig theConfig = new JDBCUserGroupServiceConfig();
        theConfig.setJndi(true);
        theConfig.setJndiName("jndiurl");
       
        setupPanel(theConfig);
        tester.assertRenderedPage(FormTestPage.class);
        tester.clickLink("form:panel:cxTest", true);
        assertEquals(1, tester.getMessages(FeedbackMessage.ERROR).size());
View Full Code Here

        assertEquals("jdbc:h2", config.getConnectURL());
    }

    @Test
    public void testConncetionTestBasic() throws Exception {
        JDBCUserGroupServiceConfig theConfig = new JDBCUserGroupServiceConfig();
        theConfig.setUserName("user1");
        theConfig.setPassword("pw");
        theConfig.setDriverClassName("org.h2.Driver");
        theConfig.setConnectURL("jdbc:foo");
       
        setupPanel(theConfig);
        tester.assertRenderedPage(FormTestPage.class);

        tester.clickLink("form:panel:cxTest", true);
View Full Code Here

TOP

Related Classes of org.geoserver.security.jdbc.config.JDBCUserGroupServiceConfig

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.