我自己遇到的这个问题解决:
在Spring Cloud OAuth2项目中使用grant_type为password方式/oauth/token访问获取token时报server_error。在postman中如下图:
{
"error": "server_error",
"error_description": "Internal Server Error"
}
java后台报错如下:
endpoint.TokenEndpoint : Handling error: NestedServletException, Handler dispatch failed; nested exception is java.lang.StackOverflowError
这个问题是由于grant_type=password代表的用户名密码授权
/**
* 该配置类,主要处理用户名和密码的校验等事宜
*/
@Configuration
public class SecurityConfiger extends WebSecurityConfigurerAdapter {
@Autowired
private PasswordEncoder passwordEncoder;
//注册1个认证管理器对象到容器
@Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
/**
* 密码编码对象(密码不进行加密处理)
*/
@Bean
public PasswordEncoder passwordEncoder() {
return NoOpPasswordEncoder.getInstance();
}
/**
* 处理用户名和密码验证事宜
* 1)客户端传递username和password参数到认证服务器
* 2)一般来说,username和password会存储在数据库中的用户表中
* 3)根据用户表中数据,验证当前传递过来的用户信息的合法性
*/
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
super.configure(auth);
// 在这个方法中就可以去关联数据库了,当前我们先把用户信息配置在内存中
// 实例化1个用户对象(相当于数据表中的1条用户记录)
UserDetails user = new User("admin","123456",new ArrayList<>());
auth.inMemoryAuthentication()
.withUser(user).passwordEncoder(passwordEncoder);
}
}
解决问题:以下纯属个人观点: