@Test
public void testRoleConfig() throws IOException {
super.testRoleConfig();
JDBCRoleServiceConfig config =
(JDBCRoleServiceConfig)createRoleConfig("jdbc", JDBCRoleService.class,
AbstractRoleService.DEFAULT_LOCAL_ADMIN_ROLE);
config.setDriverClassName("a.b.c");
config.setUserName("user");
config.setConnectURL("jdbc:connect");
config.setPropertyFileNameDDL(JDBCRoleService.DEFAULT_DDL_FILE);
config.setPropertyFileNameDML(JDBCRoleService.DEFAULT_DML_FILE);
JDBCRoleServiceConfig configJNDI = (JDBCRoleServiceConfig)
createRoleConfig("jndi", JDBCRoleService.class,
AbstractRoleService.DEFAULT_LOCAL_ADMIN_ROLE);
configJNDI.setJndi(true);
configJNDI.setJndiName("jndi:connect");
configJNDI.setPropertyFileNameDDL(JDBCRoleService.DEFAULT_DDL_FILE);
configJNDI.setPropertyFileNameDML(JDBCRoleService.DEFAULT_DML_FILE);
JdbcSecurityConfigValidator validator =
new JdbcSecurityConfigValidator(getSecurityManager());
try {
configJNDI.setJndiName("");
validator.validateAddRoleService(configJNDI);
//getSecurityManager().saveRoleService(configJNDI);
fail();
} catch (SecurityConfigException ex) {
assertEquals( JNDINAME_REQUIRED, ex.getId());
assertEquals(0, ex.getArgs().length);
}
try {
config.setDriverClassName("");
validator.validateAddRoleService(config);
//getSecurityManager().saveRoleService(config);
fail();
} catch (SecurityConfigException ex) {
assertEquals( DRIVER_CLASSNAME_REQUIRED, ex.getId());
assertEquals(0, ex.getArgs().length);
}
config.setDriverClassName("a.b.c");
try {
config.setUserName("");
validator.validateAddRoleService(config);
//getSecurityManager().saveRoleService(config);
fail();
} catch (SecurityConfigException ex) {
assertEquals( USERNAME_REQUIRED, ex.getId());
assertEquals(0, ex.getArgs().length);
}
config.setUserName("user");
try {
config.setConnectURL(null);
validator.validateAddRoleService(config);
//getSecurityManager().saveRoleService(config);
fail();
} catch (SecurityConfigException ex) {
assertEquals( JDBCURL_REQUIRED, ex.getId());
assertEquals(0, ex.getArgs().length);
}
config.setConnectURL("jdbc:connect");
try {
validator.validateAddRoleService(config);
//getSecurityManager().saveRoleService(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 {
validator.validateAddRoleService(config);
//getSecurityManager().saveRoleService(config);
} catch (SecurityConfigException ex) {
throw new IOException(ex);
}
GeoServerSecurityManager secMgr = createNiceMock(GeoServerSecurityManager.class);
expect(secMgr.listRoleServices()).andReturn(
new TreeSet<String>(Arrays.asList("default", "jdbc"))).anyTimes();
replay(secMgr);
validator = new JdbcSecurityConfigValidator(secMgr);
JDBCRoleServiceConfig oldConfig = new JDBCRoleServiceConfig(config);
config.setPropertyFileNameDML(null);
try {
//getSecurityManager().saveRoleService(config);
validator.validateModifiedRoleService(config, oldConfig);
fail();
} catch (SecurityConfigException ex) {
assertEquals( DML_FILE_REQUIRED, ex.getId());
assertEquals(0, ex.getArgs().length);
}
config.setPropertyFileNameDDL(JDBCRoleService.DEFAULT_DDL_FILE);
config.setPropertyFileNameDML(JDBCRoleService.DEFAULT_DML_FILE);
// run only if a temp dir is availbale
if (new JdbcSecurityConfigValidator(getSecurityManager()).getTempDir()!=null) {
oldConfig = new JDBCRoleServiceConfig(config);
String invalidPath="abc"+File.separator+"def.properties";
config.setPropertyFileNameDDL(invalidPath);
try {
//getSecurityManager().saveRoleService(config);
validator.validateModifiedRoleService(config, oldConfig);
fail();
} catch (SecurityConfigException ex) {
assertEquals(DDL_FILE_INVALID, ex.getId());
assertEquals(invalidPath, ex.getArgs()[0]);
}
}
config.setPropertyFileNameDDL(JDBCRoleService.DEFAULT_DDL_FILE);
config.setPropertyFileNameDML(JDBCRoleService.DEFAULT_DML_FILE);
// run only if a temp dir is availbale
if (new JdbcSecurityConfigValidator(getSecurityManager()).getTempDir()!=null) {
oldConfig = new JDBCRoleServiceConfig(config);
String invalidPath="abc"+File.separator+"def.properties";
config.setPropertyFileNameDML(invalidPath);
try {
//getSecurityManager().saveRoleService(config);
validator.validateModifiedRoleService(config, oldConfig);
fail();
} catch (SecurityConfigException ex) {
assertEquals(DML_FILE_INVALID, ex.getId());
assertEquals(invalidPath, ex.getArgs()[0]);
}
}
oldConfig = new JDBCRoleServiceConfig(config);
config.setPropertyFileNameDDL(null);
config.setCreatingTables(true);
config.setPropertyFileNameDML(JDBCRoleService.DEFAULT_DML_FILE);