I'm building an application where I need to connect to Active Directory using UnboundID
. Using an example, I managed to connect a user with their distinguishedName
and password
.
However I would like to authenticate them using only the domain
and the username
, similar to how it's done in Windows. Browsing AD using a tool called JXplorer
it seems like the sAMAccountName
might be the property I need. However replacing the distinguishedName
with the sAMAccountName resulted in an AcceptSecurityContext
error. Using the "uid=..."
syntax shown in the example also yielded the same error.
Is there a way to logon using only the domain, username
/sAMAccountName
and password
. or do I somehow need to search through AD and find the distinguishedName
of the user I wish to authenticate, and then bind the connection using their distinguishedName
and password
?
As @ioplex said in his comment, AD accepts a bind using the username from the sAMAccountName with the domain name appended to it. Just use it instead of the DN on the bind:
String userId = username + "@" + domain;
SimpleBindRequest adminBindRequest = new SimpleBindRequest(userId, passsword);
The final userId will be something like '[email protected]'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With