Primavera de seguridad OAuth2 problemas encontrados en el proceso de integración
1, no hay PasswordEncoder asignada para el ID de “nulo”
Spring Security formato 5 contraseña del formato: {id} encodedPassword este ID es un identificador que se utiliza para localizar el PasswordEncoder, se cifra la contraseña PasswordEncoder formato correspondiente. encodedPassword se refiere al cifrado de la contraseña original). ID debe comenzar contraseña, id debe ser añadido antes y después de la {}. Si no puede encontrar el ID, ID estará vacía.
Cuando OAuth2 de seguridad secreto resorte integrado también debe ser {id} encodedPassword
@Configuration
public class MyAuthorizationServerConfigurer extends AuthorizationServerConfigurerAdapter {
@Autowired
private UserDetailsService userDetailsService;
@Autowired
private AuthenticationManager authenticationManager;
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception{
clients.inMemory().withClient("trying").secret("{noop}secret").authorizedGrantTypes("refresh_token","password","client_credentials").scopes("webclient","mobileclient");
}
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpointsConfigurer) throws Exception{
endpointsConfigurer.authenticationManager((authenticationManager)).userDetailsService(userDetailsService);
}
}
@Configuration
public class MyWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {
@Override
@Bean
public AuthenticationManager authenticationManagerBean() throws Exception{
return super.authenticationManagerBean();
}
@Override
@Bean
public UserDetailsService userDetailsService() {
UserDetailsService userDetailsService = null;
try {
userDetailsService = super.userDetailsServiceBean();
} catch (Exception e) {
e.printStackTrace();
}
return userDetailsService;
}
@Override
protected void configure(AuthenticationManagerBuilder builder) throws Exception{
builder.userDetailsService(userDetailsService()).passwordEncoder(getPasswordEncoder());
builder.inMemoryAuthentication().passwordEncoder(getPasswordEncoder()).withUser("test").password(getPasswordEncoder().encode("123456")).roles("USER").and().withUser("trying").password(getPasswordEncoder().encode("123456")).roles("USER","ADMIN");
}
/**
* @Title:
* @Description: 获取加密对象
* @param
* @return
* @author huxx
* @date 2019/11/16 下午2:19
* @update
*/
private PasswordEncoder getPasswordEncoder(){
return new BCryptPasswordEncoder();
}
}