How to get specific errors when using ppolicy in LDAP from Java using JNDI

I am using JNDI for authentication in a web application. On the OpenLDAP side, I use ppolicy to (for example) lock my user account after three failed login attempts.

My problem is that I need specific error messages (for example, “Account is locked”), so that the user knows what the problem is, but right now I get an exception on execution:

InitialLdapContext ctx = new InitialLdapContext(env, null);

And the message in the exception is simple [LDAP: error code 49 - Invalid Credentials].

I found a related post that shows an example of how to do this; nonetheless, it just baffles me, as I could not find classes like PasswordExpiringResponseControlanywhere, plus I immediately get an exception, so I could not execute respControls = ctx.getResponseControls().

+3
source share
3 answers

It may be more painful than worth it, but if you use Spring-LDAP , it automatically converts these error codes into good exceptions. In any case, the library is very good and is likely to make your code cleaner and easier to maintain in the long run.

Spring, ; , , , , JNDI ..

+3

I have not tried it yet, but it may also be useful: http://www.ibm.com/developerworks/tivoli/library/t-ldap-controls/

0
source

Source: https://habr.com/ru/post/1735100/


All Articles