实际上,您只需要保护/base_url/a
,因为其他地址对所有 IP 开放。定义 2 个过滤器。首先允许通过 IP 进行本地访问,其次允许通过 localhost:
<filter>
<filter-name>RemoteAddressFilter</filter-name>
<filter-class>org.apache.catalina.filters.RemoteAddrFilter</filter-class>
<init-param>
<param-name>allow</param-name>
<param-value>127.0.0.1|::1|0:0:0:0:0:0:0:1</param-value>
</init-param>
<init-param>
<param-name>deny</param-name>
<param-value>192\.\d+\.\d+\.\d+</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>RemoteAddressFilter</filter-name>
<url-pattern>/a/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>RemoteHostFilter</filter-name>
<filter-class>org.apache.catalina.filters.RemoteHostFilter</filter-class>
<init-param>
<param-name>allow</param-name>
<param-value>localhost</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>RemoteHostFilter</filter-name>
<url-pattern>/a/*</url-pattern>
</filter-mapping>