【问题标题】:Spring security multiple hasIPAddress antMatchersSpring 安全多个 hasIPAddress antMatchers
【发布时间】:2015-04-02 21:30:03
【问题描述】:

我有以下spring安全配置sn-p:

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

这可行,但我也想从127.0.0.1 授予对"/tokens" 的访问权限。我希望按照以下方式进行操作,但它没有:

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

【问题讨论】:

    标签: spring spring-security


    【解决方案1】:
    http
        .authorizeRequests()
        .antMatchers("/tokens").access(
                "hasIpAddress('10.0.0.0/16') or hasIpAddress('127.0.0.1/32')")
    ....
    

    【讨论】:

    • 请分享配置方法的完整方法定义。
    • 丑陋但工作......显然设计浮动api的人只考虑了快乐的路径...... THX!
    【解决方案2】:

    尝试像这样在spring security配置文件中设置这个配置

    <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>
    

    【讨论】:

      猜你喜欢
      • 2015-08-29
      • 2018-04-28
      • 2015-12-22
      • 1970-01-01
      • 2013-12-30
      • 2017-04-06
      • 2015-10-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多