重构SSO模块,抽离三种模式的统一认证中心

This commit is contained in:
click33
2021-10-09 05:43:31 +08:00
parent 643118177a
commit d491f4083f
85 changed files with 727 additions and 1364 deletions

View File

@@ -10,13 +10,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import com.pj.util.AjaxJson;
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.basic.SaBasicUtil;
import cn.dev33.satoken.context.SaHolder;
import cn.dev33.satoken.filter.SaServletFilter;
import cn.dev33.satoken.interceptor.SaAnnotationInterceptor;
@@ -86,27 +80,8 @@ public class SaTokenConfigure implements WebMvcConfigurer {
@PostConstruct
public void rewriteSaStrategy() {
// 重写Sa-Token的注解处理器增加注解合并功能
SaStrategy.me.setCheckElementAnnotation(element -> {
if(AnnotatedElementUtils.isAnnotated(element, SaCheckLogin.class)) {
SaCheckLogin at = AnnotatedElementUtils.getMergedAnnotation(element, SaCheckLogin.class);
SaManager.getStpLogic(at.type()).checkByAnnotation(at);
}
if(AnnotatedElementUtils.isAnnotated(element, SaCheckRole.class)) {
SaCheckRole at = AnnotatedElementUtils.getMergedAnnotation(element, SaCheckRole.class);
SaManager.getStpLogic(at.type()).checkByAnnotation(at);
}
if(AnnotatedElementUtils.isAnnotated(element, SaCheckPermission.class)) {
SaCheckPermission at = AnnotatedElementUtils.getMergedAnnotation(element, SaCheckPermission.class);
SaManager.getStpLogic(at.type()).checkByAnnotation(at);
}
if(AnnotatedElementUtils.isAnnotated(element, SaCheckSafe.class)) {
SaCheckSafe at = AnnotatedElementUtils.getMergedAnnotation(element, SaCheckSafe.class);
SaManager.getStpLogic(null).checkByAnnotation(at);
}
if(AnnotatedElementUtils.isAnnotated(element, SaCheckBasic.class)) {
SaCheckBasic at = AnnotatedElementUtils.getMergedAnnotation(element, SaCheckBasic.class);
SaBasicUtil.check(at.realm(), at.account());
}
SaStrategy.me.setGetAnnotation((element, annotationClass) -> {
return AnnotatedElementUtils.getMergedAnnotation(element, SaCheckLogin.class);
});
}

View File

@@ -2,6 +2,8 @@ package com.pj.satoken.at;
import java.util.List;
import org.springframework.stereotype.Component;
import cn.dev33.satoken.SaManager;
import cn.dev33.satoken.fun.SaFunction;
import cn.dev33.satoken.session.SaSession;
@@ -14,6 +16,7 @@ import cn.dev33.satoken.stp.StpUtil;
* Sa-Token 权限认证工具类
* @author kong
*/
@Component
public class StpUserUtil {
/**