Oauth2.0 integrated Springcloud Zuul solve critical bug error message: Principal must not being null

Source: Internet
Author: User
Tags assert spring boot actuator

I'm not sure Oauth2.0 can view my previous posts.

Zuul for the Springcloud Micro-service framework can be used very simply can be verified online

This article only explains how to resolve conflicts between Oauth2.0 and Zuul packages.

Requirements: Create a new Oauth2.0 project the framework for gateway distribution is required on this basis Zuul

The problem is that once you import the required packages for Zuul

  
<dependency> <groupId>org.springframework.cloud</groupId>------" Conflict < Artifactid>spring-cloud-starter-zuul</artifactid> </dependency>
<properties>
<project.build.sourceencoding>utf-8</project.build.sourceEncoding>
<project.reporting.outputencoding>utf-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>dalston.sr3</spring-cloud.version>
</properties>
<dependencymanagement>
<dependencies>
<dependency>
<groupId> Org.springframework.cloud</groupid>
< Artifactid>spring-cloud-dependencies</ARTIFACTID>
<version>${spring-cloud.version}</version
<type>pom</TYPE>
<scope>import</SCOPE>
</dependency>
</dependencies>
< /dependencymanagement>


Request the distribution interface after running the error message

Java.lang.IllegalArgumentException:Principal must not beingNULLAt org.springframework.util.Assert.notNull (Assert.java:134) ~[spring-core-4.3.9.release.jar:4.3.9. RELEASE] at org.springframework.boot.actuate.audit.AuditEvent.<init> (auditevent.java:88) ~[spring-boot-actuator-1.5.4.release.jar:1.5.4. RELEASE] at org.springframework.boot.actuate.audit.AuditEvent.<init> (auditevent.java:64) ~[spring-boot-actuator-1.5.4.release.jar:1.5.4. RELEASE] at Org.springframework.boot.actuate.security.AuthenticationAuditListener.onAuthenticationSuccessEvent ( Authenticationauditlistener.java:(~[spring-boot-actuator-1.5.4.release.jar:1.5.4). RELEASE] at Org.springframework.boot.actuate.security.AuthenticationAuditListener.onApplicationEvent ( Authenticationauditlistener.java:~[spring-boot-actuator-1.5.4.release.jar:1.5.4). RELEASE] at Org.springframework.boot.actuate.security.AuthenticationAuditListener.onApplicationEvent ( Authenticationauditlistener.java:~[spring-boot-actuator-1.5.4.release.jar:1.5.4). RELEASE] at Org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener ( Simpleapplicationeventmulticaster.java:167) ~[spring-context-4.3.9.release.jar:4.3.9. RELEASE] at Org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent ( Simpleapplicationeventmulticaster.java:139) ~[spring-context-4.3.9.release.jar:4.3.9. RELEASE] at Org.springframework.context.support.AbstractApplicationContext.publishEvent ( Abstractapplicationcontext.java:393) ~[spring-context-4.3.9.release.jar:4.3.9. RELEASE] at Org.springframework.context.support.AbstractApplicationContext.publishEvent ( Abstractapplicationcontext.java:347) ~[spring-context-4.3.9.release.jar:4.3.9. RELEASE] At Org.springframework.security.authentication.DefaultAuthenticationEventPublisher.publishAuthenticationSuccess ( Defaultauthenticationeventpublisher.java:~[spring-security-core-4.2.3.release.jar:4.2.3). RELEASE] At Org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationProcessingFilter.doFilter ( Oauth2authenticationprocessingfilter.java:156) ~[spring-security-oauth2-2.0.14. RELEASE.jar:na] at Org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter ( Filterchainproxy.java:331) ~[spring-security-web-4.2.3.release.jar:4.2.3. RELEASE] at Org.springframework.security.web.authentication.logout.LogoutFilter.doFilter (Logoutfilter.java:~[spring-security-web-4.2.3.release.jar:4.2.3). RELEASE] at Org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter (FilterChainProxy.java: 331) ~[spring-security-web-4.2.3.release.jar:4.2.3. RELEASE] at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal (Headerwriterfilter.java: ) ~[spring-security-web-4.2.3.release.jar:4.2.3. RELEASE] at Org.springframework.web.filter.OncePerRequestFilter.doFilter (Onceperrequestfilter.java:107) ~[spring-web-4.3.9.release.jar:4.3.9. RELEASE] at Org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter (FilterChainProxy.java: 331) ~[spring-security-web-4.2.3.release.jar:4.2.3. RELEASE] at Org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter ( Securitycontextpersistencefilter.java:(~[spring-security-web-4.2.3.release.jar:4.2.3). RELEASE] at Org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter (FilterChainProxy.java: 331) ~[spring-security-web-4.2.3.release.jar:4.2.3. RELEASE] At Org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal ( Webasyncmanagerintegrationfilter.java:~[spring-security-web-4.2.3.release.jar:4.2.3). RELEASE] at Org.springframework.web.filter.OncePerRequestFilter.doFilter (Onceperrequestfilter.java:107) ~[spring-web-4.3.9.release.jar:4.3.9. RELEASE] at Org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter (FilterChainProxy.java: 331) ~[spring-security-web-4.2.3.release.jar:4.2.3. RELEASE] at org.springframework.security.web.FilterChainProxy.doFilterInternal (Filterchainproxy.java:214) ~[spring-security-web-4.2.3.release.jar:4.2.3. RELEASE] at Org.springframework.security.web.FilterChainProxy.doFilter (Filterchainproxy.java:177) ~[spring-security-web-4.2.3.release.jar:4.2.3. RELEASE] at Org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate (Delegatingfilterproxy.java:346) ~[spring-web-4.3.9.release.jar:4.3.9. RELEASE] at Org.springframework.web.filter.DelegatingFilterProxy.doFilter (Delegatingfilterproxy.java:262) ~[spring-web-4.3.9.release.jar:4.3.9. RELEASE] at Org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (Applicationfilterchain.java:193) ~[tomcat-embed-core-8.5.15.jar:8.5.15] at Org.apache.catalina.core.ApplicationFilterChain.doFilter (Applicationfilterchain.java:166) ~[tomcat-embed-core-8.5.15.jar:8.5.15] at org.springframework.web.filter.RequestContextFilter.doFilterInternal (Requestcontextfilter.java:~[spring-web-4.3.9.release.jar:4.3.9). RELEASE] at Org.springframework.web.filter.OncePerRequestFilter.doFilter (Onceperrequestfilter.java:107) ~[spring-web-4.3.9.release.jar:4.3.9. RELEASE] at Org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (Applicationfilterchain.java:193) ~[tomcat-embed-core-8.5.15.jar:8.5.15] at Org.apache.catalina.core.ApplicationFilterChain.doFilter (Applicationfilterchain.java:166) ~[tomcat-embed-core-8.5.15.jar:8.5.15] at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal (Httpputformcontentfilter.java: (~[spring-web-4.3.9.release.jar:4.3.9). RELEASE] at Org.springframework.web.filter.OncePerRequestFilter.doFilter (Onceperrequestfilter.java:107) ~[spring-web-4.3.9.release.jar:4.3.9. RELEASE] at Org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (Applicationfilterchain.java:193) ~[tomcat-embed-core-8.5.15.jar:8.5.15] at Org.apache.catalina.core.ApplicationFilterChain.doFilter (Applicationfilterchain.java:166) ~[tomcat-embed-core-8.5.15.jar:8.5.15] at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal (Hiddenhttpmethodfilter.java: Bayi) ~[spring-web-4.3.9.release.jar:4.3.9. RELEASE] at Org.springframework.web.filter.OncePerRequestFilter.doFilter (Onceperrequestfilter.java:107) ~[spring-web-4.3.9.release.jar:4.3.9. RELEASE] at Org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (Applicationfilterchain.java:193) ~[tomcat-embed-core-8.5.15.jar:8.5.15] at Org.apache.catalina.core.ApplicationFilterChain.doFilter (Applicationfilterchain.java:166) ~[tomcat-embed-core-8.5.15.jar:8.5.15] at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal (Characterencodingfilter.java: 197) ~[spring-web-4.3.9.release.jar:4.3.9. RELEASE] at Org.springframework.web.filter.OncePerRequestFilter.doFilter (Onceperrequestfilter.java:107) ~[spring-web-4.3.9.release.jar:4.3.9. RELEASE] at Org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (Applicationfilterchain.java:193) ~[tomcat-embed-core-8.5.15.jar:8.5.15] at Org.apache.catalina.core.ApplicationFilterChain.doFilter (Applicationfilterchain.java:166) ~[tomcat-embed-core-8.5.15.jar:8.5.15] at org.springframework.boot.actuate.autoconfigure.MetricsFilter.doFilterInternal (Metricsfilter.java:106) ~[spring-boot-actuator-1.5.4.release.jar:1.5.4. RELEASE] at Org.springframework.web.filter.OncePerRequestFilter.doFilter (Onceperrequestfilter.java:107) ~[spring-web-4.3.9.release.jar:4.3.9. RELEASE] at Org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (Applicationfilterchain.java:193) ~[tomcat-embed-core-8.5.15.jar:8.5.15] at Org.apache.catalina.core.ApplicationFilterChain.doFilter (Applicationfilterchain.java:166) ~[tomcat-embed-core-8.5.15.jar:8.5.15] at Org.apache.catalina.core.StandardWrapperValve.invoke (Standardwrappervalve.java:198) ~[tomcat-embed-core-8.5.15.jar:8.5.15] at Org.apache.catalina.core.StandardContextValve.invoke (Standardcontextvalve.java:(+) [tomcat-embed-core-8.5.15.jar:8.5.15] at Org.apache.catalina.authenticator.AuthenticatorBase.invoke (Authenticatorbase.java:478) [tomcat-embed-core-8.5.15.jar:8.5.15] at Org.apache.catalina.core.StandardHostValve.invoke (Standardhostvalve.java:(+) [tomcat-embed-core-8.5.15.jar:8.5.15] at Org.apache.catalina.valves.ErrorReportValve.invoke (Errorreportvalve.java:) [tomcat-embed-core-8.5.15.jar:8.5.15] at Org.apache.catalina.core.StandardEngineValve.invoke (Standardenginevalve.java:) [tomcat-embed-core-8.5.15.jar:8.5.15] at Org.apache.catalina.connector.CoyoteAdapter.service (Coyoteadapter.java:342) [tomcat-embed-core-8.5.15.jar:8.5.15] at Org.apache.coyote.http11.Http11Processor.service (Http11processor.java:799) [tomcat-embed-core-8.5.15.jar:8.5.15] at org.apache.coyote.AbstractProcessorLight.process (Abstractprocessorlight.java:[tomcat-embed-core-8.5.15.jar:8.5.15]] at org.apache.coyote.abstractprotocol$connectionhandler.process (Abstractprotocol.java:861) [tomcat-embed-core-8.5.15.jar:8.5.15] at Org.apache.tomcat.util.net.nioendpoint$socketprocessor.dorun (Nioendpoint.java:1455) [tomcat-embed-core-8.5.15.jar:8.5.15] at Org.apache.tomcat.util.net.SocketProcessorBase.run (Socketprocessorbase.java:) [tomcat-embed-core-8.5.15.jar:8.5.15] at Java.util.concurrent.ThreadPoolExecutor.runWorker (Threadpoolexecutor.java:1142) [na:1.8. 0_91] at Java.util.concurrent.threadpoolexecutor$worker.run (Threadpoolexecutor.java:617) [na:1.8. 0_91] at Org.apache.tomcat.util.threads.taskthread$wrappingrunnable.run (Taskthread.java:) [tomcat-embed-core-8.5.15.jar:8.5.15] at Java.lang.Thread.run (Thread.java:745) [na:1.8.0_91]
View Code

The reason is that a foreigner's blog has given the solution and the reason limited to English limited you can see for yourself 1. Address: https://github.com/spring-projects/spring-boot/issues/6447 2. Https://stackoverflow.com/questions/38958004/spring-boot-1-4-principal-must-not-be-null-exception

The translation is generally:

When you have spring Boot actuator and spring security at the same time,

trying to use SecurityContextHolder.getContext().getAuthentication() (or @AuthenticationPrincipal UriTemplate-based routing that is used in the method signature will get a null values.

That is, Oauth2.0 the imported package and Zuul the child package under the imported package Spring-boot-actuator (Note that the package is not reflected in the Zuul POM package) and that the call conflict will solve the problem of removing the package.

Workaround 1: Add the following exclusions tags to the zuul below to remove them.

<dependency>            <groupId>org.springframework.cloud</groupId>            <artifactId> spring-cloud-starter-zuul</artifactid>            <exclusions>                <exclusion>                    <artifactid >spring-boot-actuator</artifactId>                    <groupId>org.springframework.boot</groupId>                </exclusion>            </exclusions>        </dependency>

The second solution is to start without knowing the spring-boot-actuator for Zuul, and how to find him I use the Springboot +maven Framework tool is idea

Click on the right sidebar maven projects--show dependence

You can see that spring-boot-actuator belongs to the sub-package under Springzuul, as shown below.

Find spring-boot-actuator Right-click Delete in the bottom right corner of the import

This is still true in pom after deletion

<dependency>            <groupId>org.springframework.cloud</groupId>            <artifactId> spring-cloud-starter-zuul</artifactid>            <exclusions>                <exclusion>                    <artifactid >spring-boot-actuator</artifactId>                    <groupId>org.springframework.boot</groupId>                </exclusion>            </exclusions>        </dependency>

Oauth2.0 integrated Springcloud Zuul solve critical bug error message: Principal must not being null

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.