在 Tomcat 9.0.46 中使用 JNDIRealm/ActiveDirectory 时有人遇到过 NPE 错误并有解决方法吗?
语境
我不得不从 9.0.43 升级,因为在启用 keep-alive/re-use 时套接字输入流被损坏(并混淆了请求主体)的并发错误。日志中充满了“解析 HTTP 请求标头时出错”和“HTTP 方法名称必须是令牌 000x000x000x000x000x...”等。升级到 9.0.46 后,此问题已解决,但现在我们的 ActiveDirectory 登录已损坏。
日志
17-May-2021 14:31:49.405 INFO [Catalina-tomcat-workers-thread7] org.apache.catalina.realm.JNDIRealm.authenticate Exception performing authentication. Retrying...
java.lang.NullPointerException
at org.apache.catalina.realm.JNDIRealm.doAttributeValueEscaping(JNDIRealm.java:2884)
at org.apache.catalina.realm.JNDIRealm.getRoles(JNDIRealm.java:1892)
at org.apache.catalina.realm.JNDIRealm.authenticate(JNDIRealm.java:1350)
at org.apache.catalina.realm.JNDIRealm.authenticate(JNDIRealm.java:1232)
at org.apache.catalina.realm.CombinedRealm.authenticate(CombinedRealm.java:191)
at org.apache.catalina.realm.CombinedRealm.authenticate(CombinedRealm.java:191)
at org.apache.catalina.realm.LockOutRealm.authenticate(LockOutRealm.java:154)
at org.apache.catalina.authenticator.BasicAuthenticator.doAuthenticate(BasicAuthenticator.java:101)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:632)
漏洞
根据错误报告(https://bz.apache.org/bugzilla/show_bug.cgi?id=65308),userRoleAttribute为空/null存在问题。估计再过 3-4 周就不会发布了。
Tomcat 文档(https://tomcat.apache.org/tomcat-9.0-doc/realm-howto.html#JNDIRealm)说:
roleSearch - the LDAP search filter for selecting role entries.
It optionally includes pattern replacements "{0}" for the distinguished name and/or "{1}" for the username and/or "{2}" for an attribute from user's directory entry, of the authenticated user.
Use userRoleAttribute to specify the name of the attribute that provides the value for "{2}".
我没有在 roleSearch 属性中使用“{2}”,所以我不需要设置userRoleAttribute。尽管如此,我还是尝试将其设置为非空,但无济于事。
在他们发布 9.0.47 之前,我需要一个解决方法。有接盘侠吗?