【问题标题】:How to authenticate some URL and ignore anything else如何验证某些 URL 并忽略其他任何内容
【发布时间】:2020-07-23 13:00:31
【问题描述】:

我想管理如下安全策略。 (HTTP基本授权)

  1. 在 URL 之后应用身份验证。 "/foo/"、"/bar/"

  2. 忽略任何其他 URL。 (即使请求在标头中有授权字段)

我知道 permitall()。但是 permitall() 不适合,因为它在请求头中有授权字段时应用安全策略。

【问题讨论】:

    标签: spring spring-boot security authentication


    【解决方案1】:

    如果你想忽略特定的 url,那么你需要实现这个方法。

    @Configuration
    @EnableWebSecurity
    public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    
        @Override
        public void configure(final WebSecurity web) throws Exception {
            web.ignoring()
               .antMatchers("/static/**");
        }
    }
    

    您可以将您的网址放在您不希望应用身份验证的 /static/** 的位置。

    您的示例意味着 Spring (Web) Security 忽略了 URL 模式 匹配您定义的表达式(“/static/**”)。这个网址是 被 Spring Security 跳过,因此不安全。

    阅读 Spring Security 参考以获得更多详细信息: Click here for spring security details

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-29
      • 2011-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多