feat: 支持重写获取高级权限与低级权限的方法

- 将获取高级权限以及低级权限的方法放到SaOAuth2DataLoader中, 可以自定义权限数据的加载来源
This commit is contained in:
xiumu 2025-06-02 17:20:31 +08:00
parent 2cf18309b2
commit 986111b10c
2 changed files with 21 additions and 4 deletions

View File

@ -21,6 +21,8 @@ import cn.dev33.satoken.oauth2.error.SaOAuth2ErrorCode;
import cn.dev33.satoken.oauth2.exception.SaOAuth2ClientModelException;
import cn.dev33.satoken.secure.SaSecureUtil;
import java.util.List;
/**
* Sa-Token OAuth2 数据加载器
*
@ -78,4 +80,21 @@ public interface SaOAuth2DataLoader {
return SaSecureUtil.md5(SaOAuth2Manager.getServerConfig().getUnionidDigestPrefix() + "_" + subjectId + "_" + loginId);
}
/**
* 获取高级权限列表
* @return /
*/
default List<String> getHigherScopeList() {
String higherScope = SaOAuth2Manager.getServerConfig().getHigherScope();
return SaOAuth2Manager.getDataConverter().convertScopeStringToList(higherScope);
}
/**
* 获取低级权限列表
* @return /
*/
default List<String> getLowerScopeList() {
String lowerScope = SaOAuth2Manager.getServerConfig().getLowerScope();
return SaOAuth2Manager.getDataConverter().convertScopeStringToList(lowerScope);
}
}

View File

@ -765,8 +765,7 @@ public class SaOAuth2Template {
* @return /
*/
public List<String> getHigherScopeList() {
String higherScope = SaOAuth2Manager.getServerConfig().getHigherScope();
return SaOAuth2Manager.getDataConverter().convertScopeStringToList(higherScope);
return SaOAuth2Manager.getDataLoader().getHigherScopeList();
}
/**
@ -774,8 +773,7 @@ public class SaOAuth2Template {
* @return /
*/
public List<String> getLowerScopeList() {
String lowerScope = SaOAuth2Manager.getServerConfig().getLowerScope();
return SaOAuth2Manager.getDataConverter().convertScopeStringToList(lowerScope);
return SaOAuth2Manager.getDataLoader().getLowerScopeList();
}
}