【问题标题】:spring security architecture filter chain and request matcherSpring Security 架构过滤器链和请求匹配器
【发布时间】:2020-07-10 00:12:56
【问题描述】:

我一直在阅读来自 here 的 spring 安全文档。 有一个例子:

@Configuration
@Order(SecurityProperties.BASIC_AUTH_ORDER - 10)
public class ApplicationConfigurerAdapter extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
    http.antMatcher("/foo/**")
    .authorizeRequests()
        .antMatchers("/foo/bar").hasRole("BAR")
        .antMatchers("/foo/spam").hasRole("SPAM")
        .anyRequest().isAuthenticated();
    }
}

它说

配置 Spring Security 最容易犯的错误之一就是忘记了这些匹配器适用于不同的进程,一个是整个过滤器链请求匹配器,另一种只是选择要应用的访问规则。

我想知道这是什么忘记?我无法获得关系、过滤器链请求匹配器

【问题讨论】:

    标签: spring authentication spring-security


    【解决方案1】:

    这是一种非常复杂的说法:

    1. .anyRequest().isAuthenticated();确保要访问应用程序中的任何 url,用户需要经过身份验证。
    2. 此外,除了对用户进行身份验证之外,这两个 ant 匹配器只是检查所需的角色(=访问规则)。

    这一段写得不好,恕我直言。

    【讨论】:

      猜你喜欢
      • 2013-06-16
      • 2020-12-27
      • 2021-08-18
      • 2021-05-28
      • 1970-01-01
      • 1970-01-01
      • 2018-03-14
      • 2023-03-19
      • 1970-01-01
      相关资源
      最近更新 更多