Skip to content

Commit

Permalink
auth appId expireMap empty edit
Browse files Browse the repository at this point in the history
  • Loading branch information
guoshiqiufeng committed Jan 13, 2022
1 parent 5b5f65a commit 9bbb486
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public interface AuthConstants {
*/
String EXCEPTION_STEP_CODE = "11";

/**
* token header 默认参数名
*/
String DEFAULT_TOKEN_HEADER_NAME = "Authorization";

/**
* 缓存前缀
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import com.gitee.fubluesky.kernel.auth.api.LoginApi;
import com.gitee.fubluesky.kernel.auth.api.UserServiceApi;
import com.gitee.fubluesky.kernel.auth.api.constants.AuthConstants;
import com.gitee.fubluesky.kernel.auth.api.exception.AuthException;
import com.gitee.fubluesky.kernel.auth.api.exception.enums.AuthExceptionEnum;
import com.gitee.fubluesky.kernel.auth.api.pojo.AuthProperties;
Expand Down Expand Up @@ -85,6 +86,13 @@ public String getToken() {
}
}
}

token = request.getHeader(AuthConstants.DEFAULT_TOKEN_HEADER_NAME);
if (StringUtils.isNotBlank(token)) {
token = token.replace(authProperties.getTokenPrefix(), "");
return token;
}

return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,22 @@ private Date getExpiration(String appId) {
}
}
else {
// 获取 过期时间配置
Map<String, Long> map = jwtProperties.getExpireMap();

if (StringUtils.isBlank(appId)) {
log.error("generateToken fail. The appId is blank!");
throw new JwtException(JwtExceptionEnum.JWT_CREATE_ERROR);
log.warn("multi expire is enabled, but the appId is empty!");

if (map == null || map.isEmpty()) {
log.warn("multi expire is enabled, but the expire map is empty!");
return new Date(System.currentTimeMillis() + jwtProperties.getExpire() * 1000);
}
appId = map.keySet().iterator().next();
}
// 获取
Map<String, Long> map = jwtProperties.getExpireMap();

if (map == null || map.isEmpty()) {
log.error("generateToken fail. The expireMap is empty!");
throw new JwtException(JwtExceptionEnum.JWT_CREATE_ERROR);
log.warn("multi expire is enabled, but the expire map is empty!");
return new Date(System.currentTimeMillis() + jwtProperties.getExpire() * 1000);
}
Long expire = map.get(appId);
if (expire == null) {
Expand Down

0 comments on commit 9bbb486

Please sign in to comment.