|
@@ -1,8 +1,15 @@
|
|
-package com.winhc.repal.config;
|
|
|
|
|
|
+package com.winhc.repal.aspect;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
+import com.winhc.common.enums.CodeMsg;
|
|
|
|
+import com.winhc.common.exception.CommonException;
|
|
|
|
+import com.winhc.repal.annotation.RolePermission;
|
|
|
|
+import com.winhc.repal.constant.Constant;
|
|
|
|
+import com.winhc.repal.service.RepalRolePermissionService;
|
|
|
|
+import com.winhc.repal.util.RedisUtil;
|
|
|
|
+import com.winhc.repal.util.UserContextUtil;
|
|
import org.aspectj.lang.ProceedingJoinPoint;
|
|
import org.aspectj.lang.ProceedingJoinPoint;
|
|
import org.aspectj.lang.Signature;
|
|
import org.aspectj.lang.Signature;
|
|
import org.aspectj.lang.annotation.Around;
|
|
import org.aspectj.lang.annotation.Around;
|
|
@@ -11,6 +18,8 @@ import org.aspectj.lang.annotation.Pointcut;
|
|
import org.aspectj.lang.reflect.MethodSignature;
|
|
import org.aspectj.lang.reflect.MethodSignature;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.core.annotation.Order;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
@@ -23,12 +32,19 @@ import java.lang.reflect.Method;
|
|
*/
|
|
*/
|
|
@Aspect
|
|
@Aspect
|
|
@Component
|
|
@Component
|
|
|
|
+@Order(Integer.MIN_VALUE)
|
|
public class ControllerAspect {
|
|
public class ControllerAspect {
|
|
|
|
|
|
private static final long TIME_OUT = 800L;
|
|
private static final long TIME_OUT = 800L;
|
|
|
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(ControllerAspect.class);
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(ControllerAspect.class);
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private RedisUtil redisUtil;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private RepalRolePermissionService repalRolePermissionService;
|
|
|
|
+
|
|
@Pointcut("execution(* com.winhc.repal.controller.*Controller.*(..))")
|
|
@Pointcut("execution(* com.winhc.repal.controller.*Controller.*(..))")
|
|
public void validAspect() {
|
|
public void validAspect() {
|
|
|
|
|
|
@@ -72,6 +88,21 @@ public class ControllerAspect {
|
|
mappingRoute.append(((DeleteMapping) a).value().length > 0 ? ((DeleteMapping) a).value()[0] : ((DeleteMapping) a).path()[0]);
|
|
mappingRoute.append(((DeleteMapping) a).value().length > 0 ? ((DeleteMapping) a).value()[0] : ((DeleteMapping) a).path()[0]);
|
|
methodName = "DELETE";
|
|
methodName = "DELETE";
|
|
}
|
|
}
|
|
|
|
+ if (a instanceof RolePermission) {
|
|
|
|
+ // 获取注解的值
|
|
|
|
+ String userKey = Constant.USER_PERMISSION_KEY + UserContextUtil.getUser().getUserId();
|
|
|
|
+ if (redisUtil.hasKey(userKey)) {
|
|
|
|
+ if (!redisUtil.sIsMember(userKey, ((RolePermission)a).permission())) {
|
|
|
|
+ LOGGER.error("user permission error, ======>>>>>>userId:[{}], ======>>>>>>permissionCode:[{}]", UserContextUtil.getUser().getUserId(), ((RolePermission)a).permission());
|
|
|
|
+ throw new CommonException(CodeMsg.FAILED, "没有相关权限");
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ if (!repalRolePermissionService.checkUserPermission(UserContextUtil.getUser().getUserId(), ((RolePermission)a).permission())) {
|
|
|
|
+ LOGGER.error("user permission error, ======>>>>>>userId:[{}], ======>>>>>>permissionCode:[{}]", UserContextUtil.getUser().getUserId(), ((RolePermission)a).permission());
|
|
|
|
+ throw new CommonException(CodeMsg.FAILED, "没有相关权限");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
String requestInfo = "======>>>>>>requestInfo:" + mappingRoute + ",method:[" + methodName + "]" + "(" + StrUtil.repeatAndJoin("{}", params.length, ",") + ")";
|
|
String requestInfo = "======>>>>>>requestInfo:" + mappingRoute + ",method:[" + methodName + "]" + "(" + StrUtil.repeatAndJoin("{}", params.length, ",") + ")";
|
|
LOGGER.info(requestInfo, params);
|
|
LOGGER.info(requestInfo, params);
|