refactor(jwt配置): 优化名称

master
wayn 5 years ago
parent c33d9ad94c
commit 4bb46bcb98

@ -21,10 +21,15 @@ public class SysConstants {
public static final String LOGIN_TOKEN_KEY = "login_tokens:"; public static final String LOGIN_TOKEN_KEY = "login_tokens:";
/** /**
* * key
*/ */
public static final String SIGN_KEY = "login_user_key"; public static final String SIGN_KEY = "login_user_key";
/**
*
*/
public static final String TOKEN_PREFIX = "Bearer ";
/** /**
* M C F * M C F
*/ */

@ -43,8 +43,7 @@ public class TokenService {
// 解析对应的权限以及用户信息 // 解析对应的权限以及用户信息
String sign = decodedJWT.getClaim(SysConstants.SIGN_KEY).asString(); String sign = decodedJWT.getClaim(SysConstants.SIGN_KEY).asString();
String userKey = getTokenKey(sign); String userKey = getTokenKey(sign);
LoginUserDetail user = redisCache.getCacheObject(userKey); return redisCache.getCacheObject(userKey);
return user;
} }
return null; return null;
} }
@ -82,18 +81,22 @@ public class TokenService {
/** /**
* token * token
* *
* @param request * @param request
* @return token * @return token
*/ */
private String getToken(HttpServletRequest request) { private String getToken(HttpServletRequest request) {
return request.getHeader(header); String token = request.getHeader(header);
if (StringUtils.isNotEmpty(token) && token.startsWith(SysConstants.TOKEN_PREFIX)) {
token = token.replace(SysConstants.TOKEN_PREFIX, "");
}
return token;
} }
/** /**
* key * key
* *
* @param sign * @param sign
* @return * @return tokenkey
*/ */
private String getTokenKey(String sign) { private String getTokenKey(String sign) {
return SysConstants.LOGIN_TOKEN_KEY + sign; return SysConstants.LOGIN_TOKEN_KEY + sign;

Loading…
Cancel
Save