项目场景:
练习security时发生的小错误
问题描述:
java.lang.IllegalArgumentException: There is no PasswordEncoder mapped for the id “null”
:
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().withUser("zhangsan").password("123456").roles("USER");
}
原因分析:
这里主要是security的底层密码需要进行加密的比对
解决方案:
所以我们需要一个PasswordEncoder 或者直接采用明文的形式加一个{noop}就好
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().withUser(“zhangsan”).password(" {noop}123456").roles(“USER”);
}