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