优化JwtAuthenticationTokenFilter中的代码格式,修复部分空值处理逻辑
This commit is contained in:
parent
002907d98d
commit
6d5b2c2c65
|
|
@ -29,21 +29,21 @@ public class JwtAuthenticationTokenFilter extends OncePerRequestFilter {
|
|||
@Autowired
|
||||
private JWTTokenService tokenService;
|
||||
|
||||
@Value("${server.servlet.context-path}")
|
||||
public String path;
|
||||
@Value("${server.servlet.context-path:}")
|
||||
public String path;
|
||||
|
||||
@Override
|
||||
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException, IOException, ServletException {
|
||||
//获取token
|
||||
String jwtToken = SecurityUtils.getToken(request);
|
||||
String uri=request.getRequestURI();
|
||||
System.err.println(uri);
|
||||
System.err.println(uri);
|
||||
|
||||
if((path + "/login/userLogin").equals(uri)){
|
||||
if ((path + "/login/userLogin").equals(uri)) {
|
||||
filterChain.doFilter(request, response);
|
||||
return;
|
||||
}
|
||||
if((path +"/login/appUserLogin").equals(uri)){
|
||||
if ((path +"/login/appUserLogin").equals(uri)) {
|
||||
filterChain.doFilter(request, response);
|
||||
return;
|
||||
}
|
||||
|
|
@ -55,7 +55,7 @@ public class JwtAuthenticationTokenFilter extends OncePerRequestFilter {
|
|||
filterChain.doFilter(request, response);
|
||||
return;
|
||||
}
|
||||
if(StringUtils.isEmpty(jwtToken)){
|
||||
if (StringUtils.isEmpty(jwtToken)){
|
||||
System.err.println("----------------->");
|
||||
ResultUtil.responseJson(response,ResultUtil.resultCode(401,"登录过期,请先登录"));
|
||||
System.err.println("异常401,token信息:" + jwtToken + ",地址" + uri);
|
||||
|
|
@ -66,18 +66,16 @@ public class JwtAuthenticationTokenFilter extends OncePerRequestFilter {
|
|||
Claims claims = JwtUtils.parseToken(jwtToken);
|
||||
Integer userId = (Integer) claims.get(SecurityConstants.DETAILS_USER_ID);
|
||||
String userName = (String) claims.get(SecurityConstants.DETAILS_USERNAME);
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.err.println("异常401,登录过期,token信息:" + jwtToken + ",地址" + uri);
|
||||
ResultUtil.responseJson(response,ResultUtil.resultCode(401,"登录过期,请先登录"));
|
||||
return;
|
||||
}
|
||||
SelfUserEntity loginUser = tokenService.getLoginUser(request);
|
||||
if(Objects.isNull(loginUser)){
|
||||
SelfUserEntity loginUser = tokenService.getLoginUser(request);
|
||||
if (Objects.isNull(loginUser)) {
|
||||
ResultUtil.responseJson(response,ResultUtil.resultCode(401,"登录过期,请重新登录"));
|
||||
return;
|
||||
}else{
|
||||
} else {
|
||||
// 验证令牌有效期,相差不足10分钟,自动刷新缓存
|
||||
tokenService.verifyToken(loginUser);
|
||||
//存入SecurityContextHolder
|
||||
|
|
|
|||
Loading…
Reference in New Issue