Bladeren bron

优化权限初始化逻辑

zhouhao 2 jaren geleden
bovenliggende
commit
1a707a29eb

+ 3 - 3
hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/aop/AopAuthorizingController.java

@@ -64,7 +64,8 @@ public class AopAuthorizingController extends StaticMethodMatcherPointcutAdvisor
                                            AuthorizingContext context,
                                            Supplier<? extends Publisher<?>> invoker) {
 
-        return Authentication.currentReactive()
+        return Authentication
+                .currentReactive()
                 .switchIfEmpty(Mono.error(UnAuthorizedException::new))
                 .flatMapMany(auth -> {
                     context.setAuthentication(auth);
@@ -133,8 +134,7 @@ public class AopAuthorizingController extends StaticMethodMatcherPointcutAdvisor
             context.setAuthentication(authentication);
             isControl = true;
 
-            Phased dataAccessPhased = null;
-            dataAccessPhased = definition.getResources().getPhased();
+            Phased dataAccessPhased = definition.getResources().getPhased();
             if (definition.getPhased() == Phased.before) {
                 //RDAC before
                 authorizingHandler.handRBAC(context);

+ 8 - 5
hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/define/DefaultBasicAuthorizeDefinition.java

@@ -38,7 +38,7 @@ public class DefaultBasicAuthorizeDefinition implements AopAuthorizeDefinition {
 
     private String message = "error.access_denied";
 
-    private Phased phased;
+    private Phased phased = Phased.before;
 
     @Override
     public boolean isEmpty() {
@@ -65,6 +65,7 @@ public class DefaultBasicAuthorizeDefinition implements AopAuthorizeDefinition {
             getResources().getResources().clear();
             getDimensions().getDimensions().clear();
         }
+        setPhased(ann.phased());
         getResources().setPhased(ann.phased());
         for (Resource resource : ann.resources()) {
             putAnnotation(resource);
@@ -97,6 +98,8 @@ public class DefaultBasicAuthorizeDefinition implements AopAuthorizeDefinition {
             putAnnotation(resource, action);
         }
         resource.setGroup(new ArrayList<>(Arrays.asList(ann.group())));
+        setPhased(ann.phased());
+        getResources().setPhased(ann.phased());
         resources.addResource(resource, ann.merge());
     }
 
@@ -132,8 +135,8 @@ public class DefaultBasicAuthorizeDefinition implements AopAuthorizeDefinition {
             return;
         }
         definition.getDataAccess()
-                .getDataAccessTypes()
-                .add(typeDefinition);
+                  .getDataAccessTypes()
+                  .add(typeDefinition);
     }
 
     public void putAnnotation(ResourceActionDefinition definition, DataAccessType dataAccessType) {
@@ -147,8 +150,8 @@ public class DefaultBasicAuthorizeDefinition implements AopAuthorizeDefinition {
         typeDefinition.setConfiguration(dataAccessType.configuration());
         typeDefinition.setDescription(String.join("\n", dataAccessType.description()));
         definition.getDataAccess()
-                .getDataAccessTypes()
-                .add(typeDefinition);
+                  .getDataAccessTypes()
+                  .add(typeDefinition);
     }
 
 }