无法从日志记录中捕获异常
尝试使用过期密码登录 LDAP 服务器时,日志记录中会引发异常。
javax.naming.AuthenticationException:[LDAP:错误代码 49 - 80090308: LdapErr:DSID-0C0903A9,注释:AcceptSecurityContext 错误,数据 773、v1db0
我想给用户一个相应的消息,但我无法捕获该异常。 (我怎样才能得到日志记录中显示的异常?因为数据773意味着密码已过期
CallbackHandler handler = new UsernamePasswordHandler(
username, password);
LoginContext lc = new LoginContext(applicationPolicyName,
handler);
try {
lc.login();
} catch (Exception){
log.warn(e.getMessage());
}
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());
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要掌握异常堆栈跟踪。 (如有必要,请更改日志记录配置,以便将堆栈跟踪写入日志。)
这将告诉您抛出异常的位置。
然后检查源代码以查看它在哪里被捕获和记录,并查看是否有任何代码堆栈可以首先捕获它。
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.
假设您要捕获的是 javax.naming.AuthenticationException 类型的异常,您可以将其放入 try catch 块中,如下所示:
assuming that what you want to catch are those of type javax.naming.AuthenticationException, you can put it in a try catch block as: