java - HttpSecurity permitAll 和 WebSecurity 忽略未验证 URL 的功能?

标签 java spring spring-boot spring-mvc spring-security

这个问题可能看起来重复,但以下答案都没有解释何时使用:

`http
   .authorizeRequests()
   .antMatchers("/h2-console/**", "/user/register/**").permitAll()` 
`web
   .ignoring()
   .antMatchers("/h2-console/**", "/user/register/**")`
  • HttpSecurity, WebSecurity and AuthenticationManagerBuilder
  • Difference between Web ignoring and Http permitting in Spring Security?

  • 通过 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 onethis
    所以我想明白,
    为什么我们甚至应该使用 http.permitAll()对于 Un-Auth URL,如 /login/register ?
    为什么我们不能用 web.ignoring()/login/register ?
    为什么 web.ignoring()常用于提供静态内容,如 csswebjars仅等但不包括 /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) and HttpSecurity#authorizeRequests configuration method.


    configure(HttpSecurity http)

    Public endpoints that require defense against common vulnerabilities can be specified here. see HttpSecurity#authorizeRequests and the permitAll() authorization rule for more details.

    关于java - HttpSecurity permitAll 和 WebSecurity 忽略未验证 URL 的功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62677271/

    相关文章:

    java - 为类的对象分配内存

    java - 如何在 Spring 中从 application.properties 重新加载 @Value 属性?

    java - 由于缺少 bean,Web 服务器无法启动

    java - ...NoteController 中的字段存储库需要类型为 ...NoteRepository 的 bean,但无法找到

    java - 如果 Kubernetes 上存在多个 pod,则从单个 pod 运行 Spring 中的 Scheduled Cron 方法

    java - Rest API 返回 byte[] i 响应

    java - 店面和后端有单独的项目还是单个项目更好?

    java.lang.IllegalStateException。 WebClassLoader 可能出现错误

    java - ModelMapper 中的 ClassCastException : EnhancerByModelMapper cannot be cast

    Java Swing Timer 只运行一次