commit
This commit is contained in:
@@ -15,6 +15,10 @@ import java.lang.reflect.Method;
|
||||
public class SaCheckLoginInterceptor implements MethodInterceptor {
|
||||
@Override
|
||||
public void filter(InterceptorChain chain) throws Throwable {
|
||||
if (SaTokenAuthIgnoreUtil.isIgnore()) {
|
||||
chain.doChain();
|
||||
return;
|
||||
}
|
||||
Method method = chain.getCallingMethod();
|
||||
SaCheckLogin at = method.getAnnotation(SaCheckLogin.class);
|
||||
SaManager.getStpLogic(at.type()).checkByAnnotation(at);
|
||||
|
||||
+4
@@ -15,6 +15,10 @@ import java.lang.reflect.Method;
|
||||
public class SaCheckPermissionInterceptor implements MethodInterceptor {
|
||||
@Override
|
||||
public void filter(InterceptorChain chain) throws Throwable {
|
||||
if (SaTokenAuthIgnoreUtil.isIgnore()) {
|
||||
chain.doChain();
|
||||
return;
|
||||
}
|
||||
Method method = chain.getCallingMethod();
|
||||
SaCheckPermission at = method.getAnnotation(SaCheckPermission.class);
|
||||
SaManager.getStpLogic(at.type()).checkByAnnotation(at);
|
||||
|
||||
@@ -15,6 +15,10 @@ import java.lang.reflect.Method;
|
||||
public class SaCheckRoleInterceptor implements MethodInterceptor {
|
||||
@Override
|
||||
public void filter(InterceptorChain chain) throws Throwable {
|
||||
if (SaTokenAuthIgnoreUtil.isIgnore()) {
|
||||
chain.doChain();
|
||||
return;
|
||||
}
|
||||
Method method = chain.getCallingMethod();
|
||||
SaCheckRole at = method.getAnnotation(SaCheckRole.class);
|
||||
SaManager.getStpLogic(at.type()).checkByAnnotation(at);
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.budwk.app.web.commons.auth.satoken.aop;
|
||||
|
||||
import com.budwk.app.web.commons.base.Globals;
|
||||
import org.nutz.lang.Lang;
|
||||
import org.nutz.lang.Strings;
|
||||
import org.nutz.mvc.Mvcs;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Arrays;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Sa-Token 注解认证白名单工具。
|
||||
* <p>
|
||||
* 用于集中维护不需要登录、权限、角色校验即可访问的 URL,匹配规则与旧 Shiro 体系中的
|
||||
* authIgnoreUrlArr 保持一致:数组中的每一项都按正则表达式与当前请求 URI 完整匹配。
|
||||
*/
|
||||
public class SaTokenAuthIgnoreUtil {
|
||||
|
||||
/**
|
||||
* 不需要认证授权的 URL。
|
||||
* <p>
|
||||
* 参数说明:数组中的字符串为请求 URI 正则表达式,匹配的是去除项目 contextPath 后的路径。
|
||||
* 返回值说明:通过 {@link #isIgnore()} 返回 boolean,true 表示当前请求跳过 Sa-Token 注解校验。
|
||||
*/
|
||||
private static final String[] AUTH_IGNORE_URL_ARR = Lang.array("/",
|
||||
"/platform/activity/basic/scope/getScopeUser",
|
||||
"/platform/fitnessWalk/stepManage/getActivityDateStep",
|
||||
"/platform/fitnessWalk/stepManage/winningRecord",
|
||||
"/platform/fitnessWalk/stepManage/updateStepMonth",
|
||||
"/platform/fitnessWalk/stepRanking/getUserStepRanking",
|
||||
"/platform/fitnessWalk/stepManage/getActivityQualifyProgressBar",
|
||||
"/platform/fitnessWalk/stepWining/getUserStepWining",
|
||||
"/platform/fitnessWalk/common/getIssueById",
|
||||
"/platform/fitnessWalk/common/saveAnswer",
|
||||
"/platform/fitnessWalk/stepWining/prizeOption",
|
||||
"/platform/fitnessWalk/stepWining/prizeUsers",
|
||||
"/platform/fitnessWalk/punchLottery/judgeWinningToPunch",
|
||||
"/platform/fitnessWalk/punchLottery/getLotteryRecord",
|
||||
"/platform/fitnessWalk/punchLottery/doExchange",
|
||||
"/platform/fitnessWalk/punchLottery/getPunchWining",
|
||||
"/platform/fitnessWalk/punchLottery/doReadLottery",
|
||||
"/platform/fitnessWalk/activityRelation/isCurrentUserRelationActivityQualified",
|
||||
"/platform/fitnessWalk/welfare/addWelfareList",
|
||||
"/platform/fitnessWalk/weapp/.*");
|
||||
|
||||
/**
|
||||
* 判断当前请求是否命中匿名访问白名单。
|
||||
*
|
||||
* @return boolean true 表示当前 URL 不需要执行登录、权限、角色注解校验;false 表示继续走原有 Sa-Token 校验逻辑
|
||||
*/
|
||||
public static boolean isIgnore() {
|
||||
HttpServletRequest request = Mvcs.getReq();
|
||||
if (request == null) {
|
||||
return false;
|
||||
}
|
||||
String requestURI = Strings.sNull(request.getRequestURI()).replaceFirst("^" + Pattern.quote(Strings.sNull(Globals.AppBase)), "");
|
||||
return Arrays.stream(AUTH_IGNORE_URL_ARR).anyMatch(v -> Pattern.compile(v).matcher(requestURI).matches());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user