mirror of
https://gitee.com/dromara/sa-token.git
synced 2025-04-05 17:37:53 +08:00
v1.27.1 beta. 细节优化
This commit is contained in:
parent
82591e397f
commit
f9ec6e6487
@ -93,7 +93,7 @@ public class SaLoginModel {
|
||||
/**
|
||||
* @return 获取device参数,如果为null,则返回默认值
|
||||
*/
|
||||
public String getDeviceOrDefalut() {
|
||||
public String getDeviceOrDefault() {
|
||||
if(device == null) {
|
||||
return SaTokenConsts.DEFAULT_LOGIN_DEVICE;
|
||||
}
|
||||
@ -142,4 +142,13 @@ public class SaLoginModel {
|
||||
return "SaLoginModel [device=" + device + ", isLastingCookie=" + isLastingCookie + ", timeout=" + timeout + "]";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更换为 getDeviceOrDefault()
|
||||
* @return /
|
||||
*/
|
||||
@Deprecated
|
||||
public String getDeviceOrDefalut() {
|
||||
return getDeviceOrDefault();
|
||||
}
|
||||
}
|
||||
|
@ -256,7 +256,7 @@ public class StpLogic {
|
||||
if(config.getIsConcurrent()) {
|
||||
// 如果配置为共享token, 则尝试从Session签名记录里取出token
|
||||
if(config.getIsShare()) {
|
||||
tokenValue = getTokenValueByLoginId(id, loginModel.getDevice());
|
||||
tokenValue = getTokenValueByLoginId(id, loginModel.getDeviceOrDefault());
|
||||
}
|
||||
} else {
|
||||
// --- 如果不允许并发登录,则将这个账号的历史登录标记为:被顶下线
|
||||
@ -272,7 +272,7 @@ public class StpLogic {
|
||||
session.updateMinTimeout(loginModel.getTimeout());
|
||||
|
||||
// 在 User-Session 上记录token签名
|
||||
session.addTokenSign(tokenValue, loginModel.getDeviceOrDefalut());
|
||||
session.addTokenSign(tokenValue, loginModel.getDeviceOrDefault());
|
||||
|
||||
// ------ 4. 持久化其它数据
|
||||
// token -> id 映射关系
|
||||
|
@ -35,6 +35,7 @@
|
||||
<version>2.11.2</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<!-- jackson-datatype-jsr310 -->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
|
@ -55,14 +55,16 @@ public class SaTokenDaoRedisJackson implements SaTokenDao {
|
||||
// 指定相应的序列化方案
|
||||
StringRedisSerializer keySerializer = new StringRedisSerializer();
|
||||
GenericJackson2JsonRedisSerializer valueSerializer = new GenericJackson2JsonRedisSerializer();
|
||||
// 通过反射获取Mapper对象, 配置[忽略未知字段], 增强兼容性
|
||||
// 通过反射获取Mapper对象, 增加一些配置, 增强兼容性
|
||||
try {
|
||||
Field field = GenericJackson2JsonRedisSerializer.class.getDeclaredField("mapper");
|
||||
field.setAccessible(true);
|
||||
ObjectMapper objectMapper = (ObjectMapper) field.get(valueSerializer);
|
||||
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
objectMapper.registerModule(new JavaTimeModule());
|
||||
this.objectMapper = objectMapper;
|
||||
// 配置[忽略未知字段]
|
||||
this.objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
// 配置[时间类型转换]
|
||||
this.objectMapper.registerModule(new JavaTimeModule());
|
||||
} catch (Exception e) {
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ public class StpLogicJwtForStateless extends StpLogic {
|
||||
String tokenValue = SaJwtUtil.createToken(
|
||||
loginType,
|
||||
id,
|
||||
loginModel.getDeviceOrDefalut(),
|
||||
loginModel.getDeviceOrDefault(),
|
||||
loginModel.getTimeout(),
|
||||
jwtSecretKey()
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user