Ola, eu de novo.
Gente desculpa incomodar mais uma vez mas depois de muito quebrar a cabeca cheguei a lugar nenhum e preciso de uma luz. Gerei um senha Bcrypt, fiz as configuracoes todas, a API esta rodando mas sempre retornando erro 403, mesmo as senhas coencidindo. Ja tentei varias senhas criadas de varios sites. Qualquer ajuda ja agradeco
Onde gerei a senha: https://www.browserling.com/tools/bcrypt
valores no BD:
id, login, senha
'1', 'rodrigo', '$2a$10$r767pfn3em6nDYyXhT8FJ.3OgPeYN/sMB0uJzGIeT1UYqqxGYTwi.'
Meu JSon: {
"login": "rodrigo",
"senha": "$2a$10$r767pfn3em6nDYyXhT8FJ.3OgPeYN/sMB0uJzGIeT1UYqqxGYTwi."
}
"login": "rodrigo",
"senha": "$2a$12$f4qgc0n4dckPZ140u4Qk0ufUhM.kXnp8082B1NkHGO7g.SvfA5SlG"
} O HIBERNATE retorna q retorna: Hibernate: select u1_0.id, u1_0.login, u1_0.senha from usuarios u1_0 where u1_0.login=? Hibernate: select u1_0.id, u1_0.login, u1_0.senha from usuarios u1_0 where u1_0.login=?
Classes: @Table(name = "usuarios") @Entity(name = "Usuario") @Getter @NoArgsConstructor @AllArgsConstructor @EqualsAndHashCode(of = "id")
public class Usuario implements UserDetails {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String login;
private String senha;
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
return List.of(new SimpleGrantedAuthority("ROLE_USER"));
}
@Override
public String getUsername() {
return login;
}
@Override
public String getPassword() {
return senha;
}
@Override
public boolean isAccountNonExpired() {
return true;
}
@Override
public boolean isAccountNonLocked() {
return true;
}
@Override
public boolean isCredentialsNonExpired() {
return true;
}
@Override
public boolean isEnabled() {
return true;
}
}
@EnableWebSecurity @Configuration public class SecurityConfiguration { @Bean //Para desabilitar a seguranca CSRF (aquela que chamava login) public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { return http.csrf().disable() .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS) .and().build(); } @Bean public AuthenticationManager authenticationManager(AuthenticationConfiguration cnfiguration) throws Exception{ return cnfiguration.getAuthenticationManager(); }
@Bean
public PasswordEncoder passwordEncoder(){
return new BCryptPasswordEncoder();
}
} @Service public class AutenticacaoService implements UserDetailsService {
@Autowired
private UsuarioRepository repository;
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
return repository.findByLogin(username);
}
}