【问题标题】:Spring Security Unexpected Behaviour for Public Endpoints公共端点的 Spring Security 意外行为
【发布时间】:2016-08-05 17:19:50
【问题描述】:

我有一个 Spring HttpSecurity 配置

@Override
protected void configure(HttpSecurity http) throws Exception {
    http
    .sessionManagement()
        .sessionCreationPolicy(SessionCreationPolicy.STATELESS);
    http.csrf().disable().httpBasic().and()
        .authorizeRequests()
            .antMatchers("/public/**").permitAll()
            .antMatchers("/secure/**").authenticated()
            .antMatchers("/backend/**").authenticated()
            .antMatchers(HttpMethod.OPTIONS, "/**").permitAll();
}

客户端为“/public/**”端点设置授权标头可能很愚蠢。

但是,我注意到 Spring Security 尝试进行身份验证尝试为公共请求创建经过身份验证的会话,因为提供了授权标头。

HttpSecurity 配置不应该覆盖此行为吗?

【问题讨论】:

  • 不,它不应该......允许所有的东西都不同,因为根本没有安全。对于后者,覆盖configure(WebSecurity) 并使用ignoring 根本没有安全性。
  • 谢谢!为什么我需要两个安全配置?
  • 它们都有不同的用途。

标签: spring spring-security spring-boot spring-data spring-web


【解决方案1】:

在 cmets 中回答:

不,它不应该...允许所有的东西是不同的,因为根本没有安全。对于后者,请覆盖“配置(WebSecurity)”并使用“忽略”来完全不安全。

【讨论】:

    猜你喜欢
    • 2017-05-08
    • 1970-01-01
    • 2017-02-21
    • 2020-05-05
    • 1970-01-01
    • 2015-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-18
    相关资源
    最近更新 更多