mirror of
https://gitee.com/dromara/sa-token.git
synced 2026-02-27 16:50:24 +08:00
新增账户可用性注解及鉴权代码
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
package cn.dev33.satoken.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 校验当前用户是否可用
|
||||
*
|
||||
* <p> 可标注在函数、类上(效果等同于标注在此类的所有方法上)
|
||||
*
|
||||
* @author videomonster
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ ElementType.METHOD, ElementType.TYPE })
|
||||
public @interface SaCheckEnable {
|
||||
|
||||
/**
|
||||
* 多账号体系下所属的账号体系标识
|
||||
* @return see note
|
||||
*/
|
||||
String type() default "";
|
||||
}
|
||||
@@ -21,4 +21,9 @@ public @interface SaCheckLogin {
|
||||
*/
|
||||
String type() default "";
|
||||
|
||||
/**
|
||||
* 是否检查当前登陆账号是否禁用 (true: 检查 false: 不检查)
|
||||
* @return see note
|
||||
*/
|
||||
String checkEnable() default "false";
|
||||
}
|
||||
|
||||
@@ -6,11 +6,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import cn.dev33.satoken.SaManager;
|
||||
import cn.dev33.satoken.annotation.SaCheckLogin;
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.dev33.satoken.annotation.SaCheckRole;
|
||||
import cn.dev33.satoken.annotation.SaCheckSafe;
|
||||
import cn.dev33.satoken.annotation.SaMode;
|
||||
import cn.dev33.satoken.annotation.*;
|
||||
import cn.dev33.satoken.config.SaCookieConfig;
|
||||
import cn.dev33.satoken.config.SaTokenConfig;
|
||||
import cn.dev33.satoken.context.SaHolder;
|
||||
@@ -1606,6 +1602,10 @@ public class StpLogic {
|
||||
*/
|
||||
public void checkByAnnotation(SaCheckLogin at) {
|
||||
this.checkLogin();
|
||||
Object loginId = getLoginId();
|
||||
if ("true".equalsIgnoreCase(at.checkEnable().trim()) && isDisable(loginId)) {
|
||||
throw new DisableLoginException(getLoginType(), loginId, getDisableTime(loginId));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1656,6 +1656,14 @@ public class StpLogic {
|
||||
this.checkSafe();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据注解(@SaCheckEnable)鉴权
|
||||
*
|
||||
* @param at 注解对象
|
||||
*/
|
||||
public void checkByAnnotation(SaCheckEnable at) {
|
||||
this.isDisable(getLoginId());
|
||||
}
|
||||
|
||||
// ------------------- 账号封禁 -------------------
|
||||
|
||||
|
||||
@@ -10,12 +10,7 @@ import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
import cn.dev33.satoken.SaManager;
|
||||
import cn.dev33.satoken.annotation.SaCheckBasic;
|
||||
import cn.dev33.satoken.annotation.SaCheckLogin;
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.dev33.satoken.annotation.SaCheckRole;
|
||||
import cn.dev33.satoken.annotation.SaCheckSafe;
|
||||
import cn.dev33.satoken.annotation.SaIgnore;
|
||||
import cn.dev33.satoken.annotation.*;
|
||||
import cn.dev33.satoken.basic.SaBasicUtil;
|
||||
import cn.dev33.satoken.session.SaSession;
|
||||
import cn.dev33.satoken.util.SaFoxUtil;
|
||||
@@ -168,7 +163,12 @@ public final class SaStrategy {
|
||||
if(checkBasic != null) {
|
||||
SaBasicUtil.check(checkBasic.realm(), checkBasic.account());
|
||||
}
|
||||
|
||||
|
||||
// 校验 @SaCheckEable 注解
|
||||
SaCheckEnable checkEable = (SaCheckEnable) SaStrategy.me.getAnnotation.apply(target, SaCheckEnable.class);
|
||||
if(checkEable != null) {
|
||||
SaManager.getStpLogic(checkEable.type()).checkByAnnotation(checkEable);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user