|
@@ -30,45 +30,45 @@ import java.util.Arrays;
|
|
@Component
|
|
@Component
|
|
public class PermissionAspect {
|
|
public class PermissionAspect {
|
|
|
|
|
|
- @Autowired
|
|
|
|
- private ProjectUserService projectUserService;
|
|
|
|
- @Autowired
|
|
|
|
- private ProjectService projectService;
|
|
|
|
- @Autowired
|
|
|
|
- private CacheUtils cacheUtils;
|
|
|
|
- @Autowired
|
|
|
|
- private LoginUtils loginUtils;
|
|
|
|
- @Pointcut("execution(public * cn.cslg.pas.controller.*.*(..))")
|
|
|
|
- public void privilege() {
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @ResponseBody
|
|
|
|
- @Around("privilege()")
|
|
|
|
- public Object isAccessMethod(ProceedingJoinPoint joinPoint) throws Throwable {
|
|
|
|
- //获取访问目标方法
|
|
|
|
- MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
|
|
|
|
- Method targetMethod = methodSignature.getMethod();
|
|
|
|
- final int[] methodAccess = AnnotationParse.permissionParse(targetMethod);
|
|
|
|
- if (methodAccess != null && methodAccess.length != 0) {
|
|
|
|
- HttpServletRequest request = RequestHolder.getRequest();
|
|
|
|
- if (request != null) {
|
|
|
|
- String projectId = request.getHeader("x-project-id");
|
|
|
|
- Integer userId = loginUtils.getId();
|
|
|
|
- if (StringUtils.isNotEmpty(projectId)) {
|
|
|
|
- Project project = projectService.getById(projectId);
|
|
|
|
- User user = cacheUtils.getLoginUser(userId);
|
|
|
|
- ProjectUser projectUser = projectUserService.getProjectUserByProjectIdAndUserId(Integer.parseInt(projectId), userId);
|
|
|
|
- if (projectUser != null && project != null && user != null) {
|
|
|
|
- if (project.getCreateBy().equals(userId)) {
|
|
|
|
- return joinPoint.proceed();
|
|
|
|
- }
|
|
|
|
- if (Arrays.stream(methodAccess).noneMatch(item -> item == projectUser.getType())) {
|
|
|
|
- throw new PermissionException("用户操作拦截");
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return joinPoint.proceed();
|
|
|
|
- }
|
|
|
|
|
|
+// @Autowired
|
|
|
|
+// private ProjectUserService projectUserService;
|
|
|
|
+// @Autowired
|
|
|
|
+// private ProjectService projectService;
|
|
|
|
+// @Autowired
|
|
|
|
+// private CacheUtils cacheUtils;
|
|
|
|
+// @Autowired
|
|
|
|
+// private LoginUtils loginUtils;
|
|
|
|
+// @Pointcut("execution(public * cn.cslg.pas.controller.*.*(..))")
|
|
|
|
+// public void privilege() {
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// @ResponseBody
|
|
|
|
+// @Around("privilege()")
|
|
|
|
+// public Object isAccessMethod(ProceedingJoinPoint joinPoint) throws Throwable {
|
|
|
|
+// //获取访问目标方法
|
|
|
|
+// MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
|
|
|
|
+// Method targetMethod = methodSignature.getMethod();
|
|
|
|
+// final int[] methodAccess = AnnotationParse.permissionParse(targetMethod);
|
|
|
|
+// if (methodAccess != null && methodAccess.length != 0) {
|
|
|
|
+// HttpServletRequest request = RequestHolder.getRequest();
|
|
|
|
+// if (request != null) {
|
|
|
|
+// String projectId = request.getHeader("x-project-id");
|
|
|
|
+// Integer userId = loginUtils.getId();
|
|
|
|
+// if (StringUtils.isNotEmpty(projectId)) {
|
|
|
|
+// Project project = projectService.getById(projectId);
|
|
|
|
+// User user = cacheUtils.getLoginUser(userId);
|
|
|
|
+// ProjectUser projectUser = projectUserService.getProjectUserByProjectIdAndUserId(Integer.parseInt(projectId), userId);
|
|
|
|
+// if (projectUser != null && project != null && user != null) {
|
|
|
|
+// if (project.getCreateBy().equals(userId)) {
|
|
|
|
+// return joinPoint.proceed();
|
|
|
|
+// }
|
|
|
|
+// if (Arrays.stream(methodAccess).noneMatch(item -> item == projectUser.getType())) {
|
|
|
|
+// throw new PermissionException("用户操作拦截");
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// return joinPoint.proceed();
|
|
|
|
+// }
|
|
}
|
|
}
|