0
votes

While trying to login to an ldap server with an expired password an exception is thrown in the logging.

javax.naming.AuthenticationException: [LDAP: error code 49 - 80090308: LdapErr: DSID-0C0903A9, comment: AcceptSecurityContext error, data 773, v1db0

I want to give the user a corresponding message, but i'm not able to catch that exception. (how can i get the exception that's shown in the logging ? because data 773 means the password is expired

                CallbackHandler handler = new UsernamePasswordHandler(
                        username, password);
                LoginContext lc = new LoginContext(applicationPolicyName,
                        handler);

                try {
                    lc.login();
                } catch (Exception){
                    log.warn(e.getMessage());
                }
2
note: the exeption in the logging is not thrown by log.warn(e.getMessage());PinkFloyd
One of the many reasons to not use JNDI, it is strange, counter-intuitive, and difficult to deal with simple things like size limit exceeded result codes, time limit exceeded result codes and other similar very basic LDAP topics. I would recommend that developers not use JNDI for new code, but prefer the UnboundID LDAP SDK. The standard edition is free to use. Also, you may be interested in LDAP: Programming Practices.Terry Gardner

2 Answers

1
votes

You need to get hold of the exception stack trace. (If necessary, change your logging configs so that the stacktrace is written to the logs.)

That will tell you where the exception is being thrown.

Then examine the source code to see where it is being caught and logged, and see if there is any of your code upstack that could catch it first.

1
votes

assuming that what you want to catch are those of type javax.naming.AuthenticationException, you can put it in a try catch block as:

try {
  lc.login();
} catch(AuthenticationException e) {
   processError(e.getMessage());
}

...
private void processError(String errorMessage) {
  if (errorMessage.contains("data 773")) {
     // then do your stuff here like add error message as label etc
  }
}