@Override public GeoServerRoleStore createStore() throws IOException { MemoryRoleStore store = new MemoryRoleStore(); store.initializeFromService(this); return store; }
@SuppressWarnings("unchecked") @Override protected void deserialize() throws IOException { clearMaps(); byte[] bytes = ((MemoryRoleService) service).byteArray; if (bytes == null) { setModified(false); return; } ByteArrayInputStream in = new ByteArrayInputStream(bytes); ObjectInputStream oin = new ObjectInputStream(in); try { helper.roleMap = (TreeMap<String, GeoServerRole>) oin.readObject(); helper.role_parentMap = (HashMap<GeoServerRole, GeoServerRole>) oin.readObject(); helper.user_roleMap = (TreeMap<String, SortedSet<GeoServerRole>>) oin.readObject(); helper.group_roleMap = (TreeMap<String, SortedSet<GeoServerRole>>) oin.readObject(); } catch (ClassNotFoundException e) { throw new IOException(e); } setModified(false); }
/** 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()); }