簡體   English   中英

基於不同http方法的Spring Security配置

[英]Spring Security configuration based on different http methods

在我的Spring Boot應用程序中,我已經配置了以下OAuth2 ResourceServer

@Override
public void configure(HttpSecurity http) throws Exception {
    // @formatter:off
    http
            .antMatcher("/api/**").authorizeRequests()
            .antMatchers("/api/v1.0/users").permitAll()
            .anyRequest().authenticated()
            .and()
            .csrf().disable()
            .sessionManagement().sessionCreationPolicy(STATELESS); 
    // @formatter:on
}

在我的REST API UserController我有兩種不同的請求處理程序方法-POST和GET http方法。 現在,上述配置中的兩個都是公開的。

我想保護POST方法的安全性,並且即使對於匿名用戶也將GET設為公開

為了支持此功能,如何更改上面的配置?

只需在匹配器中添加方法

antMatchers(HttpMethod.POST, "/api/v1.0/users")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM