新增 revokeClientToken、revokeClientTokenByIndex: Client-Token 回收函数

This commit is contained in:
click33 2024-08-24 18:55:48 +08:00
parent a1560ce0a7
commit d3b337a6a6
3 changed files with 69 additions and 2 deletions

View File

@ -236,6 +236,15 @@ public interface SaOAuth2Dao {
getSaTokenDao().delete(splicingClientTokenIndexKey(clientId)); getSaTokenDao().delete(splicingClientTokenIndexKey(clientId));
} }
/**
* 删除Past-Token
* @param pastToken
*/
default void deletePastToken(String pastToken) {
// 其实就是删除 ClientToken
deleteClientToken(pastToken);
}
/** /**
* 删除Past-Token索引 * 删除Past-Token索引
* @param clientId 应用id * @param clientId 应用id

View File

@ -374,6 +374,47 @@ public class SaOAuth2Template {
} }
/**
* 回收指定的 ClientToken
*
* @param clientToken /
*/
public void revokeClientToken(String clientToken) {
SaOAuth2Dao dao = SaOAuth2Manager.getDao();
ClientTokenModel ctModel = dao.getClientToken(clientToken);
if(ctModel == null) {
return;
}
// ct索引
dao.deleteClientToken(clientToken);
dao.deleteClientTokenIndex(ctModel.clientId);
}
/**
* 回收指定的 ClientToken根据索引 clientId
*
* @param clientId /
*/
public void revokeClientTokenByIndex(String clientId) {
SaOAuth2Dao dao = SaOAuth2Manager.getDao();
// clientToken
String clientToken = dao.getClientTokenValue(clientId);
if(clientToken != null) {
dao.deleteClientToken(clientToken);
dao.deleteClientTokenIndex(clientId);
}
// pastToken
String pastToken = dao.getPastTokenValue(clientId);
if(pastToken != null) {
dao.deletePastToken(pastToken);
dao.deletePastTokenIndex(clientId);
}
}
// ------------------- 包装其它 bean 的方法 // ------------------- 包装其它 bean 的方法

View File

@ -21,7 +21,6 @@ import cn.dev33.satoken.oauth2.data.model.ClientTokenModel;
import cn.dev33.satoken.oauth2.data.model.CodeModel; import cn.dev33.satoken.oauth2.data.model.CodeModel;
import cn.dev33.satoken.oauth2.data.model.RefreshTokenModel; import cn.dev33.satoken.oauth2.data.model.RefreshTokenModel;
import cn.dev33.satoken.oauth2.data.model.loader.SaClientModel; import cn.dev33.satoken.oauth2.data.model.loader.SaClientModel;
import cn.dev33.satoken.oauth2.processor.SaOAuth2ServerProcessor;
import java.util.List; import java.util.List;
@ -175,7 +174,25 @@ public class SaOAuth2Util {
public static AccessTokenModel checkAccessTokenParam(String clientId, String clientSecret, String accessToken) { public static AccessTokenModel checkAccessTokenParam(String clientId, String clientSecret, String accessToken) {
return SaOAuth2Manager.getTemplate().checkAccessTokenParam(clientId, clientSecret, accessToken); return SaOAuth2Manager.getTemplate().checkAccessTokenParam(clientId, clientSecret, accessToken);
} }
/**
* 回收指定的 ClientToken
*
* @param clientToken /
*/
public static void revokeClientToken(String clientToken) {
SaOAuth2Manager.getTemplate().revokeClientToken(clientToken);
}
/**
* 回收指定的 ClientToken根据索引clientId
*
* @param clientId /
*/
public static void revokeClientTokenByIndex(String clientId) {
SaOAuth2Manager.getTemplate().revokeClientTokenByIndex(clientId);
}
// ------------------- save 数据 // ------------------- save 数据
/** /**