Upgrading Spring Boot from 1.3.7 to 1.4.0 causing NullPointerException in AuthenticatorBase.getJaspicProvider

随声附和 提交于 2019-11-29 01:51:50

Possible fixes:

1) Set authConfigFactory to default AuthConfigFactory implementation used by Tomcat 8.5 (example basic implementation):

package com.example;

import org.apache.catalina.authenticator.jaspic.AuthConfigFactoryImpl;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import javax.security.auth.message.config.AuthConfigFactory;

@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {
        if (AuthConfigFactory.getFactory() == null) {
            AuthConfigFactory.setFactory(new AuthConfigFactoryImpl());
        }
        SpringApplication.run(DemoApplication.class, args);
    }
}

or

2) Remove duplicated AuthConfigFactory class from your classpath. In my case there were two different implementations of the same class:

org.apache.tomcat.embed/tomcat-embed-core/8.5.4/tomcat-embed-core-8.5.4.jar!/javax/security/auth/message/config/AuthConfigFactory.class
javax/javaee-api/7.0/javaee-api-7.0.jar!/javax/security/auth/message/config/AuthConfigFactory.class

javaee-api-7.0.jar has it's own AuthConfigFactory implementation which is not fully compatible with Tomcat 8.5 and causes that NullPointerException (in Tomcat's version there is constant which defines default jaspic implementation class) Remove javaee-api dependency (or any other which contains different AuthConfigFactory implementation) from your gradle/mvn project (if you can)

or

3) Downgrade Tomcat to 8.0 or 7.0:

http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#howto-use-tomcat-7

Explanation:

The problem is related with Tomcat upgrade (from 8.0.x to 8.5.x) which has been made during Spring Boot upgrade from 1.3.x to 1.4. The problem is that Tomcat 8.5 introduces jaspic support (https://tomcat.apache.org/tomcat-8.5-doc/config/jaspic.html) and provides it's own implementation of AuthConfigFactory. This implementation defines default jaspic auth factory implementation:

private static final String DEFAULT_JASPI_AUTHCONFIGFACTORYIMPL =
            "org.apache.catalina.authenticator.jaspic.AuthConfigFactoryImpl";

which is not defined in other implementations (e.g. that one from javaee-api-7.0) and causes NullPointerException because no AuthConfigFactory were instantiated.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!