Эх сурвалжийг харах

扩展core-security的AuthorizationComponent注解,prefix属性支持数组,同时注册为多个uri前缀的鉴权服务

Signed-off-by: luoshi <luoshi@qmth.com.cn>
luoshi 2 жил өмнө
parent
commit
4af26e359a

+ 1 - 1
core-security/src/main/java/com/qmth/boot/core/security/annotation/AuthorizationComponent.java

@@ -19,7 +19,7 @@ public @interface AuthorizationComponent {
      *
      * @return
      */
-    String prefix() default "";
+    String[] prefix() default {};
 
     /**
      * 匹配签名类型,可以为空

+ 8 - 7
core-security/src/main/java/com/qmth/boot/core/security/config/SecurityContextListener.java

@@ -4,7 +4,6 @@ import com.qmth.boot.core.security.annotation.AuthorizationComponent;
 import com.qmth.boot.core.security.service.AuthorizationService;
 import com.qmth.boot.core.security.service.impl.BaseAuthorizationSupport;
 import com.qmth.boot.tools.signature.SignatureType;
-import org.apache.commons.lang3.StringUtils;
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.ApplicationListener;
 import org.springframework.context.event.ContextRefreshedEvent;
@@ -43,12 +42,14 @@ public class SecurityContextListener implements ApplicationListener<ContextRefre
         }
     }
 
-    private void register(AuthorizationService bean, String prefix, SignatureType type) {
-        if (StringUtils.isNotBlank(prefix)) {
-            if (type != null) {
-                baseAuthorizationSupport.getServiceContainer().setPrefix(prefix, type, bean);
-            } else {
-                baseAuthorizationSupport.getServiceContainer().setPrefix(prefix, bean);
+    private void register(AuthorizationService bean, String[] prefixs, SignatureType type) {
+        if (prefixs.length > 0) {
+            for (String prefix : prefixs) {
+                if (type != null) {
+                    baseAuthorizationSupport.getServiceContainer().setPrefix(prefix, type, bean);
+                } else {
+                    baseAuthorizationSupport.getServiceContainer().setPrefix(prefix, bean);
+                }
             }
         } else {
             if (type != null) {