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

前端 未结 1 1569
余生分开走
余生分开走 2020-12-16 00:45

This is somewhat caused by the tomcat-embed-core version 8.5.4 that comes with the spring-boot-starter-jersey. It generates an error shown below on all integration tests. It

相关标签:
1条回答
  • 2020-12-16 01:31

    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.

    0 讨论(0)
提交回复
热议问题