pingidentity / ldapsdk

UnboundID LDAP SDK for Java
Other
327 stars 79 forks source link

In order to perform this operation a successful bind must be completed on the connection #142

Open parthp2107 opened 1 year ago

parthp2107 commented 1 year ago

000004DC: LdapErr: DSID-0C090A5A, comment: In order to perform this operation a successful bind must be completed on the connection., data 0, v4f7c

dirmgr commented 1 year ago

There's not really any actual question here, but I assume that you're encountering this error and would like to know why.

First, that error is coming from the directory server (Active Directory by the looks of it), and not from the LDAP SDK itself.

Second, unlike many messages from Active Directory, this one is actually pretty clear. As the message states, the client needs to send a bind request to authenticate the connection before it will allow the operation you've requested.

parthp2107 commented 1 year ago

Can you please guide me on how I can perform a bind request to authenticate the connection?

dirmgr commented 1 year ago

Use the LDAPConnection.bind method to submit an appropriate bind request. The easiest and most common type of bind is an LDAP simple bind, which authenticates with the DN and password for the user as whom you're trying to authenticate. If you don't have the DN and password for a user account, then you'll need to talk to a server administrator.

Also, binds are one of the most fundamental concepts in LDAP. If you don't really understand them, then you should probably spend some time learning more about LDAP before proceeding.

parthp2107 commented 1 year ago

ldapConnectionPool.bind(storedUser.getName(), reqPassword);

I am using this in my code. Is this what you are suggesting to use? I have the DN and the password.

dirmgr commented 1 year ago

That call will perform a bind on a connection from the connection pool, but the problem is that if you subsequently try to perform another operation that requires a previous bind, if your connection pool has more than one connection, then there's no guarantee that it will choose the same connection for the bind as another operation that follows it.

If you want to use the same credentials for all operations processed in the connection pool, then the best option would be to provide the credentials at the time you create the connection pool. The way that you do this depends on how you're creating the pool.

On the other hand, if you want most connections in the pool to either be unauthenticated, or authenticated as a different user, then you have a couple of options. But if the bind should just be considered temporary, then you'll probably need to check a connection out of the pool using the getConnection method, use that connection to perform the bind and the subsequent operations that need to be authenticated as that user, then return the connection back to the pool using the releaseAndReAuthenticateConnection method. The releaseAndReAuthenticateConnection method will attempt to revert the connection back to the authentication state it had when the connection was initially established by the pool (and if it was initially unauthenticated, then the pool will use an anonymous simple bind to try to achieve that).