mirror of https://gitee.com/xiaonuobase/snowy
【升级】 升级SaToken版本到1.44.0
parent
6d78e12894
commit
79233da6f2
10
pom.xml
10
pom.xml
|
@ -256,35 +256,35 @@
|
|||
<dependency>
|
||||
<groupId>cn.dev33</groupId>
|
||||
<artifactId>sa-token-core</artifactId>
|
||||
<version>1.37.0</version>
|
||||
<version>1.44.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- sa-token -->
|
||||
<dependency>
|
||||
<groupId>cn.dev33</groupId>
|
||||
<artifactId>sa-token-spring-boot3-starter</artifactId>
|
||||
<version>1.37.0</version>
|
||||
<version>1.44.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- sa-token 整合 redis (使用jackson序列化方式) -->
|
||||
<dependency>
|
||||
<groupId>cn.dev33</groupId>
|
||||
<artifactId>sa-token-redis-jackson</artifactId>
|
||||
<version>1.37.0</version>
|
||||
<version>1.44.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Sa-Token插件:权限缓存与业务缓存分离 -->
|
||||
<dependency>
|
||||
<groupId>cn.dev33</groupId>
|
||||
<artifactId>sa-token-alone-redis</artifactId>
|
||||
<version>1.37.0</version>
|
||||
<version>1.44.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Sa-Token 插件:整合SSO -->
|
||||
<dependency>
|
||||
<groupId>cn.dev33</groupId>
|
||||
<artifactId>sa-token-sso</artifactId>
|
||||
<version>1.37.0</version>
|
||||
<version>1.44.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- JustAuth 第三方登录 -->
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -16,7 +16,7 @@ import cn.dev33.satoken.config.SaTokenConfig;
|
|||
import cn.dev33.satoken.interceptor.SaInterceptor;
|
||||
import cn.dev33.satoken.stp.StpInterface;
|
||||
import cn.dev33.satoken.stp.StpLogic;
|
||||
import cn.dev33.satoken.strategy.SaStrategy;
|
||||
import cn.dev33.satoken.strategy.SaAnnotationStrategy;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import jakarta.annotation.Resource;
|
||||
|
@ -81,7 +81,7 @@ public class AuthConfigure implements WebMvcConfigurer {
|
|||
@Autowired
|
||||
public void rewriteSaStrategy() {
|
||||
// 重写Sa-Token的注解处理器,增加注解合并功能
|
||||
SaStrategy.instance.getAnnotation = AnnotatedElementUtils::getMergedAnnotation;
|
||||
SaAnnotationStrategy.instance.getAnnotation = AnnotatedElementUtils::getMergedAnnotation;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -47,7 +47,7 @@ public class AuthApiProvider implements AuthApi {
|
|||
JSONObject jsonObject = JSONUtil.createObj();
|
||||
String userId = StrUtil.split(sessionId, StrUtil.COLON).get(3);
|
||||
SaSession saSession = StpUtil.getSessionByLoginId(userId, false);
|
||||
int tokenCount = saSession.getTokenSignList().size();
|
||||
int tokenCount = saSession.getTerminalList().size();
|
||||
long createTime = saSession.getCreateTime();
|
||||
jsonObject.set("userId", userId);
|
||||
jsonObject.set("tokenCount", tokenCount);
|
||||
|
@ -59,7 +59,7 @@ public class AuthApiProvider implements AuthApi {
|
|||
JSONObject jsonObject = JSONUtil.createObj();
|
||||
String userId = StrUtil.split(sessionId, StrUtil.COLON).get(3);
|
||||
SaSession saSession = StpClientUtil.getSessionByLoginId(userId, false);
|
||||
int tokenCount = saSession.getTokenSignList().size();
|
||||
int tokenCount = saSession.getTerminalList().size();
|
||||
long createTime = saSession.getCreateTime();
|
||||
jsonObject.set("userId", userId);
|
||||
jsonObject.set("tokenCount", tokenCount);
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
package vip.xiaonuo.auth.modular.login.listener;
|
||||
|
||||
import cn.dev33.satoken.listener.SaTokenListener;
|
||||
import cn.dev33.satoken.stp.SaLoginModel;
|
||||
import cn.dev33.satoken.stp.parameter.SaLoginParameter;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import jakarta.annotation.Resource;
|
||||
|
@ -43,10 +43,10 @@ public class AuthListener implements SaTokenListener {
|
|||
|
||||
/** 每次登录时触发 */
|
||||
@Override
|
||||
public void doLogin(String loginType, Object loginId, String tokenValue, SaLoginModel loginModel) {
|
||||
public void doLogin(String loginType, Object loginId, String tokenValue, SaLoginParameter loginModel) {
|
||||
// 更新用户的登录时间和登录ip等信息
|
||||
if(SaClientTypeEnum.B.getValue().equals(loginType)) {
|
||||
loginUserApi.updateUserLoginInfo(Convert.toStr(loginId), loginModel.getDevice());
|
||||
loginUserApi.updateUserLoginInfo(Convert.toStr(loginId), loginModel.getDeviceType());
|
||||
// 记录B端登录日志
|
||||
Object name = loginModel.getExtra("name");
|
||||
if(ObjectUtil.isNotEmpty(name)) {
|
||||
|
@ -55,7 +55,7 @@ public class AuthListener implements SaTokenListener {
|
|||
devLogApi.executeLoginLog(null);
|
||||
}
|
||||
} else {
|
||||
clientLoginUserApi.updateUserLoginInfo(Convert.toStr(loginId), loginModel.getDevice());
|
||||
clientLoginUserApi.updateUserLoginInfo(Convert.toStr(loginId), loginModel.getDeviceType());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -123,7 +123,7 @@ public class AuthListener implements SaTokenListener {
|
|||
|
||||
/** 每次Token续期时触发 */
|
||||
@Override
|
||||
public void doRenewTimeout(String tokenValue, Object loginId, long timeout) {
|
||||
public void doRenewTimeout(String loginType, Object loginId, String tokenValue, long timeout) {
|
||||
// ...
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,8 +12,8 @@
|
|||
*/
|
||||
package vip.xiaonuo.auth.modular.login.service.impl;
|
||||
|
||||
import cn.dev33.satoken.stp.SaLoginModel;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.dev33.satoken.stp.parameter.SaLoginParameter;
|
||||
import cn.hutool.captcha.CaptchaUtil;
|
||||
import cn.hutool.captcha.CircleCaptcha;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
|
@ -751,7 +751,7 @@ public class AuthServiceImpl implements AuthService {
|
|||
throw new CommonException(AuthExceptionEnum.ACCOUNT_DISABLED.getValue());
|
||||
}
|
||||
// 执行登录
|
||||
StpUtil.login(saBaseLoginUser.getId(), new SaLoginModel().setDevice(device).setExtra("name", saBaseLoginUser.getName()));
|
||||
StpUtil.login(saBaseLoginUser.getId(), new SaLoginParameter().setDeviceType(device).setExtra("name", saBaseLoginUser.getName()));
|
||||
// 填充B端用户信息并更新缓存
|
||||
fillSaBaseLoginUserAndUpdateCache(saBaseLoginUser);
|
||||
// 返回token
|
||||
|
@ -805,7 +805,7 @@ public class AuthServiceImpl implements AuthService {
|
|||
throw new CommonException(AuthExceptionEnum.ACCOUNT_DISABLED.getValue());
|
||||
}
|
||||
// 执行登录
|
||||
StpClientUtil.login(saBaseClientLoginUser.getId(), new SaLoginModel().setDevice(device).setExtra("name", saBaseClientLoginUser.getName()));
|
||||
StpClientUtil.login(saBaseClientLoginUser.getId(), new SaLoginParameter().setDevice(device).setExtra("name", saBaseClientLoginUser.getName()));
|
||||
// 填充C端用户信息并更新缓存
|
||||
fillSaBaseClientLoginUserAndUpdateCache(saBaseClientLoginUser);
|
||||
// 返回token
|
||||
|
|
|
@ -66,36 +66,36 @@ public class AuthSessionServiceImpl implements AuthSessionService {
|
|||
JSONObject jsonObject = JSONUtil.createObj();
|
||||
String userId = StrUtil.split(sessionId, StrUtil.COLON).get(3);
|
||||
SaSession saSession = StpUtil.getSessionByLoginId(userId, false);
|
||||
int tokenCount = saSession.getTokenSignList().size();
|
||||
int tokenCount = saSession.getTerminalList().size();
|
||||
long createTime = saSession.getCreateTime();
|
||||
jsonObject.set("userId", userId);
|
||||
jsonObject.set("tokenCount", tokenCount);
|
||||
jsonObject.set("createTime", DateTime.of(createTime));
|
||||
return jsonObject;
|
||||
}).collect(Collectors.toList());
|
||||
}).toList();
|
||||
|
||||
List<JSONObject> sessionListC = StpClientUtil.searchSessionId("", -1, -1, true).stream().map(sessionId -> {
|
||||
JSONObject jsonObject = JSONUtil.createObj();
|
||||
String userId = StrUtil.split(sessionId, StrUtil.COLON).get(3);
|
||||
SaSession saSession = StpClientUtil.getSessionByLoginId(userId, false);
|
||||
int tokenCount = saSession.getTokenSignList().size();
|
||||
int tokenCount = saSession.getTerminalList().size();
|
||||
long createTime = saSession.getCreateTime();
|
||||
jsonObject.set("userId", userId);
|
||||
jsonObject.set("tokenCount", tokenCount);
|
||||
jsonObject.set("createTime", DateTime.of(createTime));
|
||||
return jsonObject;
|
||||
}).collect(Collectors.toList());
|
||||
}).toList();
|
||||
|
||||
List<Integer> tokenCountList = CollectionUtil.newArrayList();
|
||||
tokenCountList.addAll(sessionListB.stream().map(jsonObject -> jsonObject.getInt("tokenCount")).collect(Collectors.toList()));
|
||||
tokenCountList.addAll(sessionListC.stream().map(jsonObject -> jsonObject.getInt("tokenCount")).collect(Collectors.toList()));
|
||||
tokenCountList.addAll(sessionListB.stream().map(jsonObject -> jsonObject.getInt("tokenCount")).toList());
|
||||
tokenCountList.addAll(sessionListC.stream().map(jsonObject -> jsonObject.getInt("tokenCount")).toList());
|
||||
CollectionUtil.sort(tokenCountList, Comparator.comparingInt(Integer::intValue));
|
||||
int currentSessionTotalCount = sessionListB.size() + sessionListC.size();
|
||||
authSessionAnalysisResult.setCurrentSessionTotalCount(Convert.toStr(currentSessionTotalCount));
|
||||
authSessionAnalysisResult.setMaxTokenCount(Convert.toStr(tokenCountList.get(tokenCountList.size() - 1)));
|
||||
List<Date> sessionCreateTimeList = CollectionUtil.newArrayList();
|
||||
sessionCreateTimeList.addAll(sessionListB.stream().map(jsonObject -> jsonObject.getDate("createTime")).collect(Collectors.toList()));
|
||||
sessionCreateTimeList.addAll(sessionListC.stream().map(jsonObject -> jsonObject.getDate("createTime")).collect(Collectors.toList()));
|
||||
sessionCreateTimeList.addAll(sessionListB.stream().map(jsonObject -> jsonObject.getDate("createTime")).toList());
|
||||
sessionCreateTimeList.addAll(sessionListC.stream().map(jsonObject -> jsonObject.getDate("createTime")).toList());
|
||||
DateTime oneHourAgo = DateUtil.offset(DateTime.now(), DateField.HOUR, -1);
|
||||
authSessionAnalysisResult.setOneHourNewlyAdded(Convert.toStr(sessionCreateTimeList.stream().filter(date -> DateUtil.compare(oneHourAgo, date) <= 0).count()));
|
||||
authSessionAnalysisResult.setProportionOfBAndC(sessionListB.size() + StrUtil.SLASH + sessionListC.size());
|
||||
|
@ -123,36 +123,36 @@ public class AuthSessionServiceImpl implements AuthSessionService {
|
|||
AuthSessionPageResult authSessionPageResult = JSONUtil.toBean(userJsonObject, AuthSessionPageResult.class);
|
||||
authSessionPageResult.setSessionId(saSession.getId());
|
||||
authSessionPageResult.setSessionCreateTime(DateTime.of(saSession.getCreateTime()));
|
||||
long sessionTimeOut = saSession.getTimeout();
|
||||
long sessionTimeOut = saSession.timeout();
|
||||
if (sessionTimeOut == -1) {
|
||||
authSessionPageResult.setSessionTimeout("永久");
|
||||
} else {
|
||||
authSessionPageResult.setSessionTimeout(CommonTimeFormatUtil.formatSeconds(saSession.getTimeout()));
|
||||
authSessionPageResult.setSessionTimeout(CommonTimeFormatUtil.formatSeconds(sessionTimeOut));
|
||||
}
|
||||
List<AuthSessionPageResult.TokenSignInfo> tokenInfoList = saSession.getTokenSignList().stream()
|
||||
.filter(tokenSign -> {
|
||||
long tokenTimeout = SaManager.getSaTokenDao().getTimeout(StpUtil.stpLogic.splicingKeyTokenValue(tokenSign.getValue()));
|
||||
List<AuthSessionPageResult.TokenSignInfo> tokenInfoList = saSession.getTerminalList().stream()
|
||||
.filter(terminalInfo -> {
|
||||
long tokenTimeout = SaManager.getSaTokenDao().getTimeout(StpUtil.stpLogic.splicingKeyTokenValue(terminalInfo.getTokenValue()));
|
||||
return tokenTimeout != -2; // 过滤掉tokenTimeout为-2的元素
|
||||
})
|
||||
.map(tokenSign -> {
|
||||
AuthSessionPageResult.TokenSignInfo tokenSignInfo = new AuthSessionPageResult.TokenSignInfo();
|
||||
tokenSignInfo.setTokenValue(tokenSign.getValue());
|
||||
tokenSignInfo.setTokenDevice(tokenSign.getDevice());
|
||||
long tokenTimeout = SaManager.getSaTokenDao().getTimeout(StpUtil.stpLogic.splicingKeyTokenValue(tokenSign.getValue()));
|
||||
.map(terminalInfo -> {
|
||||
AuthSessionPageResult.TokenSignInfo terminalInfoInfo = new AuthSessionPageResult.TokenSignInfo();
|
||||
terminalInfoInfo.setTokenValue(terminalInfo.getTokenValue());
|
||||
terminalInfoInfo.setTokenDevice(terminalInfo.getDeviceType());
|
||||
long tokenTimeout = SaManager.getSaTokenDao().getTimeout(StpUtil.stpLogic.splicingKeyTokenValue(terminalInfo.getTokenValue()));
|
||||
long tokenTimeoutConfig = StpUtil.stpLogic.getConfigOrGlobal().getTimeout();
|
||||
if (tokenTimeout == -1) {
|
||||
tokenSignInfo.setTokenTimeout("永久");
|
||||
tokenSignInfo.setTokenTimeoutPercent(100d);
|
||||
terminalInfoInfo.setTokenTimeout("永久");
|
||||
terminalInfoInfo.setTokenTimeoutPercent(100d);
|
||||
} else {
|
||||
tokenSignInfo.setTokenTimeout(CommonTimeFormatUtil.formatSeconds(SaManager.getSaTokenDao()
|
||||
.getTimeout(StpUtil.stpLogic.splicingKeyTokenValue(tokenSign.getValue()))));
|
||||
terminalInfoInfo.setTokenTimeout(CommonTimeFormatUtil.formatSeconds(SaManager.getSaTokenDao()
|
||||
.getTimeout(StpUtil.stpLogic.splicingKeyTokenValue(terminalInfo.getTokenValue()))));
|
||||
if (tokenTimeoutConfig == -1) {
|
||||
tokenSignInfo.setTokenTimeoutPercent(0d);
|
||||
terminalInfoInfo.setTokenTimeoutPercent(0d);
|
||||
} else {
|
||||
tokenSignInfo.setTokenTimeoutPercent(NumberUtil.div(tokenTimeout, tokenTimeoutConfig));
|
||||
terminalInfoInfo.setTokenTimeoutPercent(NumberUtil.div(tokenTimeout, tokenTimeoutConfig));
|
||||
}
|
||||
}
|
||||
return tokenSignInfo;
|
||||
return terminalInfoInfo;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
authSessionPageResult.setTokenCount(tokenInfoList.size());
|
||||
|
@ -186,34 +186,34 @@ public class AuthSessionServiceImpl implements AuthSessionService {
|
|||
AuthSessionPageResult authSessionPageResult = JSONUtil.toBean(userJsonObject, AuthSessionPageResult.class);
|
||||
authSessionPageResult.setSessionId(saSession.getId());
|
||||
authSessionPageResult.setSessionCreateTime(DateTime.of(saSession.getCreateTime()));
|
||||
long sessionTimeOut = saSession.getTimeout();
|
||||
long sessionTimeOut = saSession.timeout();
|
||||
if (sessionTimeOut == -1) {
|
||||
authSessionPageResult.setSessionTimeout("永久");
|
||||
} else {
|
||||
authSessionPageResult.setSessionTimeout(CommonTimeFormatUtil.formatSeconds(saSession.getTimeout()));
|
||||
authSessionPageResult.setSessionTimeout(CommonTimeFormatUtil.formatSeconds(sessionTimeOut));
|
||||
}
|
||||
List<AuthSessionPageResult.TokenSignInfo> tokenInfoList = saSession.getTokenSignList().stream().filter(tokenSign -> {
|
||||
long tokenTimeout = SaManager.getSaTokenDao().getTimeout(StpClientUtil.stpLogic.splicingKeyTokenValue(tokenSign.getValue()));
|
||||
List<AuthSessionPageResult.TokenSignInfo> tokenInfoList = saSession.getTerminalList().stream().filter(terminalInfo -> {
|
||||
long tokenTimeout = SaManager.getSaTokenDao().getTimeout(StpClientUtil.stpLogic.splicingKeyTokenValue(terminalInfo.getTokenValue()));
|
||||
return tokenTimeout != -2; // 过滤掉tokenTimeout为-2的元素
|
||||
}).map(tokenSign -> {
|
||||
AuthSessionPageResult.TokenSignInfo tokenSignInfo = new AuthSessionPageResult.TokenSignInfo();
|
||||
tokenSignInfo.setTokenValue(tokenSign.getValue());
|
||||
tokenSignInfo.setTokenDevice(tokenSign.getDevice());
|
||||
long tokenTimeout = SaManager.getSaTokenDao().getTimeout(StpClientUtil.stpLogic.splicingKeyTokenValue(tokenSign.getValue()));
|
||||
}).map(terminalInfo -> {
|
||||
AuthSessionPageResult.TokenSignInfo terminalInfoInfo = new AuthSessionPageResult.TokenSignInfo();
|
||||
terminalInfoInfo.setTokenValue(terminalInfo.getTokenValue());
|
||||
terminalInfoInfo.setTokenDevice(terminalInfo.getDeviceType());
|
||||
long tokenTimeout = SaManager.getSaTokenDao().getTimeout(StpClientUtil.stpLogic.splicingKeyTokenValue(terminalInfo.getTokenValue()));
|
||||
long tokenTimeoutConfig = StpClientUtil.stpLogic.getConfigOrGlobal().getTimeout();
|
||||
if (tokenTimeout == -1) {
|
||||
tokenSignInfo.setTokenTimeout("永久");
|
||||
tokenSignInfo.setTokenTimeoutPercent(100d);
|
||||
terminalInfoInfo.setTokenTimeout("永久");
|
||||
terminalInfoInfo.setTokenTimeoutPercent(100d);
|
||||
} else {
|
||||
tokenSignInfo.setTokenTimeout(CommonTimeFormatUtil.formatSeconds(SaManager.getSaTokenDao()
|
||||
.getTimeout(StpClientUtil.stpLogic.splicingKeyTokenValue(tokenSign.getValue()))));
|
||||
terminalInfoInfo.setTokenTimeout(CommonTimeFormatUtil.formatSeconds(SaManager.getSaTokenDao()
|
||||
.getTimeout(StpClientUtil.stpLogic.splicingKeyTokenValue(terminalInfo.getTokenValue()))));
|
||||
if (tokenTimeoutConfig == -1) {
|
||||
tokenSignInfo.setTokenTimeoutPercent(0d);
|
||||
terminalInfoInfo.setTokenTimeoutPercent(0d);
|
||||
} else {
|
||||
tokenSignInfo.setTokenTimeoutPercent(NumberUtil.div(tokenTimeout, tokenTimeoutConfig));
|
||||
terminalInfoInfo.setTokenTimeoutPercent(NumberUtil.div(tokenTimeout, tokenTimeoutConfig));
|
||||
}
|
||||
}
|
||||
return tokenSignInfo;
|
||||
return terminalInfoInfo;
|
||||
}).collect(Collectors.toList());
|
||||
authSessionPageResult.setTokenCount(tokenInfoList.size());
|
||||
authSessionPageResult.setTokenSignList(tokenInfoList);
|
||||
|
|
Loading…
Reference in New Issue