Spring安全多个hasIPAddress antMatchers

时间:2015-02-03 15:49:39

标签: spring spring-security

我有以下spring安全配置代码段:

http
   .authorizeRequests()
   .antMatchers("/tokens").hasIpAddress("10.0.0.0/16")
   ....

这有效,但我还想从"/tokens"授予对127.0.0.1的访问权限。我希望下面的内容能够奏效,但事实并非如此:

http
   .authorizeRequests()
   .antMatchers("/tokens").hasIpAddress("10.0.0.0/16").hasIpAddress("127.0.0.1/32")
   ....

2 个答案:

答案 0 :(得分:22)

http
    .authorizeRequests()
    .antMatchers("/tokens").access(
            "hasIpAddress('10.0.0.0/16') or hasIpAddress('127.0.0.1/32')")
....

答案 1 :(得分:4)

尝试在此弹出安全配置文件中设置此配置

<http auto-config="true" use-expressions="true">
<intercept-url pattern="/tokens**" access="hasIpAddress('10.0.0.0/16') or hasIpAddress('127.0.0.1/32')" />
</http>
相关问题