您当前的位置: 首页 >  spring

梁云亮

暂无认证

  • 2浏览

    0关注

    1211博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

SpringBoot+SpringSecurity系列五:自定义表单的请求参数

梁云亮 发布时间:2022-01-07 15:05:13 ,浏览量:2

第一步:在resources/templates下创建login.html



  
  登录页面



  
  
  



第二步:修改SpringSecurity配置文件
@Override
protected void configure(HttpSecurity http) throws Exception {
    http.formLogin() //表单登录
            .usernameParameter("username123")
            .passwordParameter("password234")
            .loginPage("/openLogin") //设置登录页面对应的地址,默认是/login
            .loginProcessingUrl("/userLogin") //设置用户登录时请求的地址,默认是/login
            .and()
            .authorizeRequests()
            //授权
            .antMatchers("/openLogin").anonymous()//toLogin放行:不需要拦截,可以随便访问
            .antMatchers("/**/*.css","/**/*.js","/imgs/**").permitAll()//放行静态资源
            .anyRequest().authenticated()//其它请求都必须认证后才能访问
            .and()
            //关闭防火墙:为了保证完整流程可用关闭CSRF安全协议
            .csrf().disable();
}
关注
打赏
1665409997
查看更多评论
立即登录/注册

微信扫码登录

0.0474s