新增 SaOAuth2Util.checkClientTokenScope(clientToken, scopes) 方法,校验 Client-Token 是否含有指定 Scope

This commit is contained in:
click33 2022-08-08 17:31:13 +08:00
parent cd909f4137
commit 386295dc6b
2 changed files with 25 additions and 1 deletions

View File

@ -98,6 +98,21 @@ public class SaOAuth2Template {
SaOAuth2Exception.throwBy(scopeList.contains(scope) == false, "该 Access-Token 不具备 Scope" + scope);
}
}
/**
* 校验指定 Client-Token 是否具有指定 Scope
* @param clientToken Client-Token
* @param scopes 需要校验的权限列表
*/
public void checkClientTokenScope(String clientToken, String... scopes) {
if(scopes == null || scopes.length == 0) {
return;
}
ClientTokenModel ct = checkClientToken(clientToken);
List<String> scopeList = SaFoxUtil.convertStringToList(ct.scope);
for (String scope : scopes) {
SaOAuth2Exception.throwBy(scopeList.contains(scope) == false, "该 Client-Token 不具备 Scope" + scope);
}
}
// ------------------- generate 构建数据
/**

View File

@ -49,7 +49,7 @@ public class SaOAuth2Util {
public static ClientTokenModel checkClientToken(String clientToken) {
return saOAuth2Template.checkClientToken(clientToken);
}
/**
* 获取 Access-Token 所代表的LoginId
* @param accessToken Access-Token
@ -68,6 +68,15 @@ public class SaOAuth2Util {
saOAuth2Template.checkScope(accessToken, scopes);
}
/**
* 校验指定 Client-Token 是否具有指定 Scope
* @param clientToken Client-Token
* @param scopes 需要校验的权限列表
*/
public static void checkClientTokenScope(String clientToken, String... scopes) {
saOAuth2Template.checkClientTokenScope(clientToken, scopes);
}
// ------------------- generate 构建数据
/**