菜单鉴权,网页下拉不鉴权

This commit is contained in:
sxu 2024-09-29 10:26:40 +08:00
parent 15c1a7e89a
commit ec2e96236b
2 changed files with 33 additions and 2 deletions

View File

@ -57,6 +57,11 @@ public class SysDic extends BaseEntity {
*/ */
private String level; private String level;
/**
* o/null: 默认,需要鉴权, 1: 跳过鉴权
*/
private Integer skipPermission;
/** /**
* 状态 * 状态
*/ */
@ -159,6 +164,14 @@ public class SysDic extends BaseEntity {
return creator; return creator;
} }
public Integer getSkipPermission() {
return skipPermission;
}
public void setSkipPermission(Integer skipPermission) {
this.skipPermission = skipPermission;
}
@Override @Override
public String toString() { public String toString() {
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)

View File

@ -2,6 +2,10 @@ package com.bonus.sgzb.common.security.aspect;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson2.JSON;
import com.bonus.sgzb.common.security.auth.AuthUtil; import com.bonus.sgzb.common.security.auth.AuthUtil;
import com.bonus.sgzb.common.security.annotation.RequiresRoles; import com.bonus.sgzb.common.security.annotation.RequiresRoles;
import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.ProceedingJoinPoint;
@ -54,9 +58,23 @@ public class PreAuthorizeAspect
@Around("pointcut()") @Around("pointcut()")
public Object around(ProceedingJoinPoint joinPoint) throws Throwable public Object around(ProceedingJoinPoint joinPoint) throws Throwable
{ {
//获取请求参数
Object[] args = joinPoint.getArgs();
String argStr = JSON.toJSONString(args);
JSONArray jsonArray = JSONUtil.parseArray(argStr);
boolean needPermission = true;
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
if ("1".equals(jsonObject.getStr("skipPermission"))) {
needPermission = false;
}
}
// 注解鉴权 // 注解鉴权
MethodSignature signature = (MethodSignature) joinPoint.getSignature(); if (needPermission) {
checkMethodAnnotation(signature.getMethod()); MethodSignature signature = (MethodSignature) joinPoint.getSignature();
checkMethodAnnotation(signature.getMethod());
}
try try
{ {
// 执行原有逻辑 // 执行原有逻辑