mirror of
https://gitee.com/dromara/sa-token.git
synced 2025-10-22 03:27:23 +08:00
feat: 支持自定义 autoRenew 逻辑
This commit is contained in:
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2020-2099 sa-token.cc
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package cn.dev33.satoken.fun.strategy;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.stp.StpLogic;
|
||||||
|
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 函数式接口:自定义自动续期条件
|
||||||
|
*
|
||||||
|
* <p> 参数:StpLogic 实例 </p>
|
||||||
|
* <p> 返回:Boolean 是否续期 </p>
|
||||||
|
*
|
||||||
|
* @author fangzhengjin
|
||||||
|
* @since 1.41.0
|
||||||
|
*/
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface SaAutoRenewFunction extends Function<StpLogic, Boolean> {
|
||||||
|
}
|
@@ -998,7 +998,7 @@ public class StpLogic {
|
|||||||
// ------ 至此,loginId 已经是一个合法的值,代表当前会话是一个正常的登录状态了
|
// ------ 至此,loginId 已经是一个合法的值,代表当前会话是一个正常的登录状态了
|
||||||
|
|
||||||
// 7.2、如果配置了自动续签功能, 则: 更新这个 token 的最后活跃时间 (注意此处的续签是在续 active-timeout,而非 timeout)
|
// 7.2、如果配置了自动续签功能, 则: 更新这个 token 的最后活跃时间 (注意此处的续签是在续 active-timeout,而非 timeout)
|
||||||
if(getConfigOrGlobal().getAutoRenew()) {
|
if(SaStrategy.instance.autoRenew.apply(this)) {
|
||||||
updateLastActiveToNow(tokenValue);
|
updateLastActiveToNow(tokenValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -156,6 +156,13 @@ public final class SaStrategy {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否自动续期
|
||||||
|
*/
|
||||||
|
public SaAutoRenewFunction autoRenew = (stpLogic) -> {
|
||||||
|
return stpLogic.getConfigOrGlobal().getAutoRenew();
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建 StpLogic 的算法
|
* 创建 StpLogic 的算法
|
||||||
*/
|
*/
|
||||||
@@ -221,6 +228,17 @@ public final class SaStrategy {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否自动续期
|
||||||
|
*
|
||||||
|
* @param autoRenew /
|
||||||
|
* @return /
|
||||||
|
*/
|
||||||
|
public SaStrategy setAutoRenew(SaAutoRenewFunction autoRenew) {
|
||||||
|
this.autoRenew = autoRenew;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -65,6 +65,15 @@ public BiFunction<AnnotatedElement, Class<? extends Annotation> , Annotation> ge
|
|||||||
public BiFunction<String, String, String> spliceTwoUrl = (url1, url2) -> {
|
public BiFunction<String, String, String> spliceTwoUrl = (url1, url2) -> {
|
||||||
return xxx;
|
return xxx;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否自动续期,每次续期前都会执行,可以加入动态判断逻辑
|
||||||
|
* <p> 参数 当前 stpLogic 实例对象
|
||||||
|
* <p> 返回 true 自动续期 false 不自动续期
|
||||||
|
*/
|
||||||
|
public Function<StpLogic, Boolean> autoRenew = (stpLogic) -> {
|
||||||
|
return stpLogic.getConfigOrGlobal().getAutoRenew();
|
||||||
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user