소스 검색

修复自定义权限管理时 默认管理失效

zhouhao 7 년 전
부모
커밋
4d9fe17cd8

+ 5 - 0
hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/Authentication.java

@@ -128,6 +128,7 @@ public interface Authentication extends Serializable {
      * @param <T>  属性值类型
      * @return Optional属性值
      */
+    @Deprecated
     <T extends Serializable> Optional<T> getAttribute(String name);
 
     /**
@@ -138,6 +139,7 @@ public interface Authentication extends Serializable {
      * @param object 属性值
      * @see AuthenticationManager#sync(Authentication)
      */
+    @Deprecated
     void setAttribute(String name, Serializable object);
 
     /**
@@ -146,6 +148,7 @@ public interface Authentication extends Serializable {
      * @param attributes 属性值map
      * @see AuthenticationManager#sync(Authentication)
      */
+    @Deprecated
     void setAttributes(Map<String, Serializable> attributes);
 
     /**
@@ -156,6 +159,7 @@ public interface Authentication extends Serializable {
      * @return 被删除的值
      * @see AuthenticationManager#sync(Authentication)
      */
+    @Deprecated
     <T extends Serializable> T removeAttributes(String name);
 
     /**
@@ -163,6 +167,7 @@ public interface Authentication extends Serializable {
      *
      * @return 全部属性集合
      */
+    @Deprecated
     Map<String, Serializable> getAttributes();
 
 }

+ 14 - 2
hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/token/ThirdPartAuthenticationManager.java

@@ -1,12 +1,24 @@
 package org.hswebframework.web.authorization.token;
 
-import org.hswebframework.web.authorization.AuthenticationManager;
+import org.hswebframework.web.authorization.Authentication;
 
 /**
  * @author zhouhao
  * @since 1.0
  */
-public interface ThirdPartAuthenticationManager extends AuthenticationManager {
+public interface ThirdPartAuthenticationManager {
 
+    /**
+     * @return 支持的tokenType
+     */
     String getTokenType();
+
+    /**
+     * 根据用户ID获取权限信息
+     *
+     * @param userId 用户ID
+     * @return 权限信息
+     */
+    Authentication getByUserId(String userId);
+
 }

+ 10 - 0
hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/token/UserTokenAuthenticationSupplier.java

@@ -39,6 +39,16 @@ public class UserTokenAuthenticationSupplier implements AuthenticationSupplier {
         return get(this.defaultAuthenticationManager, userId);
     }
 
+    protected Authentication get(ThirdPartAuthenticationManager authenticationManager, String userId) {
+        if (null == userId) {
+            return null;
+        }
+        if (null == authenticationManager) {
+            return this.defaultAuthenticationManager.getByUserId(userId);
+        }
+        return authenticationManager.getByUserId(userId);
+    }
+
     protected Authentication get(AuthenticationManager authenticationManager, String userId) {
         if (null == userId) {
             return null;