Skip to content

Commit

Permalink
未登录时调用鉴权 API 抛出未登录异常而不再是无权限异常。
Browse files Browse the repository at this point in the history
  • Loading branch information
click33 committed Oct 17, 2023
1 parent 954efeb commit e918f61
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions sa-token-core/src/main/java/cn/dev33/satoken/stp/StpLogic.java
Original file line number Diff line number Diff line change
Expand Up @@ -1175,6 +1175,11 @@ public void deleteTokenToIdMapping(String tokenValue) {
*/
public SaSession getSessionBySessionId(String sessionId, boolean isCreate, Consumer<SaSession> appendOperation) {

// 如果提供的 sessionId 为 null,则直接返回 null
if(SaFoxUtil.isEmpty(sessionId)) {
return null;
}

// 先检查这个 SaSession 是否已经存在,如果不存在且 isCreate=true,则新建并返回
SaSession session = getSaTokenDao().getSession(sessionId);

Expand Down Expand Up @@ -1725,11 +1730,7 @@ public void renewTimeout(String tokenValue, long timeout) {
* @return /
*/
public List<String> getRoleList() {
try {
return getRoleList(getLoginId());
} catch (NotLoginException e) {
return SaFoxUtil.emptyList();
}
return getRoleList(getLoginId());
}

/**
Expand Down Expand Up @@ -1773,7 +1774,7 @@ public boolean hasRoleAnd(String... roleArray){
try {
checkRoleAnd(roleArray);
return true;
} catch (NotLoginException | NotRoleException e) {
} catch (NotRoleException e) {
return false;
}
}
Expand All @@ -1788,7 +1789,7 @@ public boolean hasRoleOr(String... roleArray){
try {
checkRoleOr(roleArray);
return true;
} catch (NotLoginException | NotRoleException e) {
} catch (NotRoleException e) {
return false;
}
}
Expand Down Expand Up @@ -1863,11 +1864,7 @@ public void checkRoleOr(String... roleArray){
* @return /
*/
public List<String> getPermissionList() {
try {
return getPermissionList(getLoginId());
} catch (NotLoginException e) {
return SaFoxUtil.emptyList();
}
return getPermissionList(getLoginId());
}

/**
Expand Down Expand Up @@ -1911,7 +1908,7 @@ public boolean hasPermissionAnd(String... permissionArray){
try {
checkPermissionAnd(permissionArray);
return true;
} catch (NotLoginException | NotPermissionException e) {
} catch (NotPermissionException e) {
return false;
}
}
Expand All @@ -1926,7 +1923,7 @@ public boolean hasPermissionOr(String... permissionArray){
try {
checkPermissionOr(permissionArray);
return true;
} catch (NotLoginException | NotPermissionException e) {
} catch (NotPermissionException e) {
return false;
}
}
Expand Down

0 comments on commit e918f61

Please sign in to comment.