这个问题可能看起来重复,但以下答案都没有解释何时使用:
`http
.authorizeRequests()
.antMatchers("/h2-console/**", "/user/register/**").permitAll()`
和`web
.ignoring()
.antMatchers("/h2-console/**", "/user/register/**")`
通过 StackOverflow asnwers 和几篇文章,我了解到:
配置(HttpSecurity)允许在资源级别配置基于 Web 的安全性。
配置(网络安全)用于影响全局安全性的配置设置。使用这个 URL 会被 Spring Security Filter Chain 完全忽略。
当我使用时
permitAll()
它仅在我禁用时才有效 csrf :http.csrf().disable()
因为 Spring Security 过滤器链仍然处于 Activity 状态。但与
web.ignoring()
URL 被完全忽略。还有很多文章用
http.permitAll()
为 /login
或 /register
喜欢 like this one和 this所以我想明白,
为什么我们甚至应该使用
http.permitAll()
对于 Un-Auth URL,如 /login
和 /register
?为什么我们不能用
web.ignoring()
为 /login
和 /register
?为什么
web.ignoring()
常用于提供静态内容,如 css
和 webjars
仅等但不包括 /login
和 /register
?
最佳答案
如 @M. Deinum
指出,我正在总结答案,并且我已经在 PR 中更新了相同的文档。 .
configure(WebSecurity web)
Endpoint used in this method ignores the spring security filters, headers, CSRF etc. see HeadersConfigurer, CsrfConfigurer. Instead, if you want to protect public endpoints against common vulnerabilities, then see
configure(HttpSecurity)
andHttpSecurity#authorizeRequests
configuration method.
configure(HttpSecurity http)
Public endpoints that require defense against common vulnerabilities can be specified here. see
HttpSecurity#authorizeRequests
and thepermitAll()
authorization rule for more details.
关于java - HttpSecurity permitAll 和 WebSecurity 忽略未验证 URL 的功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62677271/