Mert Serimer
Mert Serimer

Reputation: 1255

unboundid ldap SDK how to get all users and exclude a department

I have sample code

Filter searchFilter = Filter.create("(sAMAccountType=805306368)");
                        SearchRequest searchRequest =
                                new SearchRequest(advanceBaseDnTxt.getText(), SearchScope.SUB, searchFilter,
                                        ldapAttributeSet);
                        SearchResult searchResult = lcon.search(searchRequest);

Is this enough for retreiving all users and how to exclude a department also?

Upvotes: 0

Views: 1199

Answers (1)

Esteban
Esteban

Reputation: 1815

To negate an attribute on a LDAP filter, look at this page : http://www.ldapexplorer.com/en/manual/109010000-ldap-filter-syntax.htm

(!(department=<NUMBER TO EXCLUDE>)) Should be used

If you need to filter on multiple attributes, from your example you need every entries which have sAMAccountType=805306368 and are not in department=<NUMBER TO EXCLUDE>, so the filter will be :

(&(sAMAccountType=805306368)(!(department=<NUMBER TO EXCLUDE>)))

Upvotes: 1

Related Questions