Estou achando estranho este erro.
Classe que está informando no console:
package br.com.netsoft.configuracao.auth;
import io.jsonwebtoken.ExpiredJwtException;
import java.io.IOException;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.web.authentication.WebAuthenticationDetailsSource;
import org.springframework.web.filter.OncePerRequestFilter;
public class JwtAuthorizationTokenFilter extends OncePerRequestFilter {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private UserDetailsService userDetailsService;
private JwtTokenUtil jwtTokenUtil;
private String tokenHeader;
public JwtAuthorizationTokenFilter(UserDetailsService userDetailsService,
JwtTokenUtil jwtTokenUtil, String tokenHeader) {
this.userDetailsService = userDetailsService;
this.jwtTokenUtil = jwtTokenUtil;
this.tokenHeader = tokenHeader;
}
@Override
protected void doFilterInternal(HttpServletRequest request,
HttpServletResponse response, FilterChain chain)
throws ServletException, IOException {
logger.debug("Autenticação de processamento para '{}'",
request.getRequestURL());
String requestHeader = "Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIwMjY3OTUwMDYzNiIsImV4cCI6MTUyMzIxNTg5OX0.LIVrSKcVGHdrDRvCuGlWjoZoFd9WSSyoRWDpBH-YWtZoP3HM4YGwyuED0mVItFrKdEDjSEKvxXj1K2EF_6TCVg";
String username = null;
String authToken = null;
if (requestHeader != null && requestHeader.startsWith("Bearer ")) {
authToken = requestHeader.substring(7);
try {
username = jwtTokenUtil.getUsernameFromToken(authToken);
} catch (IllegalArgumentException e) {
logger.error(
"Ocorreu um erro durante a obtenção do nome de usuário do token.",
e);
} catch (ExpiredJwtException e) {
logger.warn("O token está expirado e não é mais válido.", e);
}
} else {
logger.warn("Não foi possível encontrar a string do portador, irá ignorar o cabeçalho.");
}
logger.debug("Verificando a autenticação para o usuário: '{}'",
username);
if (username != null
&& SecurityContextHolder.getContext().getAuthentication() == null) {
logger.debug("O contexto de segurança era nulo, autorizando o usuário.");
UserDetails userDetails = this.userDetailsService
.loadUserByUsername(username);
if (jwtTokenUtil.validateToken(authToken, userDetails)) {
UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(
userDetails, null, userDetails.getAuthorities());
authentication.setDetails(new WebAuthenticationDetailsSource()
.buildDetails(request));
logger.info(
"usuario autorizado: '{}', definindo contexto de segurança",
username);
SecurityContextHolder.getContext().setAuthentication(
authentication);
}
}
chain.doFilter(request, response);
}
Error
https://gist.github.com/guilhermecostalopes/a8f67a47a0c1c1dc835dc30a0314b2cf