一、全局配置
@Configuration // IOC 容器
@EnableWebSecurity //启用Spring Security的web安全支持 @Import相关组件注册
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private WgcUserDetailsService wgcUserDetailsService;
//无需拦截的静态资源 web.ignoring()
@Override
public void configure(WebSecurity web) throws Exception {
super.configure(web);
}
//证明你是谁
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
//告诉SpringSecurity 我现在用哪种方式数据库的用户 密码 角色
auth.userDetailsService(wgcUserDetailsService);
//super.configure(auth);
/**
auth.inMemoryAuthentication().passwordEncoder(passwordEncoder())
.withUser("admin").password(passwordEncoder().encode("123")).roles("ADM")
.and()
.withUser("wgc").password(passwordEncoder().encode("321"))