Skip to content
Advertisement

Spring Security 5 : There is no PasswordEncoder mapped for the id “null”

I am migrating from Spring Boot 1.4.9 to Spring Boot 2.0 and also to Spring Security 5 and I am trying to do authenticate via OAuth 2. But I am getting this error:

java.lang.IllegalArgumentException: There is no PasswordEncoder mapped for the id “null

From the documentation of Spring Security 5, I get to know that storage format for password is changed.

In my current code I have created my password encoder bean as:

JavaScript

However it was giving me below error:

Encoded password does not look like BCrypt

So I update the encoder as per the Spring Security 5 document to:

JavaScript

Now if I can see password in database it is storing as

JavaScript

With that 1st error gone and now when I am trying to do authentication I am getting below error:

java.lang.IllegalArgumentException: There is no PasswordEncoder mapped for the id “null

To solve this issue I tried all the below questions from Stackoverflow:

Here is a question similar to mine but not answerd:

NOTE: I am already storing encrypted password in database so no need to encode again in UserDetailsService.

In the Spring security 5 documentation they suggested you can handle this exception using:

DelegatingPasswordEncoder.setDefaultPasswordEncoderForMatches(PasswordEncoder)

If this is the fix then where should I put it? I have tried to put it in PasswordEncoder bean like below but it wasn’t working:

JavaScript

MyWebSecurity class

JavaScript

MyOauth2 Configuration

JavaScript

Please guide me with this issue. I have spend hours to fix this but not able to fix.

Advertisement

Answer

When you are configuring the ClientDetailsServiceConfigurer, you have to also apply the new password storage format to the client secret.

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement