From 7079a4e7e41fa803b226709e4ea393c849fd4ddf Mon Sep 17 00:00:00 2001 From: 疯狂的狮子li <15040126243@163.com> Date: 星期三, 10 十一月 2021 13:31:54 +0800 Subject: [PATCH] update satoken 1.27.0 => 1.28.0 使用 jwt 插件代理 token 生成逻辑 --- ruoyi-framework/src/main/java/com/ruoyi/framework/config/ResourcesConfig.java | 25 +++++++++++++++++-------- 1 files changed, 17 insertions(+), 8 deletions(-) diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/ResourcesConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/ResourcesConfig.java index dc7821e..6200634 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/ResourcesConfig.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/ResourcesConfig.java @@ -7,6 +7,8 @@ import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.framework.config.properties.SecurityProperties; +import com.ruoyi.framework.Interceptor.PlusWebInvokeTimeInterceptor; +import com.yomahub.tlog.web.interceptor.TLogWebInterceptor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -34,15 +36,19 @@ // 娉ㄥ唽sa-token鐨勬嫤鎴櫒 @Override public void addInterceptors(InterceptorRegistry registry) { + // 鍏ㄥ眬閾捐矾璺熻釜鎷︽埅鍣� + registry.addInterceptor(new TLogWebInterceptor()); + // 鍏ㄥ眬璁块棶鎬ц兘鎷︽埅 + registry.addInterceptor(new PlusWebInvokeTimeInterceptor()); // 娉ㄥ唽璺敱鎷︽埅鍣紝鑷畾涔夐獙璇佽鍒� registry.addInterceptor(new SaRouteInterceptor((request, response, handler) -> { // 鐧诲綍楠岃瘉 -- 鎺掗櫎澶氫釜璺緞 - SaRouter.match( - //鑾峰彇鎵�鏈夌殑 - Collections.singletonList("/**"), - //鎺掗櫎涓嬩笉闇�瑕佹嫤鎴殑 - Arrays.asList(securityProperties.getExcludes()), - () -> { + SaRouter + // 鑾峰彇鎵�鏈夌殑 + .match(Collections.singletonList("/**")) + // 鎺掗櫎涓嬩笉闇�瑕佹嫤鎴殑 + .notMatch(Arrays.asList(securityProperties.getExcludes())) + .check(() -> { Long userId = SecurityUtils.getUserId(); if(StringUtils.isNotNull(userId) ) { long tokenTimeout = StpUtil.getTokenTimeout(); @@ -64,7 +70,6 @@ */ @Bean public CorsFilter corsFilter() { - UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); CorsConfiguration config = new CorsConfiguration(); config.setAllowCredentials(true); // 璁剧疆璁块棶婧愬湴鍧� @@ -73,8 +78,12 @@ config.addAllowedHeader("*"); // 璁剧疆璁块棶婧愯姹傛柟娉� config.addAllowedMethod("*"); - // 瀵规帴鍙i厤缃法鍩熻缃� + // 鏈夋晥鏈� 1800绉� + config.setMaxAge(1800L); + // 娣诲姞鏄犲皠璺緞锛屾嫤鎴竴鍒囪姹� + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); source.registerCorsConfiguration("/**", config); + // 杩斿洖鏂扮殑CorsFilter return new CorsFilter(source); } } -- Gitblit v1.9.3