UserAndRoleDirectoryServiceImpl implements UserDirectoryService, UserDetailsService, RoleDirectoryService { @Override public User loadUser(String userName) throws IllegalStateException { Organization org = securityService.getOrganization(); if (org == null) { throw new IllegalStateException("No organization is set"); } Object user = cache.getUnchecked(tuple(org.getId(), userName)); if (user == nullToken) { cache.invalidate(tuple(org.getId(), userName)); return null; } else { return (User) user; } }  @Override Iterator<User> getUsers(); @Override User loadUser(String userName); @Override Iterator<User> loadUsers(Collection<String> userNames); @Override UserDetails loadUserByUsername(String userName); @Reference(name = "securityService") void setSecurityService(SecurityService securityService); @Override Iterator<User> findUsers(String query, int offset, int limit); @Override List<Role> findRoles(String query, Role.Target target, int offset, int limit); @Override long countUsers(); @Override void invalidate(String userName); static final String USER_CACHE_SIZE_KEY; static final String USER_CACHE_EXPIRY_KEY; }
@Test public void testUserMerge() throws Exception { User mergedUser = directory.loadUser(userName); Set<Role> roles = mergedUser.getRoles(); assertTrue(roles.contains(role1)); assertTrue(roles.contains(role2)); assertTrue(roles.contains(role3)); assertNotNull(mergedUser.getPassword()); assertEquals(org.getId(), mergedUser.getOrganization().getId()); assertEquals(userName, mergedUser.getUsername()); assertEquals("matterhorn,test", mergedUser.getProvider()); assertTrue(mergedUser.isManageable()); assertTrue(((JaxbUser) mergedUser).isManageable()); }