Browse Source

优化配置

zhouhao 7 years ago
parent
commit
e235b1e301

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

@@ -28,6 +28,8 @@ import java.util.Map;
  * @see 3.0
  */
 public interface AuthenticationManager {
+    String USER_AUTH_CACHE_NAME = "user-auth-";
+
     /**
      * 根据用户ID获取权限信息
      *

+ 13 - 5
hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/token/MemoryUserTokenManager.java

@@ -32,9 +32,17 @@ import java.util.stream.Collectors;
  * @author zhouhao
  * @since 3.0
  */
-public class MemoryUserTokenManager implements UserTokenManager {
+public class DefaultUserTokenManager implements UserTokenManager {
 
-    private final ConcurrentMap<String, SimpleUserToken> tokenUserStorage = new ConcurrentHashMap<>(256);
+    protected final ConcurrentMap<String, SimpleUserToken> tokenUserStorage;
+
+    public DefaultUserTokenManager() {
+        this(new ConcurrentHashMap<>(256));
+    }
+
+    public DefaultUserTokenManager(ConcurrentMap<String, SimpleUserToken> storage) {
+        tokenUserStorage = storage;
+    }
 
     //令牌超时事件,默认3600秒
     private long timeout = 3600;
@@ -178,9 +186,9 @@ public class MemoryUserTokenManager implements UserTokenManager {
 
     @Override
     public void touch(String token) {
-        SimpleUserToken detail = tokenUserStorage.get(token);
-        if (null != detail)
-            detail.touch();
+        SimpleUserToken userToken = tokenUserStorage.get(token);
+        if (null != userToken)
+            userToken.touch();
     }
 
 }

+ 1 - 1
hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/token/SimpleUserToken.java

@@ -98,7 +98,7 @@ public class SimpleUserToken implements UserToken {
         requestTimesCounter.set(requestTimes);
     }
 
-    void touch() {
+    public void touch() {
         requestTimesCounter.addAndGet(1);
         lastRequestTime = System.currentTimeMillis();
     }

+ 2 - 2
hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/configuration/AuthorizingHandlerAutoConfiguration.java

@@ -8,7 +8,7 @@ import org.hswebframework.web.authorization.access.DataAccessHandler;
 import org.hswebframework.web.authorization.basic.handler.DefaultAuthorizingHandler;
 import org.hswebframework.web.authorization.basic.handler.access.DefaultDataAccessController;
 import org.hswebframework.web.authorization.basic.web.*;
-import org.hswebframework.web.authorization.token.MemoryUserTokenManager;
+import org.hswebframework.web.authorization.token.DefaultUserTokenManager;
 import org.hswebframework.web.authorization.token.UserTokenManager;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.config.BeanPostProcessor;
@@ -61,7 +61,7 @@ public class AuthorizingHandlerAutoConfiguration {
     @ConditionalOnMissingBean(UserTokenManager.class)
     @ConfigurationProperties(prefix = "hsweb.authorize")
     public UserTokenManager userTokenManager() {
-        return new MemoryUserTokenManager();
+        return new DefaultUserTokenManager();
     }
 
     @Bean

+ 2 - 2
hsweb-authorization/hsweb-authorization-cloud/src/main/java/org/hswebframework/web/authorization/cloud/client/feign/FeignAuthenticationManager.java

@@ -10,10 +10,10 @@ import org.springframework.web.bind.annotation.RequestMethod;
 @FeignClient(name = "${hsweb.cloud.user-center.name:user-center}")
 public interface FeignAuthenticationManager extends AuthenticationManager {
     @Override
-    @RequestMapping(value = "/user-auth/{userId}", method = RequestMethod.GET)
+    @RequestMapping(value = "${hsweb.cloud.user-center.prefix:/}user-auth/{userId}", method = RequestMethod.GET)
     Authentication getByUserId(@PathVariable("userId") String userId);
 
     @Override
-    @RequestMapping(value = "/user-auth", method = RequestMethod.PUT)
+    @RequestMapping(value = "${hsweb.cloud.user-center.prefix:/}user-auth", method = RequestMethod.PUT)
     Authentication sync(Authentication authentication);
 }

+ 1 - 0
hsweb-examples/hsweb-examples-cloud/hsweb-examples-cloud-gateway/src/main/resources/application.yml

@@ -18,6 +18,7 @@ zuul:
   sensitive-headers: Cookies
   host:
     connect-timeout-millis: 10000
+
 ribbon:
   eureka:
     enabled: true

+ 4 - 4
hsweb-examples/hsweb-examples-cloud/hsweb-examples-cloud-service01/src/main/resources/application.yml

@@ -11,10 +11,10 @@ hsweb:
     app:
       name: 权限管理测试
       version: 3.0.0
-#    cloud:
-#      user-center:
-#        name: gateway
-#        prefix: /api/user-center/
+    cloud:
+      user-center:
+        name: gateway
+        prefix: /api/user-center/
 server:
     port: 9001
 logging:

+ 3 - 1
hsweb-system/hsweb-system-authorization/hsweb-system-authorization-service/hsweb-system-authorization-service-simple/src/main/java/org/hswebframework/web/service/authorization/simple/CacheConstants.java

@@ -18,6 +18,8 @@
 
 package org.hswebframework.web.service.authorization.simple;
 
+import org.hswebframework.web.authorization.AuthenticationManager;
+
 /**
  * 缓存所需常量
  *
@@ -28,6 +30,6 @@ public interface CacheConstants {
 
     String USER_CACHE_NAME = "user-";
 
-    String USER_AUTH_CACHE_NAME = "user-auth-";
+    String USER_AUTH_CACHE_NAME = AuthenticationManager.USER_AUTH_CACHE_NAME;
 
 }