尝试仅为方法和 PUT 和 DELETE 添加安全性



我的微服务中有 3 个方法。它们是GET,PUT和DELETE。 我只想对PUT和删除方法进行安全性,GET方法不应该有任何安全性。我怎么能做到这一点。

请帮忙。下面是允许所有请求的代码。

@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();
}

最新更新