java为授权和非授权restful服务配置Spring安全性
我有一个SpringBoot应用程序,提供安全的RESTfulWeb服务。它在自己的WebSecurityConfigurerAdapter
类中与以下HttpSecurity
配置配合得很好:
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable();
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
http.authorizeRequests()
.antMatchers("/secure/**").hasRole(ROLE_XXX)
.anyRequest().authenticated().and().httpBasic();
}
此配置强制所有Web服务在/secure
下进行授权。
现在我想添加另一个Web服务,比如/public/test
,它可以在没有任何身份验证的情况下调用。有什么建议吗
# 1 楼答案
重写
void configure(WebSecurity web)
方法解决了我的问题: