稍微简化一下cn.dev33.satoken.action.SaTokenActionDefaultImpl.checkMethodAnnotation的验证逻辑

This commit is contained in:
xy 2021-05-24 11:24:22 +08:00
parent 737aeb5fb0
commit 953ba965aa

View File

@ -1,5 +1,6 @@
package cn.dev33.satoken.action;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Method;
import java.util.List;
import java.util.UUID;
@ -89,44 +90,29 @@ public class SaTokenActionDefaultImpl implements SaTokenAction {
// 获取这个 Method 所属的 Class
Class<?> clazz = method.getDeclaringClass();
// Class 校验 @SaCheckLogin 注解
if(clazz.isAnnotationPresent(SaCheckLogin.class)) {
SaCheckLogin at = clazz.getAnnotation(SaCheckLogin.class);
validateAnnotation(clazz);
validateAnnotation(method);
}
private void validateAnnotation(AnnotatedElement target) {
// 校验 @SaCheckLogin 注解
if(target.isAnnotationPresent(SaCheckLogin.class)) {
SaCheckLogin at = target.getAnnotation(SaCheckLogin.class);
SaManager.getStpLogic(at.key()).checkByAnnotation(at);
}
// Class 校验 @SaCheckRole 注解
if(clazz.isAnnotationPresent(SaCheckRole.class)) {
SaCheckRole at = clazz.getAnnotation(SaCheckRole.class);
// 校验 @SaCheckRole 注解
if(target.isAnnotationPresent(SaCheckRole.class)) {
SaCheckRole at = target.getAnnotation(SaCheckRole.class);
SaManager.getStpLogic(at.key()).checkByAnnotation(at);
}
// Class 校验 @SaCheckPermission 注解
if(clazz.isAnnotationPresent(SaCheckPermission.class)) {
SaCheckPermission at = clazz.getAnnotation(SaCheckPermission.class);
// 校验 @SaCheckPermission 注解
if(target.isAnnotationPresent(SaCheckPermission.class)) {
SaCheckPermission at = target.getAnnotation(SaCheckPermission.class);
SaManager.getStpLogic(at.key()).checkByAnnotation(at);
}
// Method 校验 @SaCheckLogin 注解
if(method.isAnnotationPresent(SaCheckLogin.class)) {
SaCheckLogin at = method.getAnnotation(SaCheckLogin.class);
SaManager.getStpLogic(at.key()).checkByAnnotation(at);
}
// Method 校验 @SaCheckRole 注解
if(method.isAnnotationPresent(SaCheckRole.class)) {
SaCheckRole at = method.getAnnotation(SaCheckRole.class);
SaManager.getStpLogic(at.key()).checkByAnnotation(at);
}
// Method 校验 @SaCheckPermission 注解
if(method.isAnnotationPresent(SaCheckPermission.class)) {
SaCheckPermission at = method.getAnnotation(SaCheckPermission.class);
SaManager.getStpLogic(at.key()).checkByAnnotation(at);
}
}
}