springsecurity

springsecurity旧版本自定义设置用户密码角色

protected void configure(AuthenticationManagerBuilder auth) throws Exception {
 auth.inMemoryAuthentication().withUser("admin").password("123456").roles("ADMIN");
 auth.inMemoryAuthentication().withUser("zhangsan").password("zhangsan").roles("ADMIN");
 auth.inMemoryAuthentication().withUser("demo").password("demo").roles("USER");
}

 

2.x新版本(进行了加密):

 auth.inMemoryAuthentication() 

.passwordEncoder(new BCryptPasswordEncoder()).withUser("user1") 

.password(new BCryptPasswordEncoder().encode("123456"))  .roles("USER");

 

posted @ 2019-10-24 23:42  听惊雷  阅读(253)  评论(0编辑  收藏  举报