Java 使用负载均衡器将 https 转换为 http 的 EE 表单登录

Java EE form login with load balancer transforming https to http

我有一个问题,我认为这归结为与我们的负载平衡器、网络服务器 (ihs)、https 配置和 Java EE 表单安全性不匹配 j_security_check.

我了解当客户端尝试访问安全页面时,服务器 (websphere) 会发送带有登录表单 url 的重定向,这是我们在开发和测试环境中看到的。然而,生产设置有一个网络服务器 (ihs),它使用 https url,删除 s 并将 http url 转发到 websphere(称为 ssl 卸载)。当 Websphere 回复重定向时,它会在没有 https 的情况下使用 http://server-name/loginform 我看到一个浏览器错误,它无法访问 http://server-name/loginform

web.xml的相关部分:

<security-constraint>
  <web-resource-collection>
    <web-resource-name>Whitelist</web-resource-name>
    <url-pattern>/*</url-pattern>
  </web-resource-collection>
   <auth-constraint>
    <role-name>authenticated-users</role-name>
  </auth-constraint>
</security-constraint>
  <security-constraint>
  <web-resource-collection>
    <web-resource-name>login</web-resource-name>
    <url-pattern>/keepalive</url-pattern>
    <url-pattern>/signin</url-pattern>
    <url-pattern>/signin/error</url-pattern>
    <url-pattern>/resources/*</url-pattern>
  </web-resource-collection>
</security-constraint>
<security-role>
  <description>Any LDAP authenticated user</description>
  <role-name>authenticated-users</role-name>
</security-role>
<login-config>
  <auth-method>FORM</auth-method>
  <form-login-config>
    <form-login-page>/signin</form-login-page>
    <form-error-page>/signin/error</form-error-page>
  </form-login-config>
</login-config>

我想知道这是否是 java 方面的配置错误(我的责任),我希望 form-login-page (/login) 中的 url 在浏览器上是相对的.但我也认为负载平衡器应该自动将 http call 转换为 https call (其他人的责任)。希望有人给点建议。

您应该在您的问题中提供更多信息,例如您使用的是什么负载平衡器,它是直接进入 WAS 还是通过 IHS,您的 Web 应用程序是如何配置的 (web.xml)。

所以这里有一些可能对您有用的一般提示。

在 WebSphere 中重定向到 SSL

如果您已经配置了安全性并且在 http 中正确显示了登录表单,则只需将以下内容添加到 web.xml

<security-constraint>
...
    <user-data-constraint>
        <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint>
</security-constraint>

这将确保当客户端尝试访问受保护的页面时,WebSphere 将生成到 https 的重定向。

SSL 卸载

如果您的负载平衡器配置为使用纯 http 将 SSL 和转发请求卸载到 WebSphere,那么您需要配置 WebSphere 以了解这一点。这是通过配置 httpsIndicatorHeader 自定义 属性 并在负载均衡器中添加自定义 header 来完成的。