Ola a todos Estou tendo um problema com o meu projeto, eu estou trabalhando em um projeto proprio, seguindo as aulas, agora na implementacao da camada de seguranca ao definir o meu endpoint que preciso que seja acessado sem autorizacao nao esta deixando eu acessar, por mais que eu coloque ele para ficar liberado nao me permite acessar sem antes logar, segue meu codigo:
package com.example.controlefamiliabackend.config.validacao.security;
import com.example.controlefamiliabackend.repositories.UsuarioRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;
@Configuration
public class SecurityConfigurations {
private final UsuarioRepository usuarioRepository;
private final AutenticacaoService autenticacaoService;
@Autowired
public SecurityConfigurations(UsuarioRepository usuarioRepository, AutenticacaoService autenticacaoService) {
this.usuarioRepository = usuarioRepository;
this.autenticacaoService = autenticacaoService;
}
@Bean
public AuthenticationManager authenticationManager(AuthenticationConfiguration authenticationConfiguration) throws Exception {
return authenticationConfiguration.getAuthenticationManager();
}
@Bean
public PasswordEncoder encoder() {
return new BCryptPasswordEncoder();
}
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception{
http.authorizeRequests()
.antMatchers(HttpMethod.POST, "/usuario").permitAll()
.anyRequest().authenticated().and().formLogin();
return http.build();
}
@Bean
public WebSecurityCustomizer webSecurityCustomizer() {
return (web) -> web.ignoring().antMatchers("/**.html", "/v2/api-docs", "/webjars/**", "/configuration/**", "/swagger-resources/**");
}
}