返回值优化

This commit is contained in:
myh 2023-12-11 00:02:06 +08:00
parent 7c6116f2c5
commit 14e3eda3a9

View File

@ -6,7 +6,6 @@ import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
@ -38,7 +37,7 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter {
if (StringUtils.hasText(token) && jwtTokenProvider.validateToken(token)) {
// token 获取 username
String username = jwtTokenProvider.getUsername(token);
// 加载与 token 关联的用户
// 加载与 token 关联的用户
UserDetails userDetails = userDetailsService.loadUserByUsername(username);
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(
userDetails,
@ -53,14 +52,14 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter {
filterChain.doFilter(request, response);
}
private @Nullable String getTokenFromRequest(@NotNull HttpServletRequest request) {
private @NotNull String getTokenFromRequest(@NotNull HttpServletRequest request) {
String bearerToken = request.getHeader("Authorization");
if (StringUtils.hasText(bearerToken) && bearerToken.startsWith("Bearer ")) {
return bearerToken.substring(7);
}
return null;
} else {
return "";
}
}
}