소스 검색

新增aop方式权限验证

周浩 9 년 전
부모
커밋
02aa653553
1개의 변경된 파일24개의 추가작업 그리고 0개의 파일을 삭제
  1. 24 0
      hsweb-web-controller/src/main/java/org/hsweb/web/controller/AopAuthorizeValidatorConfiguration.java

+ 24 - 0
hsweb-web-controller/src/main/java/org/hsweb/web/controller/AopAuthorizeValidatorConfiguration.java

@@ -0,0 +1,24 @@
+package org.hsweb.web.controller;
+
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
+import org.hsweb.web.authorize.AopAuthorizeValidator;
+import org.hsweb.web.exception.AuthorizeException;
+import org.springframework.core.annotation.Order;
+import org.springframework.stereotype.Component;
+
+/**
+ * Created by zhouhao on 16-4-28.
+ */
+@Aspect
+@Component
+@Order(1)
+public class AopAuthorizeValidatorConfiguration extends AopAuthorizeValidator {
+    @Around(value = "execution(* org.hsweb.web.controller..*Controller..*(..))")
+    public Object around(ProceedingJoinPoint pjp) throws Throwable {
+        boolean access = super.validate(pjp);
+        if (!access) throw new AuthorizeException("无权限", 403);
+        return pjp.proceed();
+    }
+}