Spring Security 5 : There is no PasswordEncoder mapped for the id null
When you are configuring the ClientDetailsServiceConfigurer
, you have to also apply the new password storage format to the client secret.
.secret("{noop}secret")
there is no passwordencoder mapped for the id null / how to map an id?
Spring Security requires a PasswordEncoder
when working with user passwords, you have not provided information about it. You need declare bean with it, for example using BCryptPasswordEncoder
:
@Bean
PasswordEncoder getPasswordEncoder() {
return new BCryptPasswordEncoder();
}
and use it in your code. You can find many examples on the internet, like this.
If, for any reason, we don't want to encode the configured password, we can make use of the NoOpPasswordEncoder
.
There is no PasswordEncoder mapped for the id null with database authentication
I changed MyUserDetailsService class adding passwordEncoder
method.
Added lines
BCryptPasswordEncoder encoder = passwordEncoder();
Changed Line
//changed, user.getPassword() as encoder.encode(user.getPassword())
return new org.springframework.security.core.userdetails.User(--)
MyUserDetailsService.java
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
BCryptPasswordEncoder encoder = passwordEncoder();
User user = userRepository.findByUsername(username);
if(user == null){
throw new UsernameNotFoundException("User Name "+username +"Not Found");
}
return new org.springframework.security.core.userdetails.User(user.getUserName(),encoder.encode(user.getPassword()),getGrantedAuthorities(user));
}
@Bean
public BCryptPasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
There is no PasswordEncoder mapped for the id null
you need to encode your secret in order to pass the authentication: add {noop}
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.inMemory().withClient("pgcil").secret("{noop}secret").scopes("read", "write")
.authorizedGrantTypes("password", "refresh_token").accessTokenValiditySeconds(3600)
.refreshTokenValiditySeconds(18000);
}
Related Topics
Multiple Axes on the Same Data
Correct Idiom for Managing Multiple Chained Resources in Try-With-Resources Block
In Java Critical Sections, What Should I Synchronize On
Differencebetween Cascade & Inverse in Hibernate, What Are They Used For
Stax Xmlstreamreader Check for the Next Event Without Moving Ahead
Retrofit 2.0 How to Get Deserialised Error Response.Body
Javafx: "Toolkit" Not Initialized When Trying to Play an Mp3 File Through Mediaplayer Class
Converting String to Date Using Simpledateformat Is Returning Random Date
Why Doesn't My Compare Work Between Char and Int in Java
How to Find Out If the Value Contained in a String Is Double or Not
Java Stanford Nlp: Part of Speech Labels
How to Run a Class from Jar Which Is Not the Main-Class in Its Manifest File
Eclipse - Java.Lang.Classnotfoundexception
Put Byte Array to JSON and Vice Versa
How to Upload and Store an Image with Google App Engine (Java)