您当前的位置: 首页 >  spring

梁云亮

暂无认证

  • 1浏览

    0关注

    1211博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

SpringBoot+SpringSecurity系列六:静态资源放行

梁云亮 发布时间:2022-01-07 15:27:56 ,浏览量:1

第一步:准备静态资源
  • 在resources/static/imgs下放置一张名称为mm01.jpg的图片
  • 在resources/static/css下创建文件demo.css
.cc{
    font-size: 38px;
    color: red;
}
  • 在resources/static/js下创建文件demo.js
function fun() {
    alert(3+2);
}
第二步:修改index.html


  
  首页
  


首页



fun()



第三步:修改SpringSecurity配置文件
@Override
protected void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests()
            //授权
            .antMatchers("/openIndex").permitAll()//toLogin放行:不需要拦截,可以随便访问
            .antMatchers("/**/*.css","/**/*.js","/imgs/**").permitAll() //放行静态资源
            .anyRequest().authenticated()//其它请求都必须认证后才能访问
            .and()
            //关闭防火墙:为了保证完整流程可用关闭CSRF安全协议
            .csrf().disable();
}
关注
打赏
1665409997
查看更多评论
立即登录/注册

微信扫码登录

0.0401s