java - HttpSecurity permitAll 和 WebSecurity 忽略 un-Auth URL 的功能?
问题描述
这个问题可能看起来像重复,但以下答案均未解释何时使用:
`http
.authorizeRequests()
.antMatchers("/h2-console/**", "/user/register/**").permitAll()`
和
`web
.ignoring()
.antMatchers("/h2-console/**", "/user/register/**")`
通过 StackOverflow asnwers 和几篇文章,我了解到:
configure(HttpSecurity)允许在资源级别配置基于 Web 的安全性。
configure(WebSecurity)用于影响全局安全的配置设置。使用此 URL 从 Spring Security Filter Chain 中完全忽略。
当我使用permitAll()
它时,它只有在我禁用csrf 时才有效:http.csrf().disable()
因为 Spring Security 过滤器链仍然处于活动状态。
但与web.ignoring()
URL 完全忽略。
还有很多文章http.permitAll()
用于/login
或/register
喜欢这个和这个
所以我想明白,
为什么我们甚至应该使用和http.permitAll()
之类的 Un-Auth URLS ?/login
/register
为什么我们不能使用web.ignoring()
for/login
和/register
?
为什么 web.ignoring()
通常仅用于提供静态内容,例如css
和webjars
等,而不是/login
和/register
?
解决方案
正如所@M. Deinum
指出的,我正在总结答案,并且我已经更新了PR中相同的文档。
configure(WebSecurity web)
此方法中使用的端点忽略了 spring 安全过滤器、标头、CSRF 等。请参阅 HeadersConfigurer、CsrfConfigurer。相反,如果您想保护公共端点免受常见漏洞的影响,请参阅
configure(HttpSecurity)
配置HttpSecurity#authorizeRequests
方法。
configure(HttpSecurity http)
可以在此处指定需要防御常见漏洞的公共端点。有关详细信息,请参阅授权
HttpSecurity#authorizeRequests
规则 。permitAll()
推荐阅读
- android - 实现自定义 GridView
- java - 将层从 cartoDB 浏览器添加到 Android 应用程序
- javascript - 在 d3 或 javascript 中生成 svg 圆形区域内的随机点
- python - 删除熊猫数据框中的重复记录,但根据字母顺序保留一条
- c# - Xamarin.Forms 使用 Xml 文件自定义呈现
- .net-core - 我应该使用 .Net Core 2.0 还是 2.1?
- java - 如何同步 2 个标签 JTabbedPane Swing
- r - R 中的 PortfolioAnalytics - optimize.portfolio() 结果为 NaN 的年化回报
- javascript - 如何在d3中制作堆叠条/区域
- javascript - 使用多个 jQuery-minicolors 色板更改多个 div 容器的背景颜色