Rest endpoint Springboot上的许可证桩

Rest endpoint Springboot上的许可证桩,spring,rest,spring-boot,Spring,Rest,Spring Boot,我有一个rest应用程序规范,它允许任何用户向端点发送POST请求,但限制GET仅限于系统的注册用户。有没有一种方法可以公开端点的某些方法,例如(POST或PUT),并限制其他方法,例如(GET或UPDATE),而不仅仅是保护端点的所有方法。当然。定义HttpSecurity时,可以指定要保护的HTTP方法: @Configuration public class SecurityConfig extends WebSecurityConfigurerAdapter { @Overrid

我有一个rest应用程序规范,它允许任何用户向端点发送POST请求,但限制GET仅限于系统的注册用户。有没有一种方法可以公开端点的某些方法,例如(POST或PUT),并限制其他方法,例如(GET或UPDATE),而不仅仅是保护端点的所有方法。

当然。定义HttpSecurity时,可以指定要保护的HTTP方法:

@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {

   @Override
   protected void configure(HttpSecurity http) throws Exception {
       http.
            csrf().disable().
            sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).
            and().
            authorizeRequests().
            antMatchers(HttpMethod.GET, "/rest/v1/session/login").permitAll().
            antMatchers(HttpMethod.POST, "/rest/v1/session/register").permitAll().
            antMatchers(HttpMethod.GET, "/rest/v1/session/logout").authenticated().
            antMatchers(HttpMethod.GET, "/rest/v1/**").hasAuthority("ADMIN").
            antMatchers(HttpMethod.POST, "/rest/v1/**").hasAuthority("USER").
            antMatchers(HttpMethod.PATCH, "/rest/v1/**").hasAuthority("USER").
            antMatchers(HttpMethod.DELETE, "/rest/v1/**").hasAuthority("USER").
            anyRequest().permitAll();
   }

   @Override
   protected void configure(AuthenticationManagerBuilder auth) throws Exception {
       auth
               .inMemoryAuthentication()
               .withUser('admin').password('secret').roles('ADMIN');
   }

   @Bean
   @Override
   AuthenticationManager authenticationManagerBean() throws Exception {
       return super.authenticationManagerBean()
   }
}