Professor, desculpa mais uma ver abrir uma pergunta, mais agora estou recebendo esse erro -> The token was expected to have 3 parts, but got 0. se eu uso o getSubject, se eu o desabilito consigo gerar o login e pegar o token, porém se uso o getSubject ele não valida o subject.
SecurityFilter
@Component
public class SecurityFilter extends OncePerRequestFilter {
@Autowired
private TokenService tokenService;
@Autowired
private RepositorioUsuarios repositorioUsuario;
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
FilterChain filterChain) throws ServletException, IOException {
var tokenJWT = retrieveToken(request);
if(tokenJWT != null){
var subject = tokenService.getSubject(tokenJWT);
var usuario = repositorioUsuario.findByUsername(subject);
SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken
(usuario, null, usuario.getAuthorities()));
}
filterChain.doFilter(request, response);
}
private String retrieveToken(HttpServletRequest request) {
var authorizationHeader = request.getHeader("Authorization");
if(authorizationHeader != null){
return authorizationHeader.replace("Bearer ","");
}
return "Token não recuperado";
}
}