优化配置

This commit is contained in:
zhouhao
2017-10-13 16:01:23 +08:00
parent 44bf0960c8
commit e235b1e301
8 changed files with 28 additions and 15 deletions

View File

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

View File

@@ -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();
}
}

View File

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

View File

@@ -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

View File

@@ -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);
}

View File

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

View File

@@ -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:

View File

@@ -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;
}