From 0fc13d45e6fe9e8b270f466627688c57bc435381 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BA=B7=E5=85=B4=E5=8D=8E?= Date: Tue, 19 Mar 2019 14:35:08 +0800 Subject: [PATCH 1/3] =?UTF-8?q?spring-cloud=20=E5=8D=87=E7=BA=A7=E5=88=B0G?= =?UTF-8?q?reenwich.RELEASE=20spring-boot-starter-parent=20=E5=8D=87?= =?UTF-8?q?=E7=BA=A7=E5=88=B0=202.1.3.RELEASE=20spring.boot.admin=20?= =?UTF-8?q?=E5=8D=87=E7=BA=A7=E5=88=B0=202.1.3=20kernel.version=20?= =?UTF-8?q?=E5=8D=87=E7=BA=A7=E5=88=B0=201.2.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 9 +++++---- src/main/resources/bootstrap.yml | 2 ++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 5ca762d..fff6fe5 100644 --- a/pom.xml +++ b/pom.xml @@ -15,14 +15,15 @@ org.springframework.boot spring-boot-starter-parent - 2.0.1.RELEASE + 2.1.3.RELEASE 1.8 UTF-8 UTF-8 - 1.1.5 + 1.2.0 + 1.1.5 @@ -30,7 +31,7 @@ org.springframework.cloud spring-cloud-dependencies - Finchley.SR2 + Greenwich.RELEASE pom import @@ -73,7 +74,7 @@ cn.stylefeng.roses biz-support-dict-api - ${kernel.version} + ${roses-biz-support.version} diff --git a/src/main/resources/bootstrap.yml b/src/main/resources/bootstrap.yml index 41e550f..59d1f43 100644 --- a/src/main/resources/bootstrap.yml +++ b/src/main/resources/bootstrap.yml @@ -7,6 +7,8 @@ spring: config: profile: @spring.active@ label: master + main: + allow-bean-definition-overriding: true --- -- Gitee From 88c60845cc5091edcfa272c5362e93c2943dc807 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BA=B7=E5=85=B4=E5=8D=8E?= Date: Thu, 4 Apr 2019 14:58:05 +0800 Subject: [PATCH 2/3] init --- pom.xml | 4 ---- .../roses/gateway/config/ContextConfig.java | 16 ++++++++++++++++ .../roses/gateway/config/FilterConfig.java | 9 +++++---- .../modular/service/TokenValidateService.java | 2 +- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index fff6fe5..e77d25f 100644 --- a/pom.xml +++ b/pom.xml @@ -94,10 +94,6 @@ org.springframework.cloud spring-cloud-starter-netflix-zuul - - org.springframework.cloud - spring-cloud-starter-openfeign - cn.stylefeng.roses diff --git a/src/main/java/cn/stylefeng/roses/gateway/config/ContextConfig.java b/src/main/java/cn/stylefeng/roses/gateway/config/ContextConfig.java index f515df2..a6c12fa 100644 --- a/src/main/java/cn/stylefeng/roses/gateway/config/ContextConfig.java +++ b/src/main/java/cn/stylefeng/roses/gateway/config/ContextConfig.java @@ -20,8 +20,14 @@ import cn.stylefeng.roses.core.reqres.response.ErrorResponseData; import cn.stylefeng.roses.kernel.logger.chain.aop.ChainOnConsumerAop; import cn.stylefeng.roses.kernel.logger.chain.aop.ChainOnControllerAop; import cn.stylefeng.roses.kernel.logger.chain.aop.ChainOnProviderAop; +import cn.stylefeng.roses.kernel.model.api.AuthService; +import cn.stylefeng.roses.kernel.model.auth.AbstractLoginUser; import cn.stylefeng.roses.kernel.model.exception.ServiceException; import cn.stylefeng.roses.kernel.model.exception.enums.CoreExceptionEnum; +import cn.stylefeng.roses.system.api.context.LoginContext; +import cn.stylefeng.roses.system.api.context.LoginUser; +import com.alibaba.fastjson.parser.ParserConfig; +import com.alibaba.fastjson.parser.deserializer.ObjectDeserializer; import com.netflix.zuul.context.RequestContext; import com.netflix.zuul.exception.ZuulException; import org.springframework.boot.web.servlet.error.DefaultErrorAttributes; @@ -40,6 +46,16 @@ import java.util.Map; @Configuration public class ContextConfig { + /** + * 获取当前用户的便捷工具 + */ + @Bean + public LoginContext loginContext(AuthService authService) { + ObjectDeserializer objectDeserializer = ParserConfig.getGlobalInstance().getDeserializer(LoginUser.class); + ParserConfig.getGlobalInstance().getDeserializers().put(AbstractLoginUser.class, objectDeserializer); + return new LoginContext(authService); + } + /** * zuul错误信息提示重写 */ diff --git a/src/main/java/cn/stylefeng/roses/gateway/config/FilterConfig.java b/src/main/java/cn/stylefeng/roses/gateway/config/FilterConfig.java index 45e01be..df07e05 100644 --- a/src/main/java/cn/stylefeng/roses/gateway/config/FilterConfig.java +++ b/src/main/java/cn/stylefeng/roses/gateway/config/FilterConfig.java @@ -16,6 +16,7 @@ package cn.stylefeng.roses.gateway.config; import cn.stylefeng.roses.gateway.core.filter.JwtTokenFilter; +import cn.stylefeng.roses.gateway.core.filter.PathMatchFilter; import cn.stylefeng.roses.gateway.core.filter.RequestNoGenerateFilter; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -40,10 +41,10 @@ public class FilterConfig { /** * 资源过滤器,检查每次请求是否有权限访问某些资源 */ - //@Bean - //public PathMatchFilter pathMatchFilter() { - // return new PathMatchFilter(); - //} + @Bean + public PathMatchFilter pathMatchFilter() { + return new PathMatchFilter(); + } /** * 请求唯一编号生成器,每次请求入网关时都会生成一个唯一编号,用来记录一次请求的所有日志和异常信息 diff --git a/src/main/java/cn/stylefeng/roses/gateway/modular/service/TokenValidateService.java b/src/main/java/cn/stylefeng/roses/gateway/modular/service/TokenValidateService.java index 36c27b8..43c99c2 100644 --- a/src/main/java/cn/stylefeng/roses/gateway/modular/service/TokenValidateService.java +++ b/src/main/java/cn/stylefeng/roses/gateway/modular/service/TokenValidateService.java @@ -66,7 +66,7 @@ public abstract class TokenValidateService { throw new ServiceException(AuthExceptionEnum.TOKEN_EMPTY); } } else { - authToken = authToken.substring("Bearer ".length()); +// authToken = authToken.substring("Bearer ".length()); } return authToken; -- Gitee From 9ee2a7acb16c9ed2625a2643038e313c7c1b79da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BA=B7=E5=85=B4=E5=8D=8E?= Date: Thu, 18 Apr 2019 11:08:06 +0800 Subject: [PATCH 3/3] 1.2.3.1 --- .../java/cn/stylefeng/roses/gateway/config/ContextConfig.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/cn/stylefeng/roses/gateway/config/ContextConfig.java b/src/main/java/cn/stylefeng/roses/gateway/config/ContextConfig.java index a6c12fa..254b174 100644 --- a/src/main/java/cn/stylefeng/roses/gateway/config/ContextConfig.java +++ b/src/main/java/cn/stylefeng/roses/gateway/config/ContextConfig.java @@ -51,6 +51,9 @@ public class ContextConfig { */ @Bean public LoginContext loginContext(AuthService authService) { + /** + * 让 fastjson把LoginUser可以反序列化成AbstractLoginUser + */ ObjectDeserializer objectDeserializer = ParserConfig.getGlobalInstance().getDeserializer(LoginUser.class); ParserConfig.getGlobalInstance().getDeserializers().put(AbstractLoginUser.class, objectDeserializer); return new LoginContext(authService); -- Gitee