refactor: 重构部分 sa-token-redis 插件,适配 SPI 机制
This commit is contained in:
+11
-1
@@ -111,7 +111,7 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cn.dev33</groupId>
|
<groupId>cn.dev33</groupId>
|
||||||
<artifactId>sa-token-redis</artifactId>
|
<artifactId>sa-token-redis-template</artifactId>
|
||||||
<version>${revision}</version>
|
<version>${revision}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -194,6 +194,16 @@
|
|||||||
<artifactId>sa-token-temp-jwt</artifactId>
|
<artifactId>sa-token-temp-jwt</artifactId>
|
||||||
<version>${revision}</version>
|
<version>${revision}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.dev33</groupId>
|
||||||
|
<artifactId>sa-token-jackson</artifactId>
|
||||||
|
<version>${revision}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.dev33</groupId>
|
||||||
|
<artifactId>sa-token-redis-template-jdk-serializer</artifactId>
|
||||||
|
<version>${revision}</version>
|
||||||
|
</dependency>
|
||||||
<!-- endregion-->
|
<!-- endregion-->
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|||||||
@@ -15,6 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package cn.dev33.satoken.plugin;
|
package cn.dev33.satoken.plugin;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.SaManager;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ServiceLoader;
|
import java.util.ServiceLoader;
|
||||||
@@ -27,12 +29,32 @@ import java.util.ServiceLoader;
|
|||||||
*/
|
*/
|
||||||
public class SaTokenPluginLoader {
|
public class SaTokenPluginLoader {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否已经加载过插件
|
||||||
|
*/
|
||||||
|
public static boolean isLoader = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 所有插件的集合
|
||||||
|
*/
|
||||||
public static List<SaTokenPlugin> pluginList;
|
public static List<SaTokenPlugin> pluginList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化插件
|
* 初始化加载所有插件(多次调用只会执行一次)
|
||||||
*/
|
*/
|
||||||
public static void init() {
|
public static void init() {
|
||||||
|
if(isLoader) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
loaderPlugins();
|
||||||
|
isLoader = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据 SPI 机制加载所有插件
|
||||||
|
*/
|
||||||
|
public static void loaderPlugins() {
|
||||||
|
SaManager.getLog().info("SPI 插件加载开始 ...");
|
||||||
List<SaTokenPlugin> list = new ArrayList<>();
|
List<SaTokenPlugin> list = new ArrayList<>();
|
||||||
ServiceLoader<SaTokenPlugin> plugins = ServiceLoader.load(SaTokenPlugin.class);
|
ServiceLoader<SaTokenPlugin> plugins = ServiceLoader.load(SaTokenPlugin.class);
|
||||||
for (SaTokenPlugin plugin : plugins) {
|
for (SaTokenPlugin plugin : plugins) {
|
||||||
@@ -40,6 +62,7 @@ public class SaTokenPluginLoader {
|
|||||||
list.add(plugin);
|
list.add(plugin);
|
||||||
}
|
}
|
||||||
pluginList = list;
|
pluginList = list;
|
||||||
|
SaManager.getLog().info("SPI 插件加载结束 ...");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -393,7 +393,7 @@ public class SaSession implements SaSetValueInterface, Serializable {
|
|||||||
* 获取此Session的剩余存活时间 (单位: 秒)
|
* 获取此Session的剩余存活时间 (单位: 秒)
|
||||||
* @return 此Session的剩余存活时间 (单位: 秒)
|
* @return 此Session的剩余存活时间 (单位: 秒)
|
||||||
*/
|
*/
|
||||||
public long getTimeout() {
|
public long timeout() {
|
||||||
return SaManager.getSaTokenDao().getSessionTimeout(this.id);
|
return SaManager.getSaTokenDao().getSessionTimeout(this.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -411,7 +411,7 @@ public class SaSession implements SaSetValueInterface, Serializable {
|
|||||||
*/
|
*/
|
||||||
public void updateMinTimeout(long minTimeout) {
|
public void updateMinTimeout(long minTimeout) {
|
||||||
long min = trans(minTimeout);
|
long min = trans(minTimeout);
|
||||||
long curr = trans(getTimeout());
|
long curr = trans(timeout());
|
||||||
if(curr < min) {
|
if(curr < min) {
|
||||||
updateTimeout(minTimeout);
|
updateTimeout(minTimeout);
|
||||||
}
|
}
|
||||||
@@ -423,7 +423,7 @@ public class SaSession implements SaSetValueInterface, Serializable {
|
|||||||
*/
|
*/
|
||||||
public void updateMaxTimeout(long maxTimeout) {
|
public void updateMaxTimeout(long maxTimeout) {
|
||||||
long max = trans(maxTimeout);
|
long max = trans(maxTimeout);
|
||||||
long curr = trans(getTimeout());
|
long curr = trans(timeout());
|
||||||
if(curr > max) {
|
if(curr > max) {
|
||||||
updateTimeout(maxTimeout);
|
updateTimeout(maxTimeout);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,13 +54,6 @@
|
|||||||
<version>${sa-token.version}</version>
|
<version>${sa-token.version}</version>
|
||||||
</dependency> -->
|
</dependency> -->
|
||||||
|
|
||||||
<!-- Sa-Token整合 Redis (使用jackson序列化方式) -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>cn.dev33</groupId>
|
|
||||||
<artifactId>sa-token-jackson</artifactId>
|
|
||||||
<version>${sa-token.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- Sa-Token整合 Redis (使用jackson序列化方式) -->
|
<!-- Sa-Token整合 Redis (使用jackson序列化方式) -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cn.dev33</groupId>
|
<groupId>cn.dev33</groupId>
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ public class Test2Controller {
|
|||||||
public SaResult test2() {
|
public SaResult test2() {
|
||||||
|
|
||||||
StpUtil.login(30003);
|
StpUtil.login(30003);
|
||||||
System.out.println(StpUtil.getSession().getTimeout());
|
System.out.println(StpUtil.getSession().timeout());
|
||||||
System.out.println(StpUtil.getStpLogic().getTokenSession(false));
|
System.out.println(StpUtil.getStpLogic().getTokenSession(false));
|
||||||
|
|
||||||
return SaResult.ok();
|
return SaResult.ok();
|
||||||
|
|||||||
@@ -19,9 +19,10 @@
|
|||||||
<!-- 所有子模块 -->
|
<!-- 所有子模块 -->
|
||||||
<modules>
|
<modules>
|
||||||
<module>sa-token-jackson</module>
|
<module>sa-token-jackson</module>
|
||||||
|
<module>sa-token-redis-template</module>
|
||||||
<module>sa-token-redis</module>
|
<module>sa-token-redis-template-jdk-serializer</module>
|
||||||
<module>sa-token-redis-jackson</module>
|
<module>sa-token-redis-jackson</module>
|
||||||
|
|
||||||
<module>sa-token-redis-fastjson</module>
|
<module>sa-token-redis-fastjson</module>
|
||||||
<module>sa-token-redis-fastjson2</module>
|
<module>sa-token-redis-fastjson2</module>
|
||||||
<module>sa-token-redisson-jackson</module>
|
<module>sa-token-redisson-jackson</module>
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
<!-- Sa-Token Redis Dependency -->
|
<!-- Sa-Token Redis Dependency -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cn.dev33</groupId>
|
<groupId>cn.dev33</groupId>
|
||||||
<artifactId>sa-token-redis</artifactId>
|
<artifactId>sa-token-redis-template</artifactId>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
+16
-12
@@ -15,7 +15,11 @@
|
|||||||
*/
|
*/
|
||||||
package cn.dev33.satoken.dao.alone;
|
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 cn.dev33.satoken.exception.SaTokenException;
|
||||||
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
|
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -210,22 +214,22 @@ public class SaAloneRedisInject implements EnvironmentAware{
|
|||||||
|
|
||||||
// 如果开发者引入的是:sa-token-redis
|
// 如果开发者引入的是:sa-token-redis
|
||||||
try {
|
try {
|
||||||
Class.forName("cn.dev33.satoken.dao.SaTokenDaoRedis");
|
Class.forName("cn.dev33.satoken.dao.SaTokenDaoForRedisTemplate");
|
||||||
SaTokenDaoRedis dao = (SaTokenDaoRedis)saTokenDao;
|
SaTokenDaoForRedisTemplate dao = (SaTokenDaoForRedisTemplate)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;
|
|
||||||
dao.isInit = false;
|
dao.isInit = false;
|
||||||
dao.init(factory);
|
dao.init(factory);
|
||||||
return;
|
return;
|
||||||
} catch (ClassNotFoundException ignored) {
|
} 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
|
// 如果开发者引入的是:sa-token-redis-fastjson
|
||||||
try {
|
try {
|
||||||
Class.forName("cn.dev33.satoken.dao.SaTokenDaoRedisFastjson");
|
Class.forName("cn.dev33.satoken.dao.SaTokenDaoRedisFastjson");
|
||||||
|
|||||||
+2
-2
@@ -84,8 +84,8 @@ public class SaSessionForFastjsonCustomized extends SaSession {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@JSONField(serialize = false)
|
@JSONField(serialize = false)
|
||||||
public long getTimeout() {
|
public long timeout() {
|
||||||
return super.getTimeout();
|
return super.timeout();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -84,8 +84,8 @@ public class SaSessionForFastjson2Customized extends SaSession {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@JSONField(serialize = false)
|
@JSONField(serialize = false)
|
||||||
public long getTimeout() {
|
public long timeout() {
|
||||||
return super.getTimeout();
|
return super.timeout();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,30 +17,14 @@
|
|||||||
<description>sa-token integrate redis (to jackson)</description>
|
<description>sa-token integrate redis (to jackson)</description>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<!-- sa-token-spring-boot-starter -->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cn.dev33</groupId>
|
<groupId>cn.dev33</groupId>
|
||||||
<artifactId>sa-token-core</artifactId>
|
<artifactId>sa-token-jackson</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- RedisTemplate 相关操作API -->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>cn.dev33</groupId>
|
||||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
<artifactId>sa-token-redis-template</artifactId>
|
||||||
</dependency>
|
|
||||||
<!-- jackson-databind -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
|
||||||
<artifactId>jackson-databind</artifactId>
|
|
||||||
<optional>true</optional>
|
|
||||||
</dependency>
|
|
||||||
<!-- jackson-datatype-jsr310 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
|
||||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
|
||||||
<optional>true</optional>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
-48
@@ -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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
-1
@@ -1 +0,0 @@
|
|||||||
cn.dev33.satoken.dao.SaTokenDaoRedisJackson
|
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
<?xml version='1.0' encoding='utf-8'?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>cn.dev33</groupId>
|
||||||
|
<artifactId>sa-token-plugin</artifactId>
|
||||||
|
<version>${revision}</version>
|
||||||
|
<relativePath>../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>sa-token-redis-jdk-serializer</name>
|
||||||
|
<artifactId>sa-token-redis-template-jdk-serializer</artifactId>
|
||||||
|
<description>sa-token integrate RedisTemplate (jdk-serializer)</description>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- sa-token-spring-boot-starter -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.dev33</groupId>
|
||||||
|
<artifactId>sa-token-core</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- RedisTemplate 相关操作API -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</project>
|
||||||
+3
-3
@@ -12,9 +12,9 @@
|
|||||||
</parent>
|
</parent>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>sa-token-redis</name>
|
<name>sa-token-redis-template</name>
|
||||||
<artifactId>sa-token-redis</artifactId>
|
<artifactId>sa-token-redis-template</artifactId>
|
||||||
<description>sa-token integrate redis</description>
|
<description>sa-token integrate RedisTemplate</description>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<!-- sa-token-spring-boot-starter -->
|
<!-- sa-token-spring-boot-starter -->
|
||||||
+8
-12
@@ -13,9 +13,9 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* 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 cn.dev33.satoken.util.SaFoxUtil;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||||
@@ -28,21 +28,18 @@ import java.util.Set;
|
|||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sa-Token 持久层实现 [ Redis存储、Jackson序列化 ]
|
* Sa-Token 持久层实现 [ Redis 存储 ] (可用环境: SpringBoot2、SpringBoot3)
|
||||||
*
|
*
|
||||||
* @author click33
|
* @author click33
|
||||||
* @since 1.34.0
|
* @since 1.34.0
|
||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
public class SaTokenDaoRedisJackson implements SaTokenDao {
|
public class SaTokenDaoForRedisTemplate implements SaTokenDao {
|
||||||
|
|
||||||
/**
|
|
||||||
* String 读写专用
|
|
||||||
*/
|
|
||||||
public StringRedisTemplate stringRedisTemplate;
|
public StringRedisTemplate stringRedisTemplate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 标记:是否已初始化成功
|
* 标记:当前 redis 连接信息是否已初始化成功
|
||||||
*/
|
*/
|
||||||
public boolean isInit;
|
public boolean isInit;
|
||||||
|
|
||||||
@@ -59,9 +56,6 @@ public class SaTokenDaoRedisJackson implements SaTokenDao {
|
|||||||
stringTemplate.afterPropertiesSet();
|
stringTemplate.afterPropertiesSet();
|
||||||
this.stringRedisTemplate = stringTemplate;
|
this.stringRedisTemplate = stringTemplate;
|
||||||
|
|
||||||
// 重写 SaSession 生成策略
|
|
||||||
SaStrategy.instance.createSession = (sessionId) -> new SaSessionForJacksonCustomized(sessionId);
|
|
||||||
|
|
||||||
// 打上标记,表示已经初始化成功,后续无需再重新初始化
|
// 打上标记,表示已经初始化成功,后续无需再重新初始化
|
||||||
this.isInit = true;
|
this.isInit = true;
|
||||||
}
|
}
|
||||||
@@ -92,7 +86,7 @@ public class SaTokenDaoRedisJackson implements SaTokenDao {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修修改指定key-value键值对 (过期时间不变)
|
* 修改指定key-value键值对 (过期时间不变)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void update(String key, String value) {
|
public void update(String key, String value) {
|
||||||
@@ -140,6 +134,7 @@ public class SaTokenDaoRedisJackson implements SaTokenDao {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 搜索数据
|
* 搜索数据
|
||||||
*/
|
*/
|
||||||
@@ -150,4 +145,5 @@ public class SaTokenDaoRedisJackson implements SaTokenDao {
|
|||||||
return SaFoxUtil.searchList(list, start, size, sortType);
|
return SaFoxUtil.searchList(list, start, size, sortType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
+1
-1
@@ -1 +1 @@
|
|||||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=cn.dev33.satoken.dao.SaTokenDaoRedisJackson
|
org.springframework.boot.autoconfigure.EnableAutoConfiguration=cn.dev33.satoken.dao.impl.SaTokenDaoForRedisTemplate
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
cn.dev33.satoken.dao.impl.SaTokenDaoForRedisTemplate
|
||||||
+2
-2
@@ -82,8 +82,8 @@ public class SaSessionForJson extends SaSession {
|
|||||||
* 忽略 timeout 字段的序列化
|
* 忽略 timeout 字段的序列化
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public long getTimeout() {
|
public long timeout() {
|
||||||
return super.getTimeout();
|
return super.timeout();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -201,7 +201,7 @@ public class SaSsoClientTemplate extends SaSsoTemplate {
|
|||||||
*/
|
*/
|
||||||
public SaResult request(String url) {
|
public SaResult request(String url) {
|
||||||
String body = getClientConfig().sendHttp.apply(url);
|
String body = getClientConfig().sendHttp.apply(url);
|
||||||
Map<String, Object> map = SaManager.getSaJsonTemplate().parseJsonToMap(body);
|
Map<String, Object> map = SaManager.getSaJsonTemplate().jsonToMap(body);
|
||||||
return new SaResult(map);
|
return new SaResult(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
@@ -29,6 +29,7 @@ import cn.dev33.satoken.json.SaJsonTemplate;
|
|||||||
import cn.dev33.satoken.listener.SaTokenEventCenter;
|
import cn.dev33.satoken.listener.SaTokenEventCenter;
|
||||||
import cn.dev33.satoken.listener.SaTokenListener;
|
import cn.dev33.satoken.listener.SaTokenListener;
|
||||||
import cn.dev33.satoken.log.SaLog;
|
import cn.dev33.satoken.log.SaLog;
|
||||||
|
import cn.dev33.satoken.plugin.SaTokenPluginLoader;
|
||||||
import cn.dev33.satoken.same.SaSameTemplate;
|
import cn.dev33.satoken.same.SaSameTemplate;
|
||||||
import cn.dev33.satoken.sign.SaSignTemplate;
|
import cn.dev33.satoken.sign.SaSignTemplate;
|
||||||
import cn.dev33.satoken.spring.pathmatch.SaPathMatcherHolder;
|
import cn.dev33.satoken.spring.pathmatch.SaPathMatcherHolder;
|
||||||
@@ -68,6 +69,8 @@ public class SaBeanInject {
|
|||||||
if(saTokenConfig != null) {
|
if(saTokenConfig != null) {
|
||||||
SaManager.setConfig(saTokenConfig);
|
SaManager.setConfig(saTokenConfig);
|
||||||
}
|
}
|
||||||
|
// 初始化 Sa-Token SPI 插件
|
||||||
|
SaTokenPluginLoader.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+6
-6
@@ -94,16 +94,16 @@ public class SaSessionTest {
|
|||||||
SaSession session = new SaSession("session-1005");
|
SaSession session = new SaSession("session-1005");
|
||||||
SaManager.getSaTokenDao().setSession(session, 20000);
|
SaManager.getSaTokenDao().setSession(session, 20000);
|
||||||
session.updateMaxTimeout(100);
|
session.updateMaxTimeout(100);
|
||||||
Assertions.assertTrue(session.getTimeout() <= 100);
|
Assertions.assertTrue(session.timeout() <= 100);
|
||||||
System.out.println(session.getTimeout());
|
System.out.println(session.timeout());
|
||||||
// 仍然是 <=100
|
// 仍然是 <=100
|
||||||
session.updateMaxTimeout(1000);
|
session.updateMaxTimeout(1000);
|
||||||
Assertions.assertTrue(session.getTimeout() <= 100);
|
Assertions.assertTrue(session.timeout() <= 100);
|
||||||
System.out.println(session.getTimeout());
|
System.out.println(session.timeout());
|
||||||
// Min 修改
|
// Min 修改
|
||||||
session.updateMinTimeout(-1);
|
session.updateMinTimeout(-1);
|
||||||
System.out.println(session.getTimeout());
|
System.out.println(session.timeout());
|
||||||
Assertions.assertTrue(session.getTimeout() == -1);
|
Assertions.assertTrue(session.timeout() == -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 测试token 签名
|
// 测试token 签名
|
||||||
|
|||||||
Reference in New Issue
Block a user