websphere liberty - 在没有用户身份验证的情况下为站点强制使用 https

websphere liberty - Force https for site without user authentication

我想将 websphere liberty 配置文件配置为仅通过 https 提供页面。特别是,应该阻止对 http 的请求,或者将其重定向到 https。

我在web.xml中设置了<security-constraint>如下:

<security-constraint>
    <display-name>UserConstraint</display-name>

    <web-resource-collection>
        <web-resource-name>UserCollection</web-resource-name>
        <url-pattern>/*</url-pattern>
        <http-method>GET</http-method>
        <http-method>PUT</http-method>
        <http-method>HEAD</http-method>
        <http-method>TRACE</http-method>
        <http-method>POST</http-method>
        <http-method>DELETE</http-method>
        <http-method>OPTIONS</http-method>
    </web-resource-collection>
    <user-data-constraint>
        <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint>
</security-constraint>

我还添加了 [ssl-1.0] 功能和默认密钥库。这会导致 HTTPS 正常工作,但是仍然可以通过 HTTP 访问所有页面(它不会重定向或阻止)。

接下来我添加了功能 [appSecurity-2.0],这会导致 HTTP 正确重定向到 HTTPS。但是,我在控制台中看到以下错误:

[ERROR   ] CWWKS3005E: A configuration exception has occurred. No UserRegistry implementation service is available.  Ensure that you have a user registry configured.

如前所述,我没有在 server.xml 中设置用户注册表,因为身份验证是在应用程序本身中完成的。在不更改应用程序以使用用户注册表的情况下,应该如何解决此错误?

此外,web.xml 是否需要任何其他配置来阻止通过 HTTP 访问?我还以为 <security-constraint> 就够了?

编辑:我正在发送基本身份验证 header 以进行身份​​验证,以防不清楚。

最简单的做法是在 server.xml:

中禁用 http 端口

<httpEndpoint id="defaultHttpEndpoint" httpPort="-1"/>

<basicRegistry></basicRegistry> 添加到您的 server.xml。它不会被您的应用程序使用,因为您的 security-constraint 没有定义任何 auth-constraint.

关于您的其他评论:
这可能是服务器试图解释您的基本身份验证 header 而未在注册表中找到用户的结果。

但是,如果您无论如何都在使用基本身份验证,则可以通过保护您的 Web 模块来允许服务器创建该请求,而不是使用基本注册表,将您的自定义注册表实现为 Liberty 功能,从而受益,请参阅 Developing a custom user registry for the Liberty profile

在你的 web.xml 添加:

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

这将重定向到 https。