Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Security: IP Address Whitelist Before Deferring to HTTP Basic Auth

I have a single URL accessible through a servlet that I have locked down using Spring Security's DaoAuthenticationProvider. I now have the requirement that certain incoming IP addresses must be whitelisted and so are not requested to authenticate.

I can hack around this easily enough by overriding DaoAuthenticationProvider's authenticate method and bypassing the superclasses's implementation if the IP address matches a known IP address but this then only works when the sender of the request supplies a username and password (even if it's nonsense). Otherwise the provider doesn't get called.

What would be the best way to do this? Should I be using a filter to bypass the authentication procedure if a known IP address is incoming?

like image 739
NeilInglis Avatar asked Feb 28 '11 13:02

NeilInglis


1 Answers

Could you just use the hasIpAddress() expression? We're doing that for what appears to be a similar case.

    <security:intercept-url pattern="/services/**" access="hasIpAddress('192.168.1.0/24')"/>
like image 196
dbreaux Avatar answered Nov 23 '22 23:11

dbreaux