From 574837a92aede1973fdceda0169efd37cff0673d Mon Sep 17 00:00:00 2001
From: 疯狂的狮子Li <15040126243@163.com>
Date: 星期日, 18 九月 2022 22:14:11 +0800
Subject: [PATCH] !229 升级sa-token到最新版1.31.0 Merge pull request !229 from Charles7c/dev

---
 ruoyi-framework/src/main/java/com/ruoyi/framework/config/SaTokenConfig.java |   57 +++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 53 insertions(+), 4 deletions(-)

diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SaTokenConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SaTokenConfig.java
index 9c9813f..f53dc06 100644
--- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SaTokenConfig.java
+++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SaTokenConfig.java
@@ -1,17 +1,66 @@
 package com.ruoyi.framework.config;
 
-import cn.dev33.satoken.jwt.StpLogicJwtForStyle;
+import cn.dev33.satoken.interceptor.SaInterceptor;
+import cn.dev33.satoken.jwt.StpLogicJwtForSimple;
+import cn.dev33.satoken.router.SaRouter;
 import cn.dev33.satoken.stp.StpLogic;
+import cn.dev33.satoken.stp.StpUtil;
+import com.ruoyi.common.utils.spring.SpringUtils;
+import com.ruoyi.framework.config.properties.ExcludeUrlProperties;
+import com.ruoyi.framework.config.properties.SecurityProperties;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
 
+/**
+ * sa-token 閰嶇疆
+ *
+ * @author Lion Li
+ */
+@RequiredArgsConstructor
+@Slf4j
 @Configuration
-public class SaTokenConfig {
+public class SaTokenConfig implements WebMvcConfigurer {
+
+    private final SecurityProperties securityProperties;
+
+    /**
+     * 娉ㄥ唽sa-token鐨勬嫤鎴櫒
+     */
+    @Override
+    public void addInterceptors(InterceptorRegistry registry) {
+        // 娉ㄥ唽璺敱鎷︽埅鍣紝鑷畾涔夐獙璇佽鍒�
+        registry.addInterceptor(new SaInterceptor(handler -> {
+            ExcludeUrlProperties excludeUrlProperties = SpringUtils.getBean(ExcludeUrlProperties.class);
+            // 鐧诲綍楠岃瘉 -- 鎺掗櫎澶氫釜璺緞
+            SaRouter
+                // 鑾峰彇鎵�鏈夌殑
+                .match("/**")
+                // 鎺掗櫎涓嬩笉闇�瑕佹嫤鎴殑
+                .notMatch(securityProperties.getExcludes())
+                .notMatch(excludeUrlProperties.getExcludes())
+                // 瀵规湭鎺掗櫎鐨勮矾寰勮繘琛屾鏌�
+                .check(() -> {
+                    // 妫�鏌ユ槸鍚︾櫥褰� 鏄惁鏈塼oken
+                    StpUtil.checkLogin();
+
+                    // 鏈夋晥鐜囧奖鍝� 鐢ㄤ簬涓存椂娴嬭瘯
+                    // if (log.isDebugEnabled()) {
+                    //     log.debug("鍓╀綑鏈夋晥鏃堕棿: {}", StpUtil.getTokenTimeout());
+                    //     log.debug("涓存椂鏈夋晥鏃堕棿: {}", StpUtil.getTokenActivityTimeout());
+                    // }
+
+                });
+        })).addPathPatterns("/**");
+    }
 
     @Bean
     public StpLogic getStpLogicJwt() {
-        // Sa-Token 鏁村悎 jwt (Style妯″紡)
-        return new StpLogicJwtForStyle();
+        // Sa-Token 鏁村悎 jwt (绠�鍗曟ā寮�)
+        return new StpLogicJwtForSimple();
     }
 
 }

--
Gitblit v1.9.3