From 6ca853516671882e8e54d9630a4299f12fbcf9aa Mon Sep 17 00:00:00 2001
From: 疯狂的狮子li <15040126243@163.com>
Date: 星期四, 13 一月 2022 11:14:33 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/satoken' into dev

---
 ruoyi-framework/src/main/java/com/ruoyi/framework/config/SaTokenConfig.java |   63 +++++++++++++++++++++++++++++++
 1 files changed, 63 insertions(+), 0 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
new file mode 100644
index 0000000..2604245
--- /dev/null
+++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SaTokenConfig.java
@@ -0,0 +1,63 @@
+package com.ruoyi.framework.config;
+
+import cn.dev33.satoken.interceptor.SaAnnotationInterceptor;
+import cn.dev33.satoken.interceptor.SaRouteInterceptor;
+import cn.dev33.satoken.jwt.StpLogicJwtForStyle;
+import cn.dev33.satoken.router.SaRouter;
+import cn.dev33.satoken.stp.StpLogic;
+import cn.dev33.satoken.stp.StpUtil;
+import com.ruoyi.common.utils.LoginUtils;
+import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.framework.config.properties.SecurityProperties;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+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
+ */
+@Slf4j
+@Configuration
+public class SaTokenConfig implements WebMvcConfigurer {
+
+    @Autowired
+    private SecurityProperties securityProperties;
+
+    /**
+     * 娉ㄥ唽sa-token鐨勬嫤鎴櫒
+     */
+    @Override
+    public void addInterceptors(InterceptorRegistry registry) {
+        // 娉ㄥ唽璺敱鎷︽埅鍣紝鑷畾涔夐獙璇佽鍒�
+        registry.addInterceptor(new SaRouteInterceptor((request, response, handler) -> {
+            // 鐧诲綍楠岃瘉 -- 鎺掗櫎澶氫釜璺緞
+            SaRouter
+                // 鑾峰彇鎵�鏈夌殑
+                .match("/**")
+                // 鎺掗櫎涓嬩笉闇�瑕佹嫤鎴殑
+                .notMatch(securityProperties.getExcludes())
+                .check(() -> {
+                    if (log.isDebugEnabled()) {
+                        Long userId = LoginUtils.getUserId();
+                        if (StringUtils.isNotNull(userId)) {
+                            log.debug("鍓╀綑鏈夋晥鏃堕棿: {}", StpUtil.getTokenTimeout());
+                            log.debug("涓存椂鏈夋晥鏃堕棿: {}", StpUtil.getTokenActivityTimeout());
+                        }
+                    }
+                });
+        })).addPathPatterns("/**");
+        registry.addInterceptor(new SaAnnotationInterceptor()).addPathPatterns("/**");
+    }
+
+    @Bean
+    public StpLogic getStpLogicJwt() {
+        // Sa-Token 鏁村悎 jwt (Style妯″紡)
+        return new StpLogicJwtForStyle();
+    }
+
+}

--
Gitblit v1.9.3