No meu projeto está tudo atualizado mas o metodo authenticate continua forbbiden e n consigo fazer login
@Configuration
public class SecurityConfiguration{
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
return http.csrf().disable()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and().authorizeHttpRequests()
.requestMatchers(HttpMethod.POST, "/authenticate").permitAll()
.anyRequest().authenticated()
.and().build();
}
@Bean
public WebSecurityCustomizer webSecurityCustomizer() {
return (web) -> web.ignoring().requestMatchers("/public", "/authenticate", "/user");
}
@Bean
public AuthenticationManager authenticationManager(AuthenticationConfiguration configuration) throws Exception {
return configuration.getAuthenticationManager();
}
@Bean
public BCryptPasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
}
@Component
public class SecurityFilter extends OncePerRequestFilter {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
private UserDetailsService jwtUserDetailsService;
@Autowired
private JwtTokenUtil jwtTokenUtil;
@Value("${jwt.http.request.header}")
private String tokenHeader;
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException{
var token = recuperaToken(request);
var tokenSubject = jwtTokenUtil.getSubject(token);
System.out.println(tokenSubject);
chain.doFilter(request, response);
}
private String recuperaToken(HttpServletRequest request) {
var authorizationHeader = request.getHeader("Authorization");
if(authorizationHeader == null){
throw new RuntimeException("Token is not present");
}
return authorizationHeader.replace("Bearer ", "");
}
}