From 730443b70de88d328ffa275f51f69280fda979e4 Mon Sep 17 00:00:00 2001 From: XiaoRuby <3114200645@qq.com> Date: 星期三, 30 八月 2023 12:59:50 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- sys/src/main/java/com/yuanchu/limslaboratory/aop/AuthRequestAspect.java | 99 ++++++++++++++++++++++++++----------------------- 1 files changed, 52 insertions(+), 47 deletions(-) diff --git a/sys/src/main/java/com/yuanchu/limslaboratory/aop/AuthRequestAspect.java b/sys/src/main/java/com/yuanchu/limslaboratory/aop/AuthRequestAspect.java index fd0b5fe..3a53c0d 100644 --- a/sys/src/main/java/com/yuanchu/limslaboratory/aop/AuthRequestAspect.java +++ b/sys/src/main/java/com/yuanchu/limslaboratory/aop/AuthRequestAspect.java @@ -37,6 +37,9 @@ public void pointCut() { } + private final static String ADMIN = "f5c8bcb7d5a0fd27e2323280f7e98cad"; + + @Resource private UserService userService; @@ -47,57 +50,59 @@ @SneakyThrows @Before("pointCut()") public void before(JoinPoint joinPoint) { - Class<?> clazz = joinPoint.getTarget().getClass(); - String clazzName = joinPoint.getTarget().getClass().getName(); - // 鑾峰彇璁块棶鐨勬柟娉曞悕 - String methodName = joinPoint.getSignature().getName(); - // 鑾峰彇鏂规硶鎵�鏈夊弬鏁板強鍏剁被鍨� - Class[] argClz = ((MethodSignature) joinPoint.getSignature()).getParameterTypes(); - // 鑾峰彇璁块棶鐨勬柟娉曞璞� - Method method = clazz.getDeclaredMethod(methodName, argClz); - //鑾峰彇绫讳笂璇锋眰鍦板潃 - RequestMapping annotation = clazz.getAnnotation(RequestMapping.class); - StringBuilder builder = new StringBuilder(); - String apiInfo=null; - builder.append(annotation.value()[0]); - //鑾峰彇鏂规硶涓婃敞瑙� - if (method.isAnnotationPresent(PostMapping.class)) { - PostMapping post = method.getAnnotation(PostMapping.class); - builder.append(post.value()[0]); - } - if (method.isAnnotationPresent(GetMapping.class)) { - GetMapping get = method.getAnnotation(GetMapping.class); - builder.append(get.value()[0]); - } - if (method.isAnnotationPresent(DeleteMapping.class)) { - DeleteMapping delete = method.getAnnotation(DeleteMapping.class); - builder.append(delete.value()[0]); - } - if (method.isAnnotationPresent(PutMapping.class)) { - PutMapping put = method.getAnnotation(PutMapping.class); - builder.append(put.value()[0]); - } - if (method.isAnnotationPresent(ApiOperation.class)) { - ApiOperation api = method.getAnnotation(ApiOperation.class); - apiInfo=api.value(); - } HttpServletRequest request = ServletUtils.getRequest(); Map<String, Object> userInfo = userService.getUserInfo(request.getHeader("X-Token")); - if(Objects.nonNull(userInfo)){ - String roleId = String.valueOf(userInfo.get("roleId")); - Map<String, Object> urlType = roleService.getUrlType(builder.toString()); - log.info("鎷︽埅璇锋眰----------------銆�"+builder); - boolean b = roleService.hasUrl(String.valueOf(urlType.get("type")), String.valueOf(urlType.get("menuId")), roleId); - if(!b){ - log.warn("鐢ㄦ埛/id锛�"+userInfo.get("name")+"/"+userInfo.get("id")+"---------鏉冮檺涓嶈冻锛屽凡鎷︽埅锛�"); - //throw new AuthException("400","鏃犳潈闄�"); - } - }else { - throw new AuthException("401","鐧婚檰杩囨湡"); + if (Objects.nonNull(userInfo)) { + if (Objects.equals(userInfo.get("sessionLayerId"), ADMIN)) { + log.info("瓒呯骇绠$悊鍛橈紝鏃犻渶鎷︽埅锛�"); + return; + } + Class<?> clazz = joinPoint.getTarget().getClass(); + String clazzName = joinPoint.getTarget().getClass().getName(); + // 鑾峰彇璁块棶鐨勬柟娉曞悕 + String methodName = joinPoint.getSignature().getName(); + // 鑾峰彇鏂规硶鎵�鏈夊弬鏁板強鍏剁被鍨� + Class[] argClz = ((MethodSignature) joinPoint.getSignature()).getParameterTypes(); + // 鑾峰彇璁块棶鐨勬柟娉曞璞� + Method method = clazz.getDeclaredMethod(methodName, argClz); + //鑾峰彇绫讳笂璇锋眰鍦板潃 + RequestMapping annotation = clazz.getAnnotation(RequestMapping.class); + StringBuilder builder = new StringBuilder(); + String apiInfo = null; + builder.append(annotation.value()[0]); + //鑾峰彇鏂规硶涓婃敞瑙� + if (method.isAnnotationPresent(PostMapping.class)) { + PostMapping post = method.getAnnotation(PostMapping.class); + builder.append(post.value()[0]); + } + if (method.isAnnotationPresent(GetMapping.class)) { + GetMapping get = method.getAnnotation(GetMapping.class); + builder.append(get.value()[0]); + } + if (method.isAnnotationPresent(DeleteMapping.class)) { + DeleteMapping delete = method.getAnnotation(DeleteMapping.class); + builder.append(delete.value()[0]); + } + if (method.isAnnotationPresent(PutMapping.class)) { + PutMapping put = method.getAnnotation(PutMapping.class); + builder.append(put.value()[0]); + } + if (method.isAnnotationPresent(ApiOperation.class)) { + ApiOperation api = method.getAnnotation(ApiOperation.class); + apiInfo = api.value(); + } + String roleId = String.valueOf(userInfo.get("roleId")); + Map<String, Object> urlType = roleService.getUrlType(builder.toString()); + log.info("鎷︽埅璇锋眰----------------銆�" + builder); + boolean b = roleService.hasUrl(String.valueOf(urlType.get("type")), String.valueOf(urlType.get("menuId")), roleId); + if (!b) { + log.warn("鐢ㄦ埛/id锛�" + userInfo.get("name") + "/" + userInfo.get("id") + "---------鏉冮檺涓嶈冻锛屽凡鎷︽埅锛�"); + //throw new AuthException("400","鏃犳潈闄�"); + } + } else { + throw new AuthException("401", "鐧婚檰杩囨湡!"); } } - - } -- Gitblit v1.9.3