I am getting the error below in Spring security after applying:
PasswordEncoderFactories.createDelegatingPasswordEncoder()
Project dependency:
- Spring Boot2.1.3
- Spring-cloud-starter-oauth2
I tried to use both of the below approaches:
First approach:
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
final PasswordEncoder encoder = PasswordEncoderFactories.createDelegatingPasswordEncoder();
auth.inMemoryAuthentication()
.withUser("user")
.password(encoder.encode("password"))
.roles("USER");
}
Error:
java.lang.IllegalArgumentException: There is no PasswordEncoder mapped for the id "null"
at org.springframework.security.crypto.password.DelegatingPasswordEncoder$UnmappedIdPasswordEncoder.matches
Second: approach -
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
final BCryptPasswordEncoder bcrypt = new BCryptPasswordEncoder();
auth.inMemoryAuthentication()
.withUser("user")
.password(encoder.encode("password"))
.roles("USER");
}
Error:
java.lang.IllegalArgumentException: password is not bcrypt type
I did not tried {noop}password because it is already depricated from Spring5. Had seen many solution on sites, but did not able to solve my problem.