【问题标题】:Spring Boot - FilterRegistrationBean setAllow() for several ip addressesSpring Boot - FilterRegistrationBean setAllow() 用于多个 ip 地址
【发布时间】:2018-07-19 13:16:53
【问题描述】:

如何将setAllow()(= 授予 ip 访问我的网络服务器)设置为 2 个或多个 ip 地址?

这适用于一个地址:

  @Bean
  public FilterRegistrationBean remoteAddressFilter() {
    FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
    RemoteAddrFilter filter = new RemoteAddrFilter();
    filter.setAllow("127\\.0\\.0\\.1");
    filter.setDenyStatus(403);
    filterRegistrationBean.setFilter(filter);
    filterRegistrationBean.addUrlPatterns("/*");
    return filterRegistrationBean;
  }

我正在考虑将一个白名单属性文件预加载到我的过滤器 bean 中,但我在网络上找不到合适的实现。

我的配置不使用任何.xml 文件。如果您的解决方案暗示创建web.xml,请详细说明如何创建放置位置如何调用

P.S : Spring 新手/Spring Boot 和安全配置设置

谢谢。

【问题讨论】:

  • .antMatchers("/").access("hasIpAddress('127.0.0.1') or hasIpAddress('xxx.xx.xx.x1') or hasIpAddress('xxx.xx.xx.x2') ") 等等。只是 or||access 表达式中。
  • 不,不是重复的,我的问题指向FilterRegistrationBean

标签: java spring spring-boot spring-security


【解决方案1】:

只需通过| 将它们分开即可,例如127\\.0\\.0\\.1|192\\.168\\.0\\.1 这只是一个普通的正则表达式值。

【讨论】:

    猜你喜欢
    • 2017-02-16
    • 2013-11-15
    • 2013-02-12
    • 1970-01-01
    • 2012-11-17
    • 1970-01-01
    • 2019-02-09
    • 2023-03-05
    • 1970-01-01
    相关资源
    最近更新 更多