Spring Security disable security for requests made FROM a certain url

Viewed 1199

my application uses spring security. I know you can use antMatchers to permit requests for some URI that are mapped into your application. But I need too allow requests made from an external api to a URI in my application and just for that api. I need something like this:

     @Override
     protected void configure(WebSecurity web) throws Exception 
     {            
        web.ignoring()
          .antMatchers("http://externalTestApi.com");
     }

Does anybody know if this is possible? I did not find anything on this.

1 Answers

You can do something like this (if you want to combine multiple conditions)

.authorizeRequests()
.antMatchers("/user/list")
.access("authenticated or hasIpAddress('666.666.666.666') or hasIpAddress('127.0.0.1') or hasIpAddress('0:0:0:0:0:0:0:1')")

or

.authorizeRequests()
.antMatchers("/user/list")
.hasIpAddress("0.0.0.0/0");
Related