代码之家  ›  专栏  ›  技术社区  ›  Alex Mi

在JBoss EAP 7中配置Http标头

  •  7
  • Alex Mi  · 技术社区  · 7 年前

    您知道有没有标准的方法来配置JBoss EAP 7发送给客户端的Http头? 我主要感兴趣的是能够配置以下各项:

    • X-XSS-保护
    • X帧选项
    • 严格的运输安全
    • 内容安全策略
    • X-内容-类型-选项

    我在互联网上找到了这个链接

    https://blog.akquinet.de/2017/08/03/wildfly-8-10-and-jboss-eap-7-verbose-http-headers/

    但我不确定是否可以将其用于我感兴趣的标题。

    非常感谢。

    2 回复  |  直到 6 年前
        1
  •  12
  •   JGlass    7 年前

    根据JBoss EAP 7文档:

    JBoss EAP的早期版本支持阀门。阀是在servlet过滤器之前插入到应用程序的请求处理管道中的自定义类,用于更改请求或执行其他处理。全局阀插入到所有已部署应用程序的请求处理管道中。验证器阀对请求的凭据进行身份验证。阀门是通过扩展组织创建的。阿帕奇。卡特琳娜。阀门。ValveBase类,并在jboss web的元素中配置。xml描述符文件。

    Undertow取代JBoss EAP 7中的JBoss Web,不支持阀门;但是,您应该能够通过使用底拖处理程序实现类似的功能。Undertow包括许多提供通用功能的内置处理程序。它还提供了创建自定义处理程序的能力,可用于替换自定义阀功能。

    对于复杂的情况,您仍然可以走这条路线,但是现在在使用Undertow时,添加响应头被简化了,因为您只需将自定义头添加到JBoss Undertow子系统,您的过滤器部分将改变如下:

    <filters>
        <response-header name="server-header" header-name="Server" header-value="JBoss-EAP/7"/>
        <response-header name="x-powered-by-header" header-name="X-Powered-By" header-value="Undertow/1"/>
    </filters>
    


    对此:

    <filters>
        <response-header name="server-header" header-name="Server" header-value="JBoss-EAP/7"/>
        <response-header name="x-powered-by-header" header-name="X-Powered-By" header-value="Undertow/1"/>
        <!-- Begin custom Headers -->
        <response-header name="x-xss-protection" header-name="X-XSS-Protection" header-value=""/>
        <response-header name="x-frame-options" header-name="X-Frame-Options" header-value=""/>
        <response-header name="strict-transport-security" header-name="Strict-Transport-Security" header-value=""/>
        <response-header name="content-security-policy" header-name="Content-Security-Policy" header-value=""/>
        <response-header name="x-Content-type-options" header-name="X-Content-Type-Options" header-value=""/>
    </filters>
    

    我会让其他人来决定他们要为标题放置的值(在复制/粘贴过程中保存一些编辑)

        2
  •  3
  •   zichen.L    5 年前

    查看Jboss EAP 7的链接: Configuring Filters

    打开您的 standalone.xml 在JBoss EAP 7目录中搜索“ urn:jboss:domain:undertow “在此xml中,然后添加自定义筛选规则,如:

    <filters>
      <response-header name="server-header" header-name="Server" header-value="JBoss-EAP/7"/>
      <response-header name="x-powered-by-header" header-name="X-Powered-By" header-value="Undertow/1"/>
      <!--your custom rules in detail-->
      <response-header name="x-frame-options" header-name="X-Frame-Options" header-value=""/>
    </filters>
    

    别忘了添加 <filter-ref name="x-frame-options"/> 在里面

    <subsystem xmlns="urn:jboss:domain:undertow:4.0">
    <host name="default-host" alias="localhost">
                    <location name="/" handler="welcome-content"/>
                    <filter-ref name="server-header"/>
                    <filter-ref name="x-powered-by-header"/>
                    <!--declare your custom rules here-->
                    <filter-ref name="x-frame-options"/>
                    <single-sign-on http-only="true" secure="true"/>
                    <http-invoker security-realm="ApplicationRealm"/>
     </host>
    </subsystem>