不清楚Oauth2.0 的 可以查看我前几篇博文
2018.4.8 补充 我出现这个原因:是我在资源服务器使用了 如下图所示
Principal Oauth2.0 提供的获取用户信息的方法 使其找到相关信息
配置Oauth2.0 认证服务端的时候UserDetails 配置的时候 继承的实体类
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAA/MAAABgCAYAAABR5iLTAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAACABSURBVHhe7d3dj93Gecdx/T1HflvLVZSLZG3XjiwJ1WtgJ5UqWa62klXHEAqpEgrDlS0bQoHardFiVRi+knIht6gL1I7TJIiLvsRAoxRFL3PVyyJoL/riOAmKdjrPDB+e4ZwZcniW5+zh6nvxgbTkcDgc8pzljxxyd+3evdsAAAAAAIDxIMwDAAAAADAyhHkAAAAAAEZmaWF+Mlkz+y8/bh6bTJLzAQAAAABAmaWF+S9d3m++RJAHAAAAAGDLlhLmHzu33+xfJ8gDAAAAADCEucL8Y+cOm7OX9yXnxSZH95sjRwnyAAAAAAAMpXeYd8++v/nVooA+WX/cHDm3lpwHAAAAAADm0xrmH3xgt7n61V8y33njK+bHf3TA/PgP95vvvPLL5vdvPmG+8MDEPHZ0v/na5uHkEPrJZJ85Unj3HgAAAAAAlMuG+bWHdpu/vPaE+ddvnjD/8fHXzWefnHTk/zLtO28fML/25lfMl9Zn77zz5noAAAAAABYnG+bfPP1F829/9jXz+d8+b37+DxvmF/cuOPJ/mSbzpExqWd5cDwAAAADA4mTD/I/+4LD57JMXbHi3If6HLzbINJn3z398ZGY53lwPAAAAAMBiZcP8T+6eND/7+w1j/ucT8/NPz7t/w//LvJ+8f7IxlJ431wMAAAAAsHjZMP8vt79ufvY3G+bnf/cb5v8+/5b7N/y/zJMyWp431wMAAAAAsBzZMP+93/sV89Pvb5jP/3rD/O+/33X/hv+XeVJGyvLmegAAAAAAlicb5s8f/YL5r4/Oms+/9+vOL/7xFfOLf/rd+meZ9+KxL/DmegAA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uvV3xt9f98AAHamlR5mD2Dr/J3/6YgDJRcJ+v5VBQDA9sldnAUA3J9WIsyHdxIJF8Dw3PD8l6afMyGjLUqGuAMAVoMbhcaNDwBAZWXuzAMAAAAAgDKEeQAAAAAARoYwDwAAAADAyBDmAQAAAAAYGcI8AAAAAAAjQ5gHAAAAAGBkCPMAAAAAAIwMYR4AAAAAgJEhzAMAAAAAMDKEeQAAAAAARoYwDwAAAADAyBDmAQAAAAAYGcI8AAAAAAAjQ5gHAAAAAGBkCPMAAAAAAIwMYR4AAAAAgJEhzAMAAAAAMDKEeQAAAAAARoYwDwAAAADAyBDmAQAAAAAYGcI8AAAAAAAjQ5gHAAAAAGBkCPMAAAAAAIzKbvP/SuRnA0OVqW4AAAAASUVORK5CYIIA" alt="" />
User 代码上 经个人测试必须要有这几个实体类 这里面的信息是Principal 方法里所用到的信息 必须有的 如果没有会报错:Principal must not be null
public class User extends SupplyUser {
private String firstName;
private String lastName;
private String email;
private String imageUrl;
private Instant createTime;
@JsonIgnore
private Instant updateTime;
@JsonIgnore
private Set<Role> roles = new HashSet<>();
private Set<GrantedAuthority> authorities = new HashSet<>(); public Set<GrantedAuthority> getAuthorities() {
Set<GrantedAuthority> authorities = new HashSet<>();
for (Role role : this.roles) {
for (Authority authority : role.getAuthorities()) {
authorities.add(new SimpleGrantedAuthority(authority.getValue()));
}
}
return authorities;
}
以上方法都不缺的话 只能使用以下的方法了,但笔者不建议使用删除包的方法
Zuul 为springCloud 微服务框架 单独可以使用 非常简单 可以上网查证
此文只说明如何解决Oauth2.0 和Zuul 包 的冲突
需求:新建一个Oauth2.0 项目 需要在此基础上进行网关分发 选用的框架为Zuul
遇到的问题 是 一旦导入zuul 的所需包
<dependency>
<groupId>org.springframework.cloud</groupId> ------ 》》 冲突
<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>
运行之后 请求分发接口 就报错信息
java.lang.IllegalArgumentException: Principal must not be null
at 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:92) ~[spring-boot-actuator-1.5.4.RELEASE.jar:1.5.4.RELEASE]
at org.springframework.boot.actuate.security.AuthenticationAuditListener.onApplicationEvent(AuthenticationAuditListener.java:72) ~[spring-boot-actuator-1.5.4.RELEASE.jar:1.5.4.RELEASE]
at org.springframework.boot.actuate.security.AuthenticationAuditListener.onApplicationEvent(AuthenticationAuditListener.java:35) ~[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:99) ~[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:116) ~[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:64) ~[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:105) ~[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:56) ~[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:99) ~[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:105) ~[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:81) ~[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:96) [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:140) [tomcat-embed-core-8.5.15.jar:8.5.15]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80) [tomcat-embed-core-8.5.15.jar:8.5.15]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) [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:66) [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:49) [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:61) [tomcat-embed-core-8.5.15.jar:8.5.15]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_91]
原因 是 一片老外的博文 给出了解决办法及原因 限于英语有限 大家可以自己查看一下 1.地址:https://github.com/spring-projects/spring-boot/issues/6447 2. https://*.com/questions/38958004/spring-boot-1-4-principal-must-not-be-null-exception
翻译过来大体是:
当你同时拥有Spring Boot Actuator和Spring Security时,
试图使用SecurityContextHolder.getContext().getAuthentication()
(或@AuthenticationPrincipal
在方法签名中使用)的基于UriTemplate的路由将获得一个null
值。
也就是说Oauth2.0 导入的包和Zuul导入的包下的子包spring-boot-actuator (注意这个包并没有在ZUUL pom中包 中所体现)同时调用 发生冲突 将这个包移除问题就能解决了
具体解决方法 1.:在zuul 下 添加如下exclusions 标签移除 即可
<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>
第二种解决办法 是开始的时候并不知到spring-boot-actuator 为zuul 下的包, 那如何找到他 我使用的springboot +maven 框架 工具是IDEA
点击右边栏Maven Projects--》show Dependence
变成如下界面 可以看出spring-boot-actuator 属于springZuul 下的子包
找到spring-boot-actuator 右键删除 在点击右下角的Import
删除后 pom中依然是这样
<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>
补充 : 以上这种方法不够科学 后期可能会带来许多麻烦
我最近 将 ZUUL及EUREKA 注册 和OAUTH2.0 分开三个小项目 写 可以避免 许多麻烦 也增加代码 的规范化
还有就是spring-cloud 已经提供 OAuth2.0 的包 也可以避免 相互冲突
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-oauth2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-security</artifactId>
</dependency>
后期我会写个 规范 springCloud 和Oauth2.0 整合 及Oauth2.0 资源服务器配置 代码DEMO