views:

148

answers:

2

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().

+2  A: 

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.

Alex Beardsley
I've also used Spring LDAP. It's awesome compared to writing "raw" LDAP code.
Vinnie
A: 

I haven't tried it yet but this may also be useful: http://www.ibm.com/developerworks/tivoli/library/t-ldap-controls/

regjo