setActiveRoleService(roleService);
protected void setServices(String serviceName) throws Exception { roleService = createRoleService(serviceName); usergroupService = createUserGroupService(serviceName); roleStore = createStore(roleService); usergroupStore = createStore(usergroupService); getSecurityManager().setActiveRoleService(roleService); // getSecurityManager().saveSecurityConfig(config)setActiveUserGroupService(usergroupService); }
/** Test that active role service is applied in the LDAPAuthenticationProvider */ @Test public void testRoleService() throws Exception { Assume.assumeTrue(LDAPTestUtils.initLdapServer(true, ldapServerUrl, basePath)); ((LDAPSecurityServiceConfig) config).setUserDnPattern("uid={0},ou=People"); createAuthenticationProvider(); authProvider.setSecurityManager(securityManager); securityManager.setProviders(Collections.singletonList(authProvider)); MemoryRoleStore roleService = new MemoryRoleStore(); roleService.initializeFromService(new MemoryRoleService()); roleService.setSecurityManager(securityManager); GeoServerRole role = roleService.createRoleObject("MyRole"); roleService.addRole(role); roleService.associateRoleToUser(role, "other"); securityManager.setActiveRoleService(roleService); Authentication result = authProvider.authenticate(authenticationOther); assertTrue(result.getAuthorities().contains(role)); assertEquals(3, result.getAuthorities().size()); }
roleStore.associateRoleToUser(GeoServerRole.ADMIN_ROLE, "sa"); roleStore.store(); getSecurityManager().setActiveRoleService(roleService);
roleStore.associateRoleToUser(GeoServerRole.ADMIN_ROLE, "sa"); roleStore.store(); getSecurityManager().setActiveRoleService(roleService);
@Override protected void setServices(String serviceName) throws Exception { if (getSecurityManager().loadRoleService(getFixtureId()) == null) super.setServices(getFixtureId()); else { roleService = getSecurityManager().loadRoleService(getFixtureId()); roleStore = createStore(roleService); usergroupService = getSecurityManager().loadUserGroupService(getFixtureId()); usergroupStore = createStore(usergroupService); getSecurityManager().setActiveRoleService(roleService); } }
GeoServerSecurityManager manager = GeoServerExtensions.bean(GeoServerSecurityManager.class); service.setSecurityManager(manager); manager.setActiveRoleService(service); manager.saveRoleService(config);
protected static GeoServerRoleService createH2RoleService( String serviceName, GeoServerSecurityManager securityManager) throws Exception { if (securityManager.listRoleServices().contains(serviceName)) { if (securityManager.getActiveRoleService().getName().equals(serviceName)) { GeoServerRoleService roleService = securityManager.loadRoleService("default"); securityManager.setActiveRoleService(roleService); } GeoServerRoleService service = securityManager.loadRoleService(serviceName); if (service.canCreateStore()) { GeoServerRoleStore store = service.createStore(); store.clear(); store.store(); } SecurityRoleServiceConfig old = securityManager.loadRoleServiceConfig(serviceName); securityManager.removeRoleService(old); } JDBCRoleServiceConfig config = new JDBCRoleServiceConfig(); config.setName(serviceName); config.setConnectURL("jdbc:h2:target/h2/security"); config.setDriverClassName("org.h2.Driver"); config.setUserName("sa"); config.setPassword(""); config.setClassName(JDBCRoleService.class.getName()); config.setPropertyFileNameDDL(JDBCRoleService.DEFAULT_DDL_FILE); config.setPropertyFileNameDML(JDBCRoleService.DEFAULT_DML_FILE); config.setCreatingTables(false); securityManager.saveRoleService(config); return securityManager.loadRoleService(serviceName); }
roleStore.associateRoleToUser(GeoServerRole.ADMIN_ROLE, sa.getUsername()); roleStore.store(); getSecurityManager().setActiveRoleService(roleService);
roleStore.associateRoleToUser(GeoServerRole.ADMIN_ROLE, sa.getUsername()); roleStore.store(); getSecurityManager().setActiveRoleService(roleService);
@Override protected void onSetUp(SystemTestData testData) throws Exception { super.onSetUp(testData); // set up the services GeoServerUserGroupService ugService = createUserGroupService("gaugs"); GeoServerRoleService roleService = createRoleService("gars"); getSecurityManager().setActiveRoleService(roleService); // add the users GeoServerUserGroupStore ugStore = createStore(ugService); GeoServerUser bob = ugStore.createUserObject("bob", "foobar", true); GroupAdminProperty.set(bob.getProperties(), new String[] {"users"}); ugStore.addUser(bob); GeoServerUser alice = ugStore.createUserObject("alice", "foobar", true); ugStore.addUser(alice); GeoServerUserGroup users = ugStore.createGroupObject("users", true); ugStore.addGroup(users); GeoServerUserGroup admins = ugStore.createGroupObject("admins", true); ugStore.addGroup(admins); ugStore.store(); // grant bob group admin privilege GeoServerRole groupAdminRole = null; GeoServerRoleStore roleStore = createStore(roleService); roleStore.addRole(roleStore.createRoleObject("adminRole")); roleStore.addRole(groupAdminRole = roleStore.createRoleObject("groupAdminRole")); roleStore.associateRoleToUser(groupAdminRole, bob.getUsername()); roleStore.store(); }