【问题标题】:spring boot security allow post request but only with permissionSpring Boot 安全性允许发布请求,但仅在获得许可的情况下
【发布时间】:2020-06-19 09:55:33
【问题描述】:

所以我的问题与 Spring Boot 的其他问题有点不同。我想在我的安全配置中允许发布请求,但仅限于身份验证

这是我的配置文件:

@Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
                .anyRequest().authenticated()
                .and()
                .httpBasic();
        http.csrf().disable();
    }

感谢您的帮助;)

【问题讨论】:

  • 那么 GET 和所有其他请求呢?
  • 获取请求有效。但我猜 crsf 或其他东西阻止了帖子
  • 是的,但我不确定这是否是典型的做法

标签: spring-boot spring-security


【解决方案1】:

您可以将antMachers 与以下模式一起使用。

antMatchers(HttpMethod.POST)

如果您只想验证特定路径的 POST 方法

antMatchers(HttpMethod.POST, "/path")

【讨论】:

    猜你喜欢
    • 2020-05-09
    • 2018-08-02
    • 2021-10-14
    • 2021-08-27
    • 2018-09-11
    • 2011-01-15
    • 2023-03-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多