Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm using JNDI for authentication in a web app. On the OpenLDAP side I'm using ppolicy to (for example) block a user's account after three failed log in attempts.

My problem is that I need specific error messages (e.g. "Account locked") to let the user know what was the specific problem but right now I'm just getting an exception when executing:

InitialLdapContext ctx = new InitialLdapContext(env, null);

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

I found a related post that shows an example of how to do just that; however, it is just confusing me more since I haven't been able to locate classes such as PasswordExpiringResponseControl anywhere, plus I'm getting an exception right away so I wouldn't be able to execute respControls = ctx.getResponseControls().

like image 584
regjo Avatar asked May 13 '26 01:05

regjo


1 Answers

This may be more of a pain than it's worth, but if you use Spring-LDAP, it will auto convert those error codes into nice exceptions. The library is really nice anyway and will probably make your code cleaner and more maintainable in the long run.

If you're not familiar with Spring, then there may be a bit of a learning curve; however, if you do want to go that route, this is a good article on it, including how to set it up with JNDI and etc.

like image 130
Alex Beardsley Avatar answered May 15 '26 13:05

Alex Beardsley



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!