Commit 493c0298 authored by ZhengJie's avatar ZhengJie
Browse files

[代码完善](v2.5): v2.5 beta TokenFilter Token 验证逻辑优化

对于已放行的接口不去验证 Token

Closes #338

2.5 Beta 详情:https://www.ydyno.com/archives/1225.html
parent adde56ba
......@@ -15,6 +15,7 @@
*/
package me.zhengjie.modules.security.security;
import cn.hutool.core.util.StrUtil;
import io.jsonwebtoken.ExpiredJwtException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
......@@ -47,8 +48,8 @@ public class TokenFilter extends GenericFilterBean {
throws IOException, ServletException {
HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
String token = resolveToken(httpServletRequest);
String requestRri = httpServletRequest.getRequestURI();
// 验证 token 是否存在
// 对于 Token 为空的不需要去查 Redis
if(StrUtil.isNotBlank(token)){
OnlineUserDto onlineUserDto = null;
SecurityProperties properties = SpringContextHolder.getBean(SecurityProperties.class);
try {
......@@ -62,9 +63,7 @@ public class TokenFilter extends GenericFilterBean {
SecurityContextHolder.getContext().setAuthentication(authentication);
// Token 续期
tokenProvider.checkRenewal(token);
log.debug("set Authentication to security context for '{}', uri: {}", authentication.getName(), requestRri);
} else {
log.debug("no valid JWT token found, uri: {}", requestRri);
}
}
filterChain.doFilter(servletRequest, servletResponse);
}
......
Supports Markdown
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