Parcourir la source

新增动态表单权限验证器

周浩 il y a 9 ans
Parent
commit
16b62714bc

+ 10 - 0
hsweb-web-controller/src/main/java/org/hsweb/web/controller/DynamicFormAuthorizeValidator.java

@@ -0,0 +1,10 @@
+package org.hsweb.web.controller;
+
+import org.hsweb.web.bean.po.user.User;
+
+/**
+ * Created by zhouhao on 16-5-16.
+ */
+public interface DynamicFormAuthorizeValidator {
+    boolean validate(String formName, User user, String... actions);
+}

+ 30 - 0
hsweb-web-controller/src/main/java/org/hsweb/web/controller/DynamicFormAuthorizeValidatorConfiguration.java

@@ -0,0 +1,30 @@
+package org.hsweb.web.controller;
+
+import org.hsweb.web.bean.po.user.User;
+import org.hsweb.web.core.authorize.ExpressionScopeBean;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+
+/**
+ * Created by zhouhao on 16-5-16.
+ */
+@Component("dynamicFormAuthorizeValidator")
+public class DynamicFormAuthorizeValidatorConfiguration implements ExpressionScopeBean {
+
+    @Autowired(required = false)
+    private List<DynamicFormAuthorizeValidator> dynamicFormAuthorizeValidators;
+
+    public boolean validate(String formName, User user, String... actions) {
+        if (dynamicFormAuthorizeValidators != null) {
+            for (DynamicFormAuthorizeValidator validator : dynamicFormAuthorizeValidators) {
+                if (validator.validate(formName, user, actions)) {
+                    return true;
+                }
+            }
+            return false;
+        }
+        return true;
+    }
+}