@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);