From 868942e202aeb967b8ce47b38cc2433a636a128d Mon Sep 17 00:00:00 2001 From: phanes <5411232+phanes@user.noreply.gitee.com> Date: 星期日, 16 一月 2022 17:46:24 +0800 Subject: [PATCH] update 格式化代码结构 统一编码格式 --- ruoyi-framework/src/main/java/com/ruoyi/framework/config/SaTokenConfig.java | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 45 insertions(+), 1 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..05cff03 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,12 +1,56 @@ 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 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 { +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() { -- Gitblit v1.9.3