瀏覽代碼

优化权限控制逻辑

zhouhao 5 年之前
父節點
當前提交
44a401b188

+ 4 - 6
hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/define/DimensionsDefinition.java

@@ -23,6 +23,10 @@ public class DimensionsDefinition {
         dimensions.add(definition);
     }
 
+    public boolean isEmpty(){
+        return CollectionUtils.isEmpty(this.dimensions);
+    }
+
     public boolean hasDimension(Dimension dimension) {
         return dimensions
                 .stream()
@@ -33,12 +37,6 @@ public class DimensionsDefinition {
 
     public boolean hasDimension(List<Dimension> dimensions) {
 
-        if (CollectionUtils.isEmpty(this.dimensions)) {
-            return true;
-        }
-        if (CollectionUtils.isEmpty(this.dimensions)) {
-            return false;
-        }
         if (logical == Logical.AND) {
             return dimensions.stream().allMatch(this::hasDimension);
         }

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

@@ -65,7 +65,7 @@ public class AopAuthorizingController extends StaticMethodMatcherPointcutAdvisor
                                            Supplier<? extends Publisher<?>> invoker) {
 
         return Authentication.currentReactive()
-                .switchIfEmpty(Mono.error(new UnAuthorizedException()))
+                .switchIfEmpty(Mono.error(UnAuthorizedException::new))
                 .flatMapMany(auth -> {
                     context.setAuthentication(auth);
                     Function<Runnable, Publisher> afterRuner = runnable -> {
@@ -125,6 +125,7 @@ public class AopAuthorizingController extends StaticMethodMatcherPointcutAdvisor
                 } else if (Flux.class.isAssignableFrom(returnType)) {
                     return Flux.from(publisher);
                 }
+                throw new UnsupportedOperationException("unsupported reactive type:" + returnType);
             }
 
             Authentication authentication = Authentication.current().orElseThrow(UnAuthorizedException::new);
@@ -182,9 +183,11 @@ public class AopAuthorizingController extends StaticMethodMatcherPointcutAdvisor
 
     @Override
     public boolean matches(Method method, Class<?> aClass) {
+        Authorize authorize;
         boolean support = AnnotationUtils.findAnnotation(aClass, Controller.class) != null
                 || AnnotationUtils.findAnnotation(aClass, RestController.class) != null
-                || AnnotationUtils.findAnnotation(aClass, method, Authorize.class) != null;
+                || ((authorize = AnnotationUtils.findAnnotation(aClass, method, Authorize.class)) != null && !authorize.ignore()
+        );
 
         if (support && autoParse) {
             aopMethodAuthorizeDefinitionParser.parse(aClass, method);

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

@@ -28,7 +28,7 @@ import java.util.stream.Stream;
 public class DefaultBasicAuthorizeDefinition implements AopAuthorizeDefinition {
 
     @JsonIgnore
-    private Class targetClass;
+    private Class<?> targetClass;
 
 
     @JsonIgnore
@@ -43,7 +43,7 @@ public class DefaultBasicAuthorizeDefinition implements AopAuthorizeDefinition {
 
     @Override
     public boolean isEmpty() {
-        return resources.getResources().isEmpty() && dimensions.getDimensions().isEmpty();
+        return false;
     }
 
     private static final Set<Class<? extends Annotation>> types = new HashSet<>(Arrays.asList(
@@ -55,7 +55,7 @@ public class DefaultBasicAuthorizeDefinition implements AopAuthorizeDefinition {
             DataAccessType.class
     ));
 
-    public static AopAuthorizeDefinition from(Class targetClass, Method method) {
+    public static AopAuthorizeDefinition from(Class<?> targetClass, Method method) {
         return new AopAuthorizeDefinitionParser(targetClass,method).parse();
     }