Spring安全性允许一个url
我已经使用spring实现了一个Rest api,并使用spring安全性保护该api,我的安全配置代码是:Spring安全性允许一个url,spring,spring-security,Spring,Spring Security,我已经使用spring实现了一个Rest api,并使用spring安全性保护该api,我的安全配置代码是: http .authorizeRequests() .anyRequest().authenticated() .and() .requestCache() .requestCache(new NullRequestCache()) .and() .httpBasic(); 此代码将验证所有url,但我希望允许匿名用
http
.authorizeRequests()
.anyRequest().authenticated()
.and()
.requestCache()
.requestCache(new NullRequestCache())
.and()
.httpBasic();
此代码将验证所有url,但我希望允许匿名用户在我的应用程序中注册特定url,因此我将安全配置更改为以下代码:
http
.authorizeRequests()
.antMatchers("/signup").permitAll()
.antMatchers("/**").authenticated()
.and()
.requestCache()
.requestCache(new NullRequestCache())
.and()
.httpBasic();
但是我仍然需要通过身份验证才能访问/signup请求调用。
如何在api中只允许一些请求调用?我应该使用WebSecurity参数覆盖configure方法,并使用以下代码忽略/signup请求
@Override
public void configure(WebSecurity web) throws Exception {
super.configure(web);
web.ignoring().antMatchers("/signup");
}
我应该用WebSecurity参数覆盖configure方法,并使用以下代码忽略/signup请求
@Override
public void configure(WebSecurity web) throws Exception {
super.configure(web);
web.ignoring().antMatchers("/signup");
}
下面这个链接应该解决你的问题:谢谢这个解决我的问题下面这个链接应该解决你的问题:谢谢这个解决我的问题