Commit 15494106 authored by zhouxudong's avatar zhouxudong

优化代码

parent 9202d753
......@@ -24,14 +24,14 @@ public class CurrentUserInterceptor implements AsyncHandlerInterceptor {
// 从header中获取权限请求头
String authToken = request.getHeader(Constants.TOKEN_HEADER);
if(StringUtils.isBlank(authToken)){
throw new ServiceException("未授权,登录失败");
throw new ServiceException("未授权,请重新登录");
}
String token = authToken.substring("Bearer".length() + 1).trim();
JwtInfo jwtUser = JwtTokenUtil.getJwtUser(token);
Object redisToken = RedisUtil.get(RedisConstants.token + jwtUser.getPhone());
if(ObjectUtils.isEmpty(redisToken)){
throw new ServiceException("请重新登录");
throw new ServiceException("当前会话失效,请重新登录");
}
//判断是否续期
Long expire = RedisUtil.getExpire(RedisConstants.token + jwtUser.getPhone());
......
......@@ -59,6 +59,7 @@ public class WebConfig implements WebMvcConfigurer {
"/webjars/**",
"/v3/**",
"/v2/**",
"/error",
"/swagger**/**",
"/swagger-ui/index.html",
"/swagger-ui/index.html/**",
......
......@@ -12,6 +12,7 @@ public class TokenConstants {
public static final String DETAILS = "details";
public static final String AUTHORITIES = "authorities";
public static final String EXPIRE_TIME = "expire_time";
public static final String CREATE_TIME = "create_time";
public static final String RESULT = "message";
public static final String SUCCESS = "success";
......
package com.lyy.user.util.jwt;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUtil;
import com.lyy.user.config.exception.ServiceException;
import com.lyy.user.constant.TokenConstants;
import com.lyy.user.domain.JwtInfo;
......@@ -43,7 +44,7 @@ public class JwtTokenUtil {
JSONObject jsonObject = new JSONObject();
jsonObject.appendField(TokenConstants.DETAILS, jwtUser);
jsonObject.appendField(TokenConstants.AUTHORITIES, authorities);
jsonObject.appendField(TokenConstants.CREATE_TIME, System.currentTimeMillis());
Payload payload = new Payload(jsonObject);
JWSObject jwsObject = new JWSObject(jwsHeader, payload);
JWSSigner jwsSigner;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment