diff --git a/src/main/java/com/wayn/common/constant/SysConstants.java b/src/main/java/com/wayn/common/constant/SysConstants.java index dc85df4..4354a52 100644 --- a/src/main/java/com/wayn/common/constant/SysConstants.java +++ b/src/main/java/com/wayn/common/constant/SysConstants.java @@ -21,10 +21,15 @@ public class SysConstants { public static final String LOGIN_TOKEN_KEY = "login_tokens:"; /** - * 令牌前缀 + * 登录用户key */ public static final String SIGN_KEY = "login_user_key"; + /** + * 令牌前缀 + */ + public static final String TOKEN_PREFIX = "Bearer "; + /** * 类型(M目录 C菜单 F按钮) */ diff --git a/src/main/java/com/wayn/framework/security/service/TokenService.java b/src/main/java/com/wayn/framework/security/service/TokenService.java index 87a92a4..041be8d 100644 --- a/src/main/java/com/wayn/framework/security/service/TokenService.java +++ b/src/main/java/com/wayn/framework/security/service/TokenService.java @@ -43,8 +43,7 @@ public class TokenService { // 解析对应的权限以及用户信息 String sign = decodedJWT.getClaim(SysConstants.SIGN_KEY).asString(); String userKey = getTokenKey(sign); - LoginUserDetail user = redisCache.getCacheObject(userKey); - return user; + return redisCache.getCacheObject(userKey); } return null; } @@ -82,18 +81,22 @@ public class TokenService { /** * 获取请求头中的token * - * @param request + * @param request 请求 * @return token */ 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 * - * @param sign - * @return + * @param sign 签名 + * @return 返回token的key */ private String getTokenKey(String sign) { return SysConstants.LOGIN_TOKEN_KEY + sign;