在学习spring boot security的过程中遇到了这样的一个问题。

查看代码,为了跳转到我们自己定义的登录页面,写了loginPage("/login.html"),按照正常的逻辑,应该我们在访问接口的时候,都会跳到登录页面,结果却报错了。其原因是我们在访问接口时,因为有 anyRequest(),对所有的请求都要进行认证,所以会跳到login.html这个页面,跳转过去之后去请求login.html这个页面也需要身份认证,所以还是跳到了login.html这个页面,形成了死循环,所以会出现这个错误。

http.formLogin().loginPage("/login.html").and().authorizeRequests().anyRequest().authenticated();

解决方式:加上.antMatchers("/login.html").permitAll() ,在这个方法里添加的url是不需要进行身份认证的,如果以后有更多的页面需要加入,只需要以逗号隔开就行,如antMatchers("/login.html","/index.html").permitAll()

 http.formLogin().loginPage("/login.html").and().authorizeRequests().antMatchers("/login.html").permitAll().anyRequest().authenticated();

spring boot security 将您重定向的次数过多相关推荐

  1. Spring Boot Security + Vue 登录成功后重定向无 Access-Control-Allow-Origin 问题解决办法

    需要明确: 已正确配置跨域资源共享(CORS)(不然也不可能看到登录成功了). 已正确配置了跨站请求伪造(CSRF)(登录时需要携带 _csrf.token). 全部使用 POST 提交的数据. 本文 ...

  2. 《深入理解 Spring Cloud 与微服务构建》第十六章 Spring Boot Security 详解

    <深入理解 Spring Cloud 与微服务构建>第十六章 Spring Boot Security 详解 文章目录 <深入理解 Spring Cloud 与微服务构建>第十 ...

  3. Spring Boot + Security + MyBatis + Thymeleaf + Activiti 快速开发平台项目

    项目介绍 Spring Boot + Security + MyBatis + Thymeleaf + Activiti 快速开发平台 基于 Layui 的后台管理系统模板,扩展 Layui 原生 U ...

  4. spring boot security学习

    spring boot security(一) 配置认证和授权 通过继承WebSecurityConfigurerAdapter,可以重写其认证和授权的逻辑. @Configuration @Enab ...

  5. boke练习: spring boot: security post数据时,要么关闭crst,要么添加隐藏域

    spring boot: security post数据时,要么关闭crst,要么添加隐藏域 http.csrf().disable(); 或者: <input name="${_cs ...

  6. Spring Boot + Security + Thymeleaf + Activiti 快速开发平台项目

    点击关注公众号,实用技术文章及时了解 项目介绍 Spring Boot + Security + MyBatis + Thymeleaf + Activiti 快速开发平台 基于 Layui 的后台管 ...

  7. Spring Boot Security - Remember Me示例

    Spring Boot Security- Remember Me Example - Websparrowhttps://www.websparrow.org/spring/spring-boot- ...

  8. Spring Boot + Security + MyBatis + Thymeleaf + Activiti 快速开发平台

    前言 项目介绍 Spring Boot + Security + MyBatis + Thymeleaf + Activiti 快速开发平台 基于Layui的后台管理系统模板,扩展Layui原生UI样 ...

  9. SpringBootAdmin集成Turbine、使用Spring Boot Security添加安全验证

    SpringBootAdmin集成Turbine Hystrix Dashboard是一个监控熔断器状况的组件,而Turbine是一个可以聚合多个HystrixDashboard的组件.在Spring ...

最新文章

  1. 华为笔记本matebook13_为什么我不推荐华为Matebook 13给职场新人/小白?
  2. 查看网页js数据接口
  3. D3.tsv与D3.csv加载数据
  4. AJAX的安全性及AJAX安全隐患
  5. 高级浏览器-SRWare Iron 29.0.1600.0 版本发布
  6. MYSQL索引结构学习笔记
  7. android开机自动开启zram,低内存配置  |  Android 开源项目  |  Android Open Source Project...
  8. shell调用python权限不足_使用权限从python运行shell脚本
  9. LWIP之TCP协议
  10. 一个c++程序员一年前的生活笔记
  11. 打车应用上马快递业务靠谱吗?
  12. 域控服务器取消验证_Linux 开发笔记《使用CentOS 7进行初始服务器设置》
  13. pytorch---之halfTensor
  14. win11电脑快捷键
  15. centos7 aarch64 环境编译安装MP4Box
  16. 用计算机三角函数公式,三角函数公式习题.doc
  17. 做正确的事永远都不迟
  18. winstor磁盘阵列数据恢复
  19. 用piranha配置LVS
  20. NOI——Bless All

热门文章

  1. 食品类目如何打造爆款?
  2. windows 中文输入法卡死解决办法
  3. 估计参数的方法:最大似然估计、贝叶斯推断
  4. java9 钻石操作符
  5. pipenet.v9.0(Spray V3.40,Standard V3.4,Transient V5.3)
  6. HappyPack not work in webpack 4
  7. 私はずっと頑張って、しかしどうしてやはりこのようにしますか。自分で問題を探します!
  8. eclipse无法进入debug模式
  9. 能救命的Apple Watch和双卡双待的iPhone来了
  10. linux配置svn开启端口映射,linux 下搭建Subversion (SVN)