@Override public SecurityConfig clone(boolean allowEnvParametrization) { final GeoServerEnvironment gsEnvironment = GeoServerExtensions.bean(GeoServerEnvironment.class); SecurityManagerConfig target = (SecurityManagerConfig) SerializationUtils.clone(this); if (target != null) { if (allowEnvParametrization && gsEnvironment != null && GeoServerEnvironment.ALLOW_ENV_PARAMETRIZATION) { target.setConfigPasswordEncrypterName( (String) gsEnvironment.resolveValue(configPasswordEncrypterName)); target.setRoleServiceName((String) gsEnvironment.resolveValue(roleServiceName)); } } return target; } }
config.setRoleServiceName(roleService.getName()); config.getAuthProviderNames().add(authProvider.getName()); config.setEncryptingUrlParams(false);
protected void createServices() throws Exception { GeoServerRoleService rservice = createRoleService("rs1"); GeoServerRoleStore rstore = rservice.createStore(); GeoServerRole root, derived; rstore.addRole(root = rstore.createRoleObject(rootRole)); rstore.addRole(derived = rstore.createRoleObject(derivedRole)); rstore.setParentRole(derived, root); rstore.associateRoleToUser(derived, testUserName); rstore.associateRoleToUser(derived, "castest"); rstore.store(); SecurityManagerConfig mconfig = getSecurityManager().loadSecurityConfig(); mconfig.setRoleServiceName("rs1"); getSecurityManager().saveSecurityConfig(mconfig); GeoServerUserGroupService ugservice = createUserGroupService("ug1"); GeoServerUserGroupStore ugstore = ugservice.createStore(); GeoServerUser u1 = ugstore.createUserObject(testUserName, testPassword, true); ugstore.addUser(u1); GeoServerUser u2 = ugstore.createUserObject("abc@xyz.com", "abc", true); ugstore.addUser(u2); GeoServerUser u3 = ugstore.createUserObject("castest", "castest", true); ugstore.addUser(u3); ugstore.store(); GeoServerAuthenticationProvider prov = createAuthProvider(testProviderName, ugservice.getName()); prepareAuthProviders(prov.getName()); }
@Test public void testGeoServerEnvParametrization() throws Exception { GeoServerSecurityManager secMgr = getSecurityManager(); SecurityManagerConfig config = secMgr.loadSecurityConfig(); String oldRoleServiceName = config.getRoleServiceName(); try { if (GeoServerEnvironment.ALLOW_ENV_PARAMETRIZATION) { System.setProperty("TEST_SYS_PROPERTY", oldRoleServiceName); config.setRoleServiceName("${TEST_SYS_PROPERTY}"); secMgr.saveSecurityConfig(config); SecurityManagerConfig config1 = secMgr.loadSecurityConfig(); assertEquals(config1.getRoleServiceName(), oldRoleServiceName); } } finally { config.setRoleServiceName(oldRoleServiceName); secMgr.saveSecurityConfig(config); System.clearProperty("TEST_SYS_PROPERTY"); } } }
@Test public void testMasterConfigValidation() throws Exception { SecurityManagerConfig config = new SecurityManagerConfig(); config.setRoleServiceName(XMLRoleService.DEFAULT_NAME); config.setConfigPasswordEncrypterName(getPBEPasswordEncoder().getName()); config.getAuthProviderNames().add(GeoServerAuthenticationProvider.DEFAULT_NAME); config.setRoleServiceName("XX"); config.setRoleServiceName(null); try { validator.validateManagerConfig(config, new SecurityManagerConfig()); config.setRoleServiceName(XMLRoleService.DEFAULT_NAME); config.getAuthProviderNames().add("XX");