开始吧
1、 在自己的配置类中重写父类的 configure(HttpSecuritysecurity)方法。
SpringSecurityConfig
//重写configure方法进行配置
@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity
.authorizeRequests() //对请求进行授权
.antMatchers("/index.jsp","/layui/**") //针对 /index.jsp以及layui下的内容进行授权
.permitAll() //授权的级别:可以无条件访问
.and()
.authorizeRequests() //对请求进行授权
.anyRequest() //人已请求
.authenticated() //需要登陆后才可以访问
;
}
.antMatchers("/index.jsp","/layui/**")参数可以写多个
2、 启动服务器测试效果
得到放行:
登录是访问不到没有授权的资源的: