2017-06-05 110 views
0

我已经实现用弹簧REST API和使用Spring Security进行保护的API,我的安全配置代码:春季安全允许的URL

http 
    .authorizeRequests() 
    .anyRequest().authenticated() 
    .and() 
    .requestCache() 
    .requestCache(new NullRequestCache()) 
    .and() 
    .httpBasic(); 

这个代码将验证所有的网址,但我希望允许匿名用户特定的URL在我的应用程序立即登记,所以我没有更改安全配置到下面的代码:

http 
    .authorizeRequests() 
    .antMatchers("/signup").permitAll() 
    .antMatchers("/**").authenticated() 
    .and() 
    .requestCache() 
    .requestCache(new NullRequestCache()) 
    .and() 
    .httpBasic(); 

,但我仍然需要通过验证才能访问/注册请求调用。 如何在我的API中允许一些请求调用?

+0

按照此链接应该解决您的问题:https://stackoverflow.com/questions/30366405/how-to-disable-spring-security-for-particular-url –

+1

谢谢这个解决我的问题 –

回答

0

我应该用WebSecurity参数覆盖configure方法,并使用下面的代码来忽略/注册请求。

@Override 
public void configure(WebSecurity web) throws Exception { 
    super.configure(web); 
    web.ignoring().antMatchers("/signup"); 
}