2

Im trying to get all entities with the "OU=Users". Right now i can get all the entities but i just wanted the entities that belong to the group User.

I have tried to change my search request but everything failed:

SearchRequest searchRequest = new SearchRequest(ldapConfig.getBaseDn(), SearchScope.SUB,
                Filter.createEqualityFilter("(objectClass=Users)", "person"));

Here is the full code:

SearchRequest searchRequest = new SearchRequest(ldapConfig.getBaseDn(), SearchScope.SUB,
                Filter.createEqualityFilter("(objectClass=Users)", "person"));
        ASN1OctetString resumeCookie = null;
        while (true) {
            searchRequest.setControls(new SimplePagedResultsControl(10, resumeCookie));
            SearchResult searchResult = ldapConnection.search(searchRequest);
            numSearches++;
            totalEntriesReturned += searchResult.getEntryCount();
            for (SearchResultEntry e : searchResult.getSearchEntries()) {
                System.out.println(e.getDN());
            }
            cont++;
            LDAPTestUtils.assertHasControl(searchResult, SimplePagedResultsControl.PAGED_RESULTS_OID);
            SimplePagedResultsControl responseControl = SimplePagedResultsControl.get(searchResult);
            if (responseControl.moreResultsToReturn()) {
                // The resume cookie can be included in the simple paged results
                // control included in the next search to get the next page of results.
                resumeCookie = responseControl.getCookie();
            } else {
                break;
            }

Ldap sample:

CN=name,OU=Users,OU=group2,OU=group3,OU=group4,OU=group5,DC=dc1,DC=dc2
jose azevedo
  • 245
  • 2
  • 3
  • 19
  • Try changing your filter to "(&(objectClass=Users)(memberOf=User))", but replace the "memberOf" with the name of the attribute your LDAP server uses to represent the group name. Active Directory uses "memberOf" while Novell Directory uses "groupMembership", so your LDAP server may differ. – Palamino Mar 21 '19 at 17:20
  • Sorry but i tried in many ways but it doesnt retrieve me nothing, i tried to replace with both ways, i put a sample a LDAP dn on my question – jose azevedo Mar 21 '19 at 17:55
  • Do you want all the users within the "OU=Users" and that are members of what Group? Are you using Active Directory? – jwilleke Mar 23 '19 at 09:46
  • Yes I'm using active directory.Well i just want all the users of the OU=Users. – jose azevedo Mar 23 '19 at 10:44
  • 1
    Did you find any solution to this? I have similar requirement now. – jarvo69 Mar 26 '20 at 16:22

1 Answers1

0

You may try something close to:

fun exaple(baseDN: String = "DC=dc1,DC=dc2", groupName = "groupName") {
    val groupDN = "CN=$groupName,CN=Users,$baseDN"

    val filterForUsersInGroup = Filter.createANDFilter(
        Filter.createEqualityFilter("objectClass", "user"),
        Filter.createEqualityFilter("memberOf", groupDN)
    )

    client.search(baseDN, SearchScope.ONE, filterForUsersInGroup)
}