mirror of
https://gitee.com/dromara/sa-token.git
synced 2025-06-28 04:35:16 +08:00
Pre Merge pull request !337 from 浮梁卖茶人/dev
This commit is contained in:
commit
7ccbc29cdc
@ -18,6 +18,8 @@ package cn.dev33.satoken.dao.timedcache;
|
||||
|
||||
import cn.dev33.satoken.SaManager;
|
||||
import cn.dev33.satoken.dao.SaTokenDao;
|
||||
import cn.dev33.satoken.listener.SaTokenEventCenter;
|
||||
import cn.dev33.satoken.util.SaFoxUtil;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@ -100,6 +102,18 @@ public class SaTimedCache {
|
||||
if(expirationTime != null && expirationTime != SaTokenDao.NEVER_EXPIRE && expirationTime < System.currentTimeMillis()) {
|
||||
dataMap.remove(key);
|
||||
expireMap.remove(key);
|
||||
|
||||
// 如果这个 key 是 token 才处理
|
||||
String tokenSegment = "token:";
|
||||
if (SaFoxUtil.isNotEmpty(key)) {
|
||||
int index = key.lastIndexOf(tokenSegment);
|
||||
if (index != -1) {
|
||||
// 截取 token 部分
|
||||
String token = key.substring(index + tokenSegment.length());
|
||||
// $$ 发布事件:token 失效
|
||||
SaTokenEventCenter.doTokenExpire(token);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -277,6 +277,17 @@ public class SaTokenEventCenter {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 事件发布:该 Token 失效(仅支持默认持久层)
|
||||
*
|
||||
* @param tokenValue token 值
|
||||
*/
|
||||
public static void doTokenExpire(String tokenValue) {
|
||||
for (SaTokenListener listener : listenerList) {
|
||||
listener.doTokenExpire(tokenValue);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 事件发布:有新的全局组件载入到框架中
|
||||
* @param compName 组件名称
|
||||
|
@ -119,6 +119,13 @@ public interface SaTokenListener {
|
||||
*/
|
||||
void doRenewTimeout(String tokenValue, Object loginId, long timeout);
|
||||
|
||||
/**
|
||||
* 每次 Token 失效时触发(仅支持默认持久层)
|
||||
*
|
||||
* @param tokenValue token 值
|
||||
*/
|
||||
void doTokenExpire(String tokenValue);
|
||||
|
||||
/**
|
||||
* 全局组件载入
|
||||
* @param compName 组件名称
|
||||
|
@ -119,6 +119,14 @@ public class SaTokenListenerForLog implements SaTokenListener {
|
||||
log.info("token 续期成功, {} 秒后到期, 帐号={}, token值={} ", timeout, loginId, tokenValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* 每次 Token 失效时触发(仅支持默认持久层)
|
||||
*/
|
||||
@Override
|
||||
public void doTokenExpire(String tokenValue) {
|
||||
log.info("token 失效, token值={} ", tokenValue);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 全局组件载入
|
||||
|
@ -82,5 +82,9 @@ public class SaTokenListenerForSimple implements SaTokenListener {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void doTokenExpire(String tokenValue) {
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user