Spring Security 5:There Is No Passwordencoder Mapped for the Id "Null"

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



Leave a reply



Submit