无法从日志记录中捕获异常

发布于 2024-12-18 03:50:16 字数 696 浏览 0 评论 0原文

尝试使用过期密码登录 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦醒灬来后我 2024-12-25 03:50:16

您需要掌握异常堆栈跟踪。 (如有必要,请更改日志记录配置,以便将堆栈跟踪写入日志。)

这将告诉您抛出异常的位置。

然后检查源代码以查看它在哪里被捕获和记录,并查看是否有任何代码堆栈可以首先捕获它。

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.

爱给你人给你 2024-12-25 03:50:16

假设您要捕获的是 javax.naming.AuthenticationException 类型的异常,您可以将其放入 try catch 块中,如下所示:

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
  }
}

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
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文