第 17 章 配置 Web 服务器(Undertow)
17.1. Undertow 子系统概述 复制链接链接已复制到粘贴板!
在 JBoss EAP 7 中,undertow 子系统取代了 JBoss EAP 6 中的 Web 子系统。
undertow 子系统可用于配置 Web 服务器和 servlet 容器设置。它实施 Jakarta Servlet 4.0 规范和 websocket。它还支持 HTTP 升级,并在 servlet 部署中使用高性能非阻塞处理程序。undertow 子系统也能够充当支持 mod_cluster 的高性能反向代理。
在 undertow 子系统内,需要配置五个主要组件:
尽管 JBoss EAP 确实提供了更新每个组件的配置,但默认配置适用于大多数用例,并且提供合理的性能设置。
默认 Undertow 子系统配置
undertow 子系统也依赖于 io 子系统来提供 XNIO 工作线程和缓冲区池。The io 子系统单独配置,提供默认配置,这在大部分情形中都能提供最佳性能。
与 JBoss EAP 6 中的 Web 子系统相比,JBoss EAP 7 中的 undertow 子系统具有不同的 HTTP 方法默认行为。
将 Elytron 与 Undertow 子系统搭配使用
部署 Web 应用时,将识别该应用所需的安全域名称。这可以来自部署内部,或者部署没有安全域,则将假定 undertow 子系统中定义的 default-security-domain。默认情况下,假定安全域映射到旧安全子系统中定义的 PicketBox。不过,可以将 application-security-domain 资源添加到 undertow 子系统中,该子系统从应用所需的安全域名称映射到适当的 Elytron 配置。
示例:添加映射.
/subsystem=undertow/application-security-domain=ApplicationDomain:add(security-domain=ApplicationDomain)
/subsystem=undertow/application-security-domain=ApplicationDomain:add(security-domain=ApplicationDomain)
如果结果为:
- 如果此时部署部署,应重新加载应用服务器,使应用安全域映射生效。
- 在当前的 Web service-Elytron 集成中,为保护 Web 服务端点而指定的安全域名称,Elytron 安全域名必须相同。
这种简单形式适合在部署中使用 Servlet 规范中定义的标准 HTTP 机制,如 BASIC、CLIENT_CERT、DIGEST、FORM。此处将对 ApplicationDomain 安全域 进行身份验证。此表单也适用于应用不使用任何身份验证机制,而是使用编程身份验证,或者试图获取与部署关联的 SecurityDomain 并直接使用。
示例:映射的高级表单:
/subsystem=undertow/application-security-domain=MyAppSecurity:add(http-authentication-factory=application-http-authentication)
/subsystem=undertow/application-security-domain=MyAppSecurity:add(http-authentication-factory=application-http-authentication)
如果结果为:
在这种配置形式中,引用 http-authentication-factory,而不是引用安全域。这是用于获取身份验证机制实例且与安全域关联的工厂。
在使用自定义 HTTP 身份验证机制时,或者必须针对主体转换器、凭据工厂和机制域等机制定义其他配置时,您应该引用 http-authentication-factory 属性。在使用 Servlet 规范中描述的四种机制之外,最好使用 http-authentication-factory 属性引用 http-authentication-factory 属性。
使用高级形式的映射时,可以使用另一个配置选项 override-deployment-config。引用的 http-authentication-factory 可以返回一整套身份验证机制。默认情况下,这些将被过滤为仅与应用请求的机制匹配。如果此选项设为 true,则工厂提供的机制将覆盖应用请求的机制。
application-security-domain 资源还有一个额外的选项 enable-jacc。如果设置为 true,则 对于与此映射匹配的任何部署,将启用 JACC。
Runtime Information
如果使用 application-security-domain 映射,可以重复检查部署是否按预期与其匹配。如果资源使用 include-runtime=true 读取,与映射关联的部署也将显示为:
在此输出中,reference -deployments 属性显示已使用该映射部署了 simple-webapp.war 部署。