我的应用程序在 Websphere 应用程序服务器 9.0.0.9 上运行。我在应用程序的 web.xml 文件中添加了以下安全约束。目的是保护每个请求,无论它是否需要进行身份验证。
<security-constraint>
<web-resource-collection>
<web-resource-name>All</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<user-data-constraint>
<description>Ensure to allow only confidential communication</description>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
<!-- For FORM authentication -->
<login-config>
<auth-method>FORM</auth-method>
<form-login-config>
<form-login-page>/login.jsp</form-login-page>
<form-error-page>/login.jsp?error=true</form-error-page>
</form-login-config>
</login-config>
接下来在我调用的一个 servlet 过滤器中:
if (CommonUtils.isNullOrEmpty(user)) {
response.setHeader( "auth-msg", "auth-required");
request.authenticate(response);
return;
}
在浏览器中,点击 /home url 后,我总是得到一个 200 OK 响应,响应中设置了上述“auth-msg”标头和一个空白页面。预期的行为是将用户带到登录页面,但这并没有发生。“启用应用程序安全性”也在 WAS 控制台中被选中。这里还缺少什么?这里唯一的解决方法是显式点击 login.jsp 页面。登录页面出现,我可以从那里登录,一切正常。但是自动重定向到登录页面并没有发生。相同的设置在 WAS liberty 中运行良好。