StpUtil.getTokenSession() 时若未提供 token 将直接抛出异常

This commit is contained in:
click33 2024-05-12 08:59:02 +08:00
parent 43c9452fb2
commit 8f467bbc9c
2 changed files with 5 additions and 2 deletions

View File

@ -125,6 +125,9 @@ public interface SaErrorCode {
/** 获取 SaSession 时提供的 SessionId 为空 */ /** 获取 SaSession 时提供的 SessionId 为空 */
int CODE_11072 = 11072; int CODE_11072 = 11072;
/** 获取 Token-Session 时提供的 token 为空 */
int CODE_11073 = 11073;
// ------------ // ------------

View File

@ -1296,7 +1296,7 @@ public class StpLogic {
*/ */
public SaSession getTokenSessionByToken(String tokenValue, boolean isCreate) { public SaSession getTokenSessionByToken(String tokenValue, boolean isCreate) {
if(SaFoxUtil.isEmpty(tokenValue)) { if(SaFoxUtil.isEmpty(tokenValue)) {
throw new SaTokenException("Token-Session 获取失败token 不能为空"); throw new SaTokenException("Token-Session 获取失败token 为空").setCode(SaErrorCode.CODE_11073);
} }
return getSessionBySessionId(splicingKeyTokenSession(tokenValue), isCreate, null, session -> { return getSessionBySessionId(splicingKeyTokenSession(tokenValue), isCreate, null, session -> {
// 这里是该 Token-Session 首次创建时才会被执行的方法 // 这里是该 Token-Session 首次创建时才会被执行的方法
@ -1333,7 +1333,7 @@ public class StpLogic {
// 2如果前端根本没有提供 Token 则直接返回 null // 2如果前端根本没有提供 Token 则直接返回 null
String tokenValue = getTokenValue(); String tokenValue = getTokenValue();
if(SaFoxUtil.isEmpty(tokenValue)) { if(SaFoxUtil.isEmpty(tokenValue)) {
return null; throw new SaTokenException("Token-Session 获取失败token 为空").setCode(SaErrorCode.CODE_11073);
} }
// 3代码至此tokenSessionCheckLogin 校验通过 Token 有值 // 3代码至此tokenSessionCheckLogin 校验通过 Token 有值