我正在使用一个Filter
在我的所有页面中插入反点击劫持标头 - 这可以正常工作,但 JBoss EAP 6.3 容器管理的登录页面除外,这是拥有该功能的更重要的页面之一。
登录页面根本不会调用过滤器,该页面由http://localhost/Application/
。我尝试过的过滤器映射包括
<filter>
<filter-name>InsertXFrameOptions</filter-name>
<filter-class>com.filter.InsertXFrameOptionsFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>InsertXFrameOptions</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>InsertXFrameOptions</filter-name>
<url-pattern>*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>InsertXFrameOptions</filter-name>
<url-pattern>/</url-pattern>
</filter-mapping>
但一点运气都没有 - 如何映射过滤器以使其适用于容器管理的登录页面?
过滤器不启动j_security_check
要求。在访问 Web 应用程序的过滤器之前,它们由容器在内部进行处理。因此,您需要使用特定于容器的解决方案来挂钩请求/响应。
JBoss 6.x/7.x(以及所有其他基于 Tomcat 的容器)提供Valves https://access.redhat.com/documentation/en-US/JBoss_Enterprise_Application_Platform/6.3/html/Development_Guide/chap-Valves.html为了这。基本上,更换你的Filter
by a Valve
which 看起来像下面 https://access.redhat.com/documentation/en-US/JBoss_Enterprise_Application_Platform/6.3/html/Development_Guide/Create_a_Custom_Valve.html:
import org.apache.catalina.connector.Request;
import org.apache.catalina.connector.Response;
import org.apache.catalina.valves.ValveBase;
public class InsertXFrameOptionsValve extends ValveBase {
@Override
public void invoke(Request request, Response response) throws IOException, ServletException {
response.addHeader("X-Frame-Options", "SAMEORIGIN");
getNext().invoke(request, response);
}
}
为了让它运行起来,register https://access.redhat.com/documentation/en-US/JBoss_Enterprise_Application_Platform/6.3/html/Development_Guide/Configure_a_Web_Application_to_use_a_Valve.html it in jboss-web.xml
像下面这样:
<valve>
<class-name>com.example.InsertXFrameOptionsValve</class-name>
</valve>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)