zhou-hao vor 7 Jahren
Ursprung
Commit
ffedcb84de

+ 2 - 0
hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/AuthenticationPredicate.java

@@ -9,6 +9,7 @@ import java.util.function.Predicate;
  * @author zhouhao
  * @since 3.0
  */
+@FunctionalInterface
 public interface AuthenticationPredicate extends Predicate<Authentication> {
 
     static AuthenticationPredicate has(String permissionString) {
@@ -54,6 +55,7 @@ public interface AuthenticationPredicate extends Predicate<Authentication> {
             throw new AccessDenyException();
         }
     }
+
     default void assertHas(Authentication authentication) {
         if (!test(authentication)) {
             throw new AccessDenyException();

+ 10 - 4
hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/Permission.java

@@ -17,12 +17,14 @@
 
 package org.hswebframework.web.authorization;
 
+import lombok.NonNull;
 import org.hswebframework.web.authorization.access.DataAccessConfig;
 import org.hswebframework.web.authorization.access.FieldFilterDataAccessConfig;
 import org.hswebframework.web.authorization.access.ScopeDataAccessConfig;
 
 import java.io.Serializable;
 import java.util.Collections;
+import java.util.Objects;
 import java.util.Optional;
 import java.util.Set;
 import java.util.function.Predicate;
@@ -140,7 +142,7 @@ public interface Permission extends Serializable {
      */
     default Set<String> findDenyFields(String action) {
         return findFieldFilter(action)
-                .filter(conf -> conf.getType().equals(DENY_FIELDS))
+                .filter(conf -> DENY_FIELDS.equals(conf.getType()))
                 .map(FieldFilterDataAccessConfig::getFields)
                 .orElseGet(Collections::emptySet);
     }
@@ -173,11 +175,15 @@ public interface Permission extends Serializable {
      * @return {@link DataAccessPredicate}
      */
     static Permission.DataAccessPredicate<ScopeDataAccessConfig> scope(String action, String type, String scopeType) {
+        Objects.requireNonNull(action, "action can not be null");
+        Objects.requireNonNull(type, "type can not be null");
+        Objects.requireNonNull(scopeType, "scopeType can not be null");
+
         return config ->
                 config instanceof ScopeDataAccessConfig
-                        && config.getAction().equals(action)
-                        && config.getType().equals(type)
-                        && ((ScopeDataAccessConfig) config).getScopeType().equals(scopeType);
+                        && action.equals(config.getAction())
+                        && type.equals(config.getType())
+                        && scopeType.equals(((ScopeDataAccessConfig) config).getScopeType());
     }