I have started to use UnboundID to implement the authentication against LDAP. I implemented the authentication as following:
Connect to LDAP
ldapConnection = new LDAPConnection(host, port, bindUserDN, bindUserPassword);
Search user DN:
Filter.create("(sAMAccountName=" + userName + ")");
SearchRequest searchRequest =
new SearchRequest(baseDN, SearchScope.SUB,
DereferencePolicy.NEVER, 0, 0, false, filter,
attributesToReturn);
SearchResult searchResult = ldapConnection.search(searchRequest);`
Bind a user
SimpleBindRequest bindRequest = new SimpleBindRequest(searchResultEntry.getDN(), userPassword);
BindResult bindResult = ldapConnection.bind(bindRequest);
Unfortunately, after the last bind using a user DN and a user password ldapConnection
is changed to the user DN (and not the bind User DN). I checked it using ldapConnection.getLastBindRequest()
.
Therefore, I can not use it for father entries retrieval (e.g. group retrieval) since the user does not have an appropriate permission.
Is it expected behavior that ldapConnection
changes a user?
How to preserve LDAP bind user connection after a user authentication?
Should I reconnect using bindUserDN before any LDAP operation (or at least after the authentication)?