JBossServerAuthConfig出现NullPointerException,第108行

vkc1a9a2  于 2023-04-30  发布在  其他
关注(0)|答案(1)|浏览(110)

使用Sping Boot 27.9与Spring OAuth2和Google Auth沿着创建网站。当我尝试访问该网站时,我得到了上面的错误。我已经追溯了一点,但希望听到有人谁知道代码更好地帮助我确定什么是错的。下面是异常堆栈跟踪。

java.lang.NullPointerException
at org.jboss.security.auth.message.config.JBossServerAuthConfig.getAuthContext(JBossServerAuthConfig.java:108)
at org.apache.catalina.authenticator.AuthenticatorBase.getJaspicState(AuthenticatorBase.java:773)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:619)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:360)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:399)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:891)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1784)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Thread.java:834)

看起来错误在下面的语句中:

secDomain = (String) properties.get("security-domain");

并且似乎“属性”为空。这一行的代码是这样的:

SecurityContext securityContext = SecurityActions.getSecurityContext();
if (securityContext != null)
{
   secDomain = securityContext.getSecurityDomain();
}
else{
   secDomain = (String) properties.get("security-domain");

所以我假设securityContext是null,而且不应该是null。顺便说一句,这段代码只是我在网上找到的,没有做Git pull。
什么会导致SecurityActions。getSecurityContext()返回null?
另外,作为一个附带说明,除了调用getAuthContext()的方式之外,我们不会有NPE。我认为这是发生在www.example www.example.com ,下面是一个代码片段:

private JaspicState getJaspicState(AuthConfigProvider jaspicProvider, Request request, Response response,
        boolean authMandatory) throws IOException {
...
    try {
        CallbackHandler callbackHandler = getCallbackHandler();
        ServerAuthConfig serverAuthConfig = jaspicProvider.getServerAuthConfig("HttpServlet", jaspicAppContextID,
                callbackHandler);
        String authContextID = serverAuthConfig.getAuthContextID(jaspicState.messageInfo);
        jaspicState.serverAuthContext = serverAuthConfig.getAuthContext(authContextID, null, null); <--- Passing in null for properties
    } catch (AuthException e) {
        log.warn(sm.getString("authenticator.jaspicServerAuthContextFail"), e);
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        return null;
    }
icnyk63a

icnyk63a1#

奇怪的是,这是通过注意到我认为是一个完全不同的问题来解决的。我的项目使用了一个我也创建的'commons'项目。在这方面,我在pom有一个问题。我指定的是“maven-compiler-plugin”,但没有指定版本,Eclipse对此表示不满。然后我注意到这是我的项目中唯一一个使用它的项目,而其他项目都使用“spring-boot-maven-plugin”,所以我把我的commons pom切换到那个项目,突然之间,原来的问题消失了。

相关问题