From 0d9fed1558940b1d6dfe9b7b3f6863b3aee243fd Mon Sep 17 00:00:00 2001 From: click33 <2393584716@qq.com> Date: Fri, 21 Feb 2025 21:27:34 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=E9=83=A8?= =?UTF-8?q?=E5=88=86=20sa-token-redis=20=E6=8F=92=E4=BB=B6=EF=BC=8C?= =?UTF-8?q?=E9=80=82=E9=85=8D=20SPI=20=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sa-token-bom/pom.xml | 12 ++++- .../satoken/plugin/SaTokenPluginLoader.java | 25 +++++++++- .../cn/dev33/satoken/session/SaSession.java | 6 +-- sa-token-demo/sa-token-demo-test/pom.xml | 7 --- .../java/com/pj/test/Test2Controller.java | 2 +- sa-token-plugin/pom.xml | 5 +- sa-token-plugin/sa-token-alone-redis/pom.xml | 2 +- .../satoken/dao/alone/SaAloneRedisInject.java | 28 ++++++----- .../dao/SaSessionForFastjsonCustomized.java | 4 +- .../dao/SaSessionForFastjson2Customized.java | 4 +- .../sa-token-redis-jackson/pom.xml | 24 ++-------- .../dao/SaSessionForJacksonCustomized.java | 48 ------------------- .../cn.dev33.satoken.plugin.SaTokenPlugin | 0 ...ot.autoconfigure.AutoConfiguration.imports | 1 - .../pom.xml | 34 +++++++++++++ .../cn/dev33/satoken/dao/SaTokenDaoRedis.java | 0 .../main/resources/META-INF/spring.factories | 0 ...ot.autoconfigure.AutoConfiguration.imports | 0 .../.gitignore | 0 .../pom.xml | 6 +-- .../dao/impl/SaTokenDaoForRedisTemplate.java} | 26 +++++----- .../main/resources/META-INF/spring.factories | 2 +- ...ot.autoconfigure.AutoConfiguration.imports | 1 + .../dev33/satoken/dao/SaSessionForJson.java | 4 +- .../sso/template/SaSsoClientTemplate.java | 2 +- .../cn/dev33/satoken/spring/SaBeanInject.java | 3 ++ .../satoken/core/session/SaSessionTest.java | 12 ++--- 27 files changed, 129 insertions(+), 129 deletions(-) delete mode 100644 sa-token-plugin/sa-token-redis-jackson/src/main/java/cn/dev33/satoken/dao/SaSessionForJacksonCustomized.java delete mode 100644 sa-token-plugin/sa-token-redis-jackson/src/main/resources/META-INF/services/cn.dev33.satoken.plugin.SaTokenPlugin delete mode 100644 sa-token-plugin/sa-token-redis-jackson/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports create mode 100644 sa-token-plugin/sa-token-redis-template-jdk-serializer/pom.xml rename sa-token-plugin/{sa-token-redis => sa-token-redis-template-jdk-serializer}/src/main/java/cn/dev33/satoken/dao/SaTokenDaoRedis.java (100%) rename sa-token-plugin/{sa-token-redis => sa-token-redis-template-jdk-serializer}/src/main/resources/META-INF/spring.factories (100%) rename sa-token-plugin/{sa-token-redis => sa-token-redis-template-jdk-serializer}/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports (100%) rename sa-token-plugin/{sa-token-redis => sa-token-redis-template}/.gitignore (100%) rename sa-token-plugin/{sa-token-redis => sa-token-redis-template}/pom.xml (85%) rename sa-token-plugin/{sa-token-redis-jackson/src/main/java/cn/dev33/satoken/dao/SaTokenDaoRedisJackson.java => sa-token-redis-template/src/main/java/cn/dev33/satoken/dao/impl/SaTokenDaoForRedisTemplate.java} (86%) rename sa-token-plugin/{sa-token-redis-jackson => sa-token-redis-template}/src/main/resources/META-INF/spring.factories (55%) create mode 100644 sa-token-plugin/sa-token-redis-template/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports diff --git a/sa-token-bom/pom.xml b/sa-token-bom/pom.xml index 0a2a9d66..8d473089 100644 --- a/sa-token-bom/pom.xml +++ b/sa-token-bom/pom.xml @@ -111,7 +111,7 @@ cn.dev33 - sa-token-redis + sa-token-redis-template ${revision} @@ -194,6 +194,16 @@ sa-token-temp-jwt ${revision} + + cn.dev33 + sa-token-jackson + ${revision} + + + cn.dev33 + sa-token-redis-template-jdk-serializer + ${revision} + diff --git a/sa-token-core/src/main/java/cn/dev33/satoken/plugin/SaTokenPluginLoader.java b/sa-token-core/src/main/java/cn/dev33/satoken/plugin/SaTokenPluginLoader.java index 72063a76..58bcc40b 100644 --- a/sa-token-core/src/main/java/cn/dev33/satoken/plugin/SaTokenPluginLoader.java +++ b/sa-token-core/src/main/java/cn/dev33/satoken/plugin/SaTokenPluginLoader.java @@ -15,6 +15,8 @@ */ package cn.dev33.satoken.plugin; +import cn.dev33.satoken.SaManager; + import java.util.ArrayList; import java.util.List; import java.util.ServiceLoader; @@ -27,12 +29,32 @@ import java.util.ServiceLoader; */ public class SaTokenPluginLoader { + /** + * 是否已经加载过插件 + */ + public static boolean isLoader = false; + + /** + * 所有插件的集合 + */ public static List pluginList; /** - * 初始化插件 + * 初始化加载所有插件(多次调用只会执行一次) */ public static void init() { + if(isLoader) { + return; + } + loaderPlugins(); + isLoader = true; + } + + /** + * 根据 SPI 机制加载所有插件 + */ + public static void loaderPlugins() { + SaManager.getLog().info("SPI 插件加载开始 ..."); List list = new ArrayList<>(); ServiceLoader plugins = ServiceLoader.load(SaTokenPlugin.class); for (SaTokenPlugin plugin : plugins) { @@ -40,6 +62,7 @@ public class SaTokenPluginLoader { list.add(plugin); } pluginList = list; + SaManager.getLog().info("SPI 插件加载结束 ..."); } } diff --git a/sa-token-core/src/main/java/cn/dev33/satoken/session/SaSession.java b/sa-token-core/src/main/java/cn/dev33/satoken/session/SaSession.java index 8e7f3e6f..f1ff5b74 100644 --- a/sa-token-core/src/main/java/cn/dev33/satoken/session/SaSession.java +++ b/sa-token-core/src/main/java/cn/dev33/satoken/session/SaSession.java @@ -393,7 +393,7 @@ public class SaSession implements SaSetValueInterface, Serializable { * 获取此Session的剩余存活时间 (单位: 秒) * @return 此Session的剩余存活时间 (单位: 秒) */ - public long getTimeout() { + public long timeout() { return SaManager.getSaTokenDao().getSessionTimeout(this.id); } @@ -411,7 +411,7 @@ public class SaSession implements SaSetValueInterface, Serializable { */ public void updateMinTimeout(long minTimeout) { long min = trans(minTimeout); - long curr = trans(getTimeout()); + long curr = trans(timeout()); if(curr < min) { updateTimeout(minTimeout); } @@ -423,7 +423,7 @@ public class SaSession implements SaSetValueInterface, Serializable { */ public void updateMaxTimeout(long maxTimeout) { long max = trans(maxTimeout); - long curr = trans(getTimeout()); + long curr = trans(timeout()); if(curr > max) { updateTimeout(maxTimeout); } diff --git a/sa-token-demo/sa-token-demo-test/pom.xml b/sa-token-demo/sa-token-demo-test/pom.xml index bf6e1a6c..075746aa 100644 --- a/sa-token-demo/sa-token-demo-test/pom.xml +++ b/sa-token-demo/sa-token-demo-test/pom.xml @@ -54,13 +54,6 @@ ${sa-token.version} --> - - - cn.dev33 - sa-token-jackson - ${sa-token.version} - - cn.dev33 diff --git a/sa-token-demo/sa-token-demo-test/src/main/java/com/pj/test/Test2Controller.java b/sa-token-demo/sa-token-demo-test/src/main/java/com/pj/test/Test2Controller.java index 397617ac..24e0c033 100644 --- a/sa-token-demo/sa-token-demo-test/src/main/java/com/pj/test/Test2Controller.java +++ b/sa-token-demo/sa-token-demo-test/src/main/java/com/pj/test/Test2Controller.java @@ -18,7 +18,7 @@ public class Test2Controller { public SaResult test2() { StpUtil.login(30003); - System.out.println(StpUtil.getSession().getTimeout()); + System.out.println(StpUtil.getSession().timeout()); System.out.println(StpUtil.getStpLogic().getTokenSession(false)); return SaResult.ok(); diff --git a/sa-token-plugin/pom.xml b/sa-token-plugin/pom.xml index c1a4aab6..786d669b 100644 --- a/sa-token-plugin/pom.xml +++ b/sa-token-plugin/pom.xml @@ -19,9 +19,10 @@ sa-token-jackson - - sa-token-redis + sa-token-redis-template + sa-token-redis-template-jdk-serializer sa-token-redis-jackson + sa-token-redis-fastjson sa-token-redis-fastjson2 sa-token-redisson-jackson diff --git a/sa-token-plugin/sa-token-alone-redis/pom.xml b/sa-token-plugin/sa-token-alone-redis/pom.xml index 8f22844a..7f9c5951 100644 --- a/sa-token-plugin/sa-token-alone-redis/pom.xml +++ b/sa-token-plugin/sa-token-alone-redis/pom.xml @@ -20,7 +20,7 @@ cn.dev33 - sa-token-redis + sa-token-redis-template true diff --git a/sa-token-plugin/sa-token-alone-redis/src/main/java/cn/dev33/satoken/dao/alone/SaAloneRedisInject.java b/sa-token-plugin/sa-token-alone-redis/src/main/java/cn/dev33/satoken/dao/alone/SaAloneRedisInject.java index abafe8c2..100ea6a8 100644 --- a/sa-token-plugin/sa-token-alone-redis/src/main/java/cn/dev33/satoken/dao/alone/SaAloneRedisInject.java +++ b/sa-token-plugin/sa-token-alone-redis/src/main/java/cn/dev33/satoken/dao/alone/SaAloneRedisInject.java @@ -15,7 +15,11 @@ */ package cn.dev33.satoken.dao.alone; -import cn.dev33.satoken.dao.*; +import cn.dev33.satoken.dao.SaTokenDao; +import cn.dev33.satoken.dao.SaTokenDaoDefaultImpl; +import cn.dev33.satoken.dao.SaTokenDaoRedisFastjson; +import cn.dev33.satoken.dao.SaTokenDaoRedisFastjson2; +import cn.dev33.satoken.dao.impl.SaTokenDaoForRedisTemplate; import cn.dev33.satoken.exception.SaTokenException; import org.apache.commons.pool2.impl.GenericObjectPoolConfig; import org.springframework.beans.factory.annotation.Autowired; @@ -210,22 +214,22 @@ public class SaAloneRedisInject implements EnvironmentAware{ // 如果开发者引入的是:sa-token-redis try { - Class.forName("cn.dev33.satoken.dao.SaTokenDaoRedis"); - SaTokenDaoRedis dao = (SaTokenDaoRedis)saTokenDao; - dao.isInit = false; - dao.init(factory); - return; - } catch (ClassNotFoundException ignored) { - } - // 如果开发者引入的是:sa-token-redis-jackson - try { - Class.forName("cn.dev33.satoken.dao.SaTokenDaoRedisJackson"); - SaTokenDaoRedisJackson dao = (SaTokenDaoRedisJackson)saTokenDao; + Class.forName("cn.dev33.satoken.dao.SaTokenDaoForRedisTemplate"); + SaTokenDaoForRedisTemplate dao = (SaTokenDaoForRedisTemplate)saTokenDao; dao.isInit = false; dao.init(factory); return; } catch (ClassNotFoundException ignored) { } + // TODO: 如果开发者引入的是:sa-token-redis-jdk-serializer +// try { +// Class.forName("cn.dev33.satoken.dao.SaTokenDaoForRedisTemplate"); +// SaTokenDaoRedisJackson dao = (SaTokenDaoRedisJackson)saTokenDao; +// dao.isInit = false; +// dao.init(factory); +// return; +// } catch (ClassNotFoundException ignored) { +// } // 如果开发者引入的是:sa-token-redis-fastjson try { Class.forName("cn.dev33.satoken.dao.SaTokenDaoRedisFastjson"); diff --git a/sa-token-plugin/sa-token-redis-fastjson/src/main/java/cn/dev33/satoken/dao/SaSessionForFastjsonCustomized.java b/sa-token-plugin/sa-token-redis-fastjson/src/main/java/cn/dev33/satoken/dao/SaSessionForFastjsonCustomized.java index f2a49023..27415f15 100644 --- a/sa-token-plugin/sa-token-redis-fastjson/src/main/java/cn/dev33/satoken/dao/SaSessionForFastjsonCustomized.java +++ b/sa-token-plugin/sa-token-redis-fastjson/src/main/java/cn/dev33/satoken/dao/SaSessionForFastjsonCustomized.java @@ -84,8 +84,8 @@ public class SaSessionForFastjsonCustomized extends SaSession { */ @Override @JSONField(serialize = false) - public long getTimeout() { - return super.getTimeout(); + public long timeout() { + return super.timeout(); } } diff --git a/sa-token-plugin/sa-token-redis-fastjson2/src/main/java/cn/dev33/satoken/dao/SaSessionForFastjson2Customized.java b/sa-token-plugin/sa-token-redis-fastjson2/src/main/java/cn/dev33/satoken/dao/SaSessionForFastjson2Customized.java index bde2c07d..86609141 100644 --- a/sa-token-plugin/sa-token-redis-fastjson2/src/main/java/cn/dev33/satoken/dao/SaSessionForFastjson2Customized.java +++ b/sa-token-plugin/sa-token-redis-fastjson2/src/main/java/cn/dev33/satoken/dao/SaSessionForFastjson2Customized.java @@ -84,8 +84,8 @@ public class SaSessionForFastjson2Customized extends SaSession { */ @Override @JSONField(serialize = false) - public long getTimeout() { - return super.getTimeout(); + public long timeout() { + return super.timeout(); } } diff --git a/sa-token-plugin/sa-token-redis-jackson/pom.xml b/sa-token-plugin/sa-token-redis-jackson/pom.xml index 4384248c..23dbabbf 100644 --- a/sa-token-plugin/sa-token-redis-jackson/pom.xml +++ b/sa-token-plugin/sa-token-redis-jackson/pom.xml @@ -17,30 +17,14 @@ sa-token integrate redis (to jackson) - - cn.dev33 - sa-token-core - - - - org.springframework.boot - spring-boot-starter-data-redis - - - - com.fasterxml.jackson.core - jackson-databind - true + cn.dev33 + sa-token-jackson - - com.fasterxml.jackson.datatype - jackson-datatype-jsr310 - true + cn.dev33 + sa-token-redis-template - - diff --git a/sa-token-plugin/sa-token-redis-jackson/src/main/java/cn/dev33/satoken/dao/SaSessionForJacksonCustomized.java b/sa-token-plugin/sa-token-redis-jackson/src/main/java/cn/dev33/satoken/dao/SaSessionForJacksonCustomized.java deleted file mode 100644 index ca387336..00000000 --- a/sa-token-plugin/sa-token-redis-jackson/src/main/java/cn/dev33/satoken/dao/SaSessionForJacksonCustomized.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2020-2099 sa-token.cc - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package cn.dev33.satoken.dao; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; - -import cn.dev33.satoken.session.SaSession; - -/** - * Jackson 定制版 SaSession,忽略 timeout 等属性的序列化 - * - * @author click33 - * @since 1.34.0 - */ -@JsonIgnoreProperties({"timeout"}) -public class SaSessionForJacksonCustomized extends SaSession { - - /** - * - */ - private static final long serialVersionUID = -7600983549653130681L; - - public SaSessionForJacksonCustomized() { - super(); - } - - /** - * 构建一个Session对象 - * @param id Session的id - */ - public SaSessionForJacksonCustomized(String id) { - super(id); - } - -} diff --git a/sa-token-plugin/sa-token-redis-jackson/src/main/resources/META-INF/services/cn.dev33.satoken.plugin.SaTokenPlugin b/sa-token-plugin/sa-token-redis-jackson/src/main/resources/META-INF/services/cn.dev33.satoken.plugin.SaTokenPlugin deleted file mode 100644 index e69de29b..00000000 diff --git a/sa-token-plugin/sa-token-redis-jackson/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/sa-token-plugin/sa-token-redis-jackson/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports deleted file mode 100644 index 40e2ed0b..00000000 --- a/sa-token-plugin/sa-token-redis-jackson/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ /dev/null @@ -1 +0,0 @@ -cn.dev33.satoken.dao.SaTokenDaoRedisJackson \ No newline at end of file diff --git a/sa-token-plugin/sa-token-redis-template-jdk-serializer/pom.xml b/sa-token-plugin/sa-token-redis-template-jdk-serializer/pom.xml new file mode 100644 index 00000000..ad80ac1f --- /dev/null +++ b/sa-token-plugin/sa-token-redis-template-jdk-serializer/pom.xml @@ -0,0 +1,34 @@ + + + 4.0.0 + + + cn.dev33 + sa-token-plugin + ${revision} + ../pom.xml + + jar + + sa-token-redis-jdk-serializer + sa-token-redis-template-jdk-serializer + sa-token integrate RedisTemplate (jdk-serializer) + + + + + cn.dev33 + sa-token-core + + + + org.springframework.boot + spring-boot-starter-data-redis + + + + + + diff --git a/sa-token-plugin/sa-token-redis/src/main/java/cn/dev33/satoken/dao/SaTokenDaoRedis.java b/sa-token-plugin/sa-token-redis-template-jdk-serializer/src/main/java/cn/dev33/satoken/dao/SaTokenDaoRedis.java similarity index 100% rename from sa-token-plugin/sa-token-redis/src/main/java/cn/dev33/satoken/dao/SaTokenDaoRedis.java rename to sa-token-plugin/sa-token-redis-template-jdk-serializer/src/main/java/cn/dev33/satoken/dao/SaTokenDaoRedis.java diff --git a/sa-token-plugin/sa-token-redis/src/main/resources/META-INF/spring.factories b/sa-token-plugin/sa-token-redis-template-jdk-serializer/src/main/resources/META-INF/spring.factories similarity index 100% rename from sa-token-plugin/sa-token-redis/src/main/resources/META-INF/spring.factories rename to sa-token-plugin/sa-token-redis-template-jdk-serializer/src/main/resources/META-INF/spring.factories diff --git a/sa-token-plugin/sa-token-redis/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/sa-token-plugin/sa-token-redis-template-jdk-serializer/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports similarity index 100% rename from sa-token-plugin/sa-token-redis/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports rename to sa-token-plugin/sa-token-redis-template-jdk-serializer/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports diff --git a/sa-token-plugin/sa-token-redis/.gitignore b/sa-token-plugin/sa-token-redis-template/.gitignore similarity index 100% rename from sa-token-plugin/sa-token-redis/.gitignore rename to sa-token-plugin/sa-token-redis-template/.gitignore diff --git a/sa-token-plugin/sa-token-redis/pom.xml b/sa-token-plugin/sa-token-redis-template/pom.xml similarity index 85% rename from sa-token-plugin/sa-token-redis/pom.xml rename to sa-token-plugin/sa-token-redis-template/pom.xml index a7603150..8b1741bd 100644 --- a/sa-token-plugin/sa-token-redis/pom.xml +++ b/sa-token-plugin/sa-token-redis-template/pom.xml @@ -12,9 +12,9 @@ jar - sa-token-redis - sa-token-redis - sa-token integrate redis + sa-token-redis-template + sa-token-redis-template + sa-token integrate RedisTemplate diff --git a/sa-token-plugin/sa-token-redis-jackson/src/main/java/cn/dev33/satoken/dao/SaTokenDaoRedisJackson.java b/sa-token-plugin/sa-token-redis-template/src/main/java/cn/dev33/satoken/dao/impl/SaTokenDaoForRedisTemplate.java similarity index 86% rename from sa-token-plugin/sa-token-redis-jackson/src/main/java/cn/dev33/satoken/dao/SaTokenDaoRedisJackson.java rename to sa-token-plugin/sa-token-redis-template/src/main/java/cn/dev33/satoken/dao/impl/SaTokenDaoForRedisTemplate.java index 642ce65c..dfd2d01c 100644 --- a/sa-token-plugin/sa-token-redis-jackson/src/main/java/cn/dev33/satoken/dao/SaTokenDaoRedisJackson.java +++ b/sa-token-plugin/sa-token-redis-template/src/main/java/cn/dev33/satoken/dao/impl/SaTokenDaoForRedisTemplate.java @@ -13,9 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package cn.dev33.satoken.dao; +package cn.dev33.satoken.dao.impl; -import cn.dev33.satoken.strategy.SaStrategy; +import cn.dev33.satoken.dao.SaTokenDao; import cn.dev33.satoken.util.SaFoxUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.connection.RedisConnectionFactory; @@ -28,21 +28,18 @@ import java.util.Set; import java.util.concurrent.TimeUnit; /** - * Sa-Token 持久层实现 [ Redis存储、Jackson序列化 ] + * Sa-Token 持久层实现 [ Redis 存储 ] (可用环境: SpringBoot2、SpringBoot3) * * @author click33 * @since 1.34.0 */ @Component -public class SaTokenDaoRedisJackson implements SaTokenDao { +public class SaTokenDaoForRedisTemplate implements SaTokenDao { + + public StringRedisTemplate stringRedisTemplate; /** - * String 读写专用 - */ - public StringRedisTemplate stringRedisTemplate; - - /** - * 标记:是否已初始化成功 + * 标记:当前 redis 连接信息是否已初始化成功 */ public boolean isInit; @@ -59,9 +56,6 @@ public class SaTokenDaoRedisJackson implements SaTokenDao { stringTemplate.afterPropertiesSet(); this.stringRedisTemplate = stringTemplate; - // 重写 SaSession 生成策略 - SaStrategy.instance.createSession = (sessionId) -> new SaSessionForJacksonCustomized(sessionId); - // 打上标记,表示已经初始化成功,后续无需再重新初始化 this.isInit = true; } @@ -76,7 +70,7 @@ public class SaTokenDaoRedisJackson implements SaTokenDao { } /** - * 写入Value,并设定存活时间 (单位: 秒) + * 写入Value,并设定存活时间 (单位: 秒) */ @Override public void set(String key, String value, long timeout) { @@ -92,7 +86,7 @@ public class SaTokenDaoRedisJackson implements SaTokenDao { } /** - * 修修改指定key-value键值对 (过期时间不变) + * 修改指定key-value键值对 (过期时间不变) */ @Override public void update(String key, String value) { @@ -139,6 +133,7 @@ public class SaTokenDaoRedisJackson implements SaTokenDao { stringRedisTemplate.expire(key, timeout, TimeUnit.SECONDS); } + /** * 搜索数据 @@ -150,4 +145,5 @@ public class SaTokenDaoRedisJackson implements SaTokenDao { return SaFoxUtil.searchList(list, start, size, sortType); } + } diff --git a/sa-token-plugin/sa-token-redis-jackson/src/main/resources/META-INF/spring.factories b/sa-token-plugin/sa-token-redis-template/src/main/resources/META-INF/spring.factories similarity index 55% rename from sa-token-plugin/sa-token-redis-jackson/src/main/resources/META-INF/spring.factories rename to sa-token-plugin/sa-token-redis-template/src/main/resources/META-INF/spring.factories index d792b9f9..c895fb4b 100644 --- a/sa-token-plugin/sa-token-redis-jackson/src/main/resources/META-INF/spring.factories +++ b/sa-token-plugin/sa-token-redis-template/src/main/resources/META-INF/spring.factories @@ -1 +1 @@ -org.springframework.boot.autoconfigure.EnableAutoConfiguration=cn.dev33.satoken.dao.SaTokenDaoRedisJackson \ No newline at end of file +org.springframework.boot.autoconfigure.EnableAutoConfiguration=cn.dev33.satoken.dao.impl.SaTokenDaoForRedisTemplate \ No newline at end of file diff --git a/sa-token-plugin/sa-token-redis-template/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/sa-token-plugin/sa-token-redis-template/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 00000000..638b0601 --- /dev/null +++ b/sa-token-plugin/sa-token-redis-template/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1 @@ +cn.dev33.satoken.dao.impl.SaTokenDaoForRedisTemplate \ No newline at end of file diff --git a/sa-token-plugin/sa-token-redisx/src/main/java/cn/dev33/satoken/dao/SaSessionForJson.java b/sa-token-plugin/sa-token-redisx/src/main/java/cn/dev33/satoken/dao/SaSessionForJson.java index f5a89f87..19b3205e 100644 --- a/sa-token-plugin/sa-token-redisx/src/main/java/cn/dev33/satoken/dao/SaSessionForJson.java +++ b/sa-token-plugin/sa-token-redisx/src/main/java/cn/dev33/satoken/dao/SaSessionForJson.java @@ -82,8 +82,8 @@ public class SaSessionForJson extends SaSession { * 忽略 timeout 字段的序列化 */ @Override - public long getTimeout() { - return super.getTimeout(); + public long timeout() { + return super.timeout(); } } diff --git a/sa-token-plugin/sa-token-sso/src/main/java/cn/dev33/satoken/sso/template/SaSsoClientTemplate.java b/sa-token-plugin/sa-token-sso/src/main/java/cn/dev33/satoken/sso/template/SaSsoClientTemplate.java index 80b4d603..8418f482 100644 --- a/sa-token-plugin/sa-token-sso/src/main/java/cn/dev33/satoken/sso/template/SaSsoClientTemplate.java +++ b/sa-token-plugin/sa-token-sso/src/main/java/cn/dev33/satoken/sso/template/SaSsoClientTemplate.java @@ -201,7 +201,7 @@ public class SaSsoClientTemplate extends SaSsoTemplate { */ public SaResult request(String url) { String body = getClientConfig().sendHttp.apply(url); - Map map = SaManager.getSaJsonTemplate().parseJsonToMap(body); + Map map = SaManager.getSaJsonTemplate().jsonToMap(body); return new SaResult(map); } diff --git a/sa-token-starter/sa-token-spring-boot-autoconfig/src/main/java/cn/dev33/satoken/spring/SaBeanInject.java b/sa-token-starter/sa-token-spring-boot-autoconfig/src/main/java/cn/dev33/satoken/spring/SaBeanInject.java index ce9ff0d3..e02f33d9 100644 --- a/sa-token-starter/sa-token-spring-boot-autoconfig/src/main/java/cn/dev33/satoken/spring/SaBeanInject.java +++ b/sa-token-starter/sa-token-spring-boot-autoconfig/src/main/java/cn/dev33/satoken/spring/SaBeanInject.java @@ -29,6 +29,7 @@ import cn.dev33.satoken.json.SaJsonTemplate; import cn.dev33.satoken.listener.SaTokenEventCenter; import cn.dev33.satoken.listener.SaTokenListener; import cn.dev33.satoken.log.SaLog; +import cn.dev33.satoken.plugin.SaTokenPluginLoader; import cn.dev33.satoken.same.SaSameTemplate; import cn.dev33.satoken.sign.SaSignTemplate; import cn.dev33.satoken.spring.pathmatch.SaPathMatcherHolder; @@ -68,6 +69,8 @@ public class SaBeanInject { if(saTokenConfig != null) { SaManager.setConfig(saTokenConfig); } + // 初始化 Sa-Token SPI 插件 + SaTokenPluginLoader.init(); } /** diff --git a/sa-token-test/sa-token-springboot-test/src/test/java/cn/dev33/satoken/core/session/SaSessionTest.java b/sa-token-test/sa-token-springboot-test/src/test/java/cn/dev33/satoken/core/session/SaSessionTest.java index c7096941..601206f3 100644 --- a/sa-token-test/sa-token-springboot-test/src/test/java/cn/dev33/satoken/core/session/SaSessionTest.java +++ b/sa-token-test/sa-token-springboot-test/src/test/java/cn/dev33/satoken/core/session/SaSessionTest.java @@ -94,16 +94,16 @@ public class SaSessionTest { SaSession session = new SaSession("session-1005"); SaManager.getSaTokenDao().setSession(session, 20000); session.updateMaxTimeout(100); - Assertions.assertTrue(session.getTimeout() <= 100); - System.out.println(session.getTimeout()); + Assertions.assertTrue(session.timeout() <= 100); + System.out.println(session.timeout()); // 仍然是 <=100 session.updateMaxTimeout(1000); - Assertions.assertTrue(session.getTimeout() <= 100); - System.out.println(session.getTimeout()); + Assertions.assertTrue(session.timeout() <= 100); + System.out.println(session.timeout()); // Min 修改 session.updateMinTimeout(-1); - System.out.println(session.getTimeout()); - Assertions.assertTrue(session.getTimeout() == -1); + System.out.println(session.timeout()); + Assertions.assertTrue(session.timeout() == -1); } // 测试token 签名