kw,sSpringSecurity快速搭建_小黑孩666的博客-CSDN博客j
接上篇,我们搭建好了基本框架之后,怎么实现自定义用户及角色来登录不同的系统呢?话不多说,直接开干
一、首先创建一个自定义的配置类,继承WebSecurityConfigurerAdapter类
/**
* EnableGlobalMethodSecurity 启用方法级别的认证
*/
@Configuration
@EnableWebSecurity //标识启用spring security 安全框架的功能
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class MywebConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
PasswordEncoder passwordEncoder=passwordEncoder();
auth.inMemoryAuthentication().withUser("zhangsan")
// 给密码加密
.password(passwordEncoder.encode("123456"))
// 设置用户角色