Spring boot 尝试仅为方法添加安全性并放置和删除
我的微服务中有3种方法。它们是GET、PUT和DELETE。 我只想为PUT和delete方法提供安全性,GET方法不应该有任何安全性。我怎样才能做到这一点 请帮忙。下面是允许所有请求的代码Spring boot 尝试仅为方法添加安全性并放置和删除,spring-boot,Spring Boot,我的微服务中有3种方法。它们是GET、PUT和DELETE。 我只想为PUT和delete方法提供安全性,GET方法不应该有任何安全性。我怎样才能做到这一点 请帮忙。下面是允许所有请求的代码 @Override protected void configure(HttpSecurity http) throws Exception { http .csrf().disable() .authorizeRequests()
@Override
protected void configure(HttpSecurity http) throws Exception
{
http
.csrf().disable()
.authorizeRequests().anyRequest().authenticated()
.and()
.httpBasic();
}
你可以试试这个:
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers(HttpMethod.PUT).fullyAuthenticated()
.antMatchers(HttpMethod.DELETE).fullyAuthenticated()
.antMatchers(HttpMethod.GET).permitAll();
}