LDAPUserGroupCallbackImpl extends AbstractLDAPUserGroupInfo implements UserGroupCallback { @Override public List<String> getGroupsForUser(String userId) { String roleContext = getConfigProperty(USER_ROLES_CTX, getConfigProperty(ROLE_CTX)); String roleFilter = getConfigProperty(USER_ROLES_FILTER); String roleAttributeId = getConfigProperty(ROLE_ATTR_ID, DEFAULT_ROLE_ATTR_ID); String userDn = userId; if (!isUserIdDn()) { String userContext = getConfigProperty(USER_CTX); String userFilter = getConfigProperty(USER_FILTER); SearchResult searchResult = ldapSearcher.search(userContext, userFilter, userId).getSingleSearchResult(); userDn = searchResult.getNameInNamespace(); } List<String> result = ldapSearcher.search(roleContext, roleFilter, userDn).getAttributeResults(roleAttributeId); return result.stream().map(r-> unescapeIllegalChars(r)).collect(Collectors.toList()); } LDAPUserGroupCallbackImpl(boolean activate);  LDAPUserGroupCallbackImpl(Properties config); @Override boolean existsUser(String userId); @Override boolean existsGroup(String groupId); @Override List<String> getGroupsForUser(String userId); static final String USER_CTX; static final String ROLE_CTX; static final String USER_ROLES_CTX; static final String USER_FILTER; static final String ROLE_FILTER; static final String USER_ROLES_FILTER; static final String USER_ATTR_ID; static final String ROLE_ATTR_ID; static final String IS_USER_ID_DN; static final String SEARCH_SCOPE; static final String LDAP_NAME_ESCAPE; }
@Test public void testGroupsForUser() { UserGroupCallback ldapUserGroupCallback = createLdapUserGroupCallback(Configuration.CUSTOM); Assertions.assertThat(ldapUserGroupCallback).isNotNull(); List<String> userGroups = ldapUserGroupCallback.getGroupsForUser("john"); Assertions.assertThat(userGroups).hasSize(1); }
@Test public void testGroupsForUserDefaultProperties() { UserGroupCallback ldapUserGroupCallback = createLdapUserGroupCallback(Configuration.DEFAULT); Assertions.assertThat(ldapUserGroupCallback).isNotNull(); List<String> userGroups = ldapUserGroupCallback.getGroupsForUser("john"); Assertions.assertThat(userGroups).hasSize(1); }
@Test public void testGroupsForUserSystemProperties() { UserGroupCallback ldapUserGroupCallback = createLdapUserGroupCallback(Configuration.SYSTEM); Assertions.assertThat(ldapUserGroupCallback).isNotNull(); List<String> userGroups = ldapUserGroupCallback.getGroupsForUser("john"); Assertions.assertThat(userGroups).hasSize(1); }
@Test public void testGroupsForUserWithCommaInDN() { UserGroupCallback ldapUserGroupCallback = createLdapUserGroupCallback(Configuration.CUSTOM); Assertions.assertThat(ldapUserGroupCallback).isNotNull(); List<String> userGroups = ldapUserGroupCallback.getGroupsForUser("john,jr"); Assertions.assertThat(userGroups).hasSize(1).allMatch(s -> s.equals("manager,eng")); }