如何使欢迎页面不受 websphere 中基于表单的身份验证的保护
How to make welcome page unprotected for form based authentication in websphere
我的欢迎屏幕是任何网站的主屏幕(应该是未受保护的资源)。
说 http://domain:port/myApp 重定向到 web.xml 的欢迎文件列表中配置的 jsp 文件说 welcome.jsp.
但是在点击 welcome.jsp 上的任何 link 时,这些资源必须受到保护,相应的 url 将像 http://:port/myApp/someRequest
我在部署描述符中使用了以下更改:
<security-constraint>
<web-resource-collection>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>SuperUser</role-name>
</auth-constraint>
<user-data-constraint>
<description>Encryption is not required for the application in general.
</description>
<transport-guarantee>NONE</transport-guarantee>
</user-data-constraint>
</security-constraint>
<security-constraint>
<web-resource-collection>
<url-pattern>/styles/*</url-pattern>
<url-pattern>/welcome.jsp</url-pattern>
</web-resource-collection>
</security-constraint>
<login-config>
<auth-method>FORM</auth-method>
<realm-name>MyRealm</realm-name>
<form-login-config>
<form-login-page>/login.jsp</form-login-page>
<form-error-page>/loginerror.jsp</form-error-page>
</form-login-config>
</login-config>
问题仍然是我的主页,即 welcome.jsp 受到保护,应用程序重定向到 WebSphere Application 服务器的登录屏幕,但在 tomcat 和 Wildfly 中工作正常。
如何使 http://:port/myApp 在 WebSphere 中不受保护。
在默认 servlet 处理请求之前,WebContainer 不会确定它是否需要为特定请求使用欢迎页面。当 WebContainer 确定没有 servlet 映射到此请求时,它会将默认 servlet 设置为目标,然后检查是否需要欢迎页面。在为默认 servlet 提供服务之前,WebContainer 调用安全检查,这是将请求 URI 与定义的安全约束进行比较的地方。本场景的请求URI(/myApp)与定义的/*约束相匹配,因此会触发鉴权过程。
这是按设计工作的。为了获得所需的行为,安全约束需要更加具体,而不仅仅是 /*。一种可能性是将所有旨在保护的静态资源保存在一个单独的目录中,并为该目录定义一个约束,例如 /secured/*。对于 servlet,您可以定义一个 servlet 映射模式以用于安全的 servlet,并向您的安全配置添加更具体的约束以匹配该模式,类似于上面的静态资源示例。
我的欢迎屏幕是任何网站的主屏幕(应该是未受保护的资源)。
说 http://domain:port/myApp 重定向到 web.xml 的欢迎文件列表中配置的 jsp 文件说 welcome.jsp.
但是在点击 welcome.jsp 上的任何 link 时,这些资源必须受到保护,相应的 url 将像 http://:port/myApp/someRequest
我在部署描述符中使用了以下更改:
<security-constraint>
<web-resource-collection>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>SuperUser</role-name>
</auth-constraint>
<user-data-constraint>
<description>Encryption is not required for the application in general.
</description>
<transport-guarantee>NONE</transport-guarantee>
</user-data-constraint>
</security-constraint>
<security-constraint>
<web-resource-collection>
<url-pattern>/styles/*</url-pattern>
<url-pattern>/welcome.jsp</url-pattern>
</web-resource-collection>
</security-constraint>
<login-config>
<auth-method>FORM</auth-method>
<realm-name>MyRealm</realm-name>
<form-login-config>
<form-login-page>/login.jsp</form-login-page>
<form-error-page>/loginerror.jsp</form-error-page>
</form-login-config>
</login-config>
问题仍然是我的主页,即 welcome.jsp 受到保护,应用程序重定向到 WebSphere Application 服务器的登录屏幕,但在 tomcat 和 Wildfly 中工作正常。
如何使 http://:port/myApp 在 WebSphere 中不受保护。
在默认 servlet 处理请求之前,WebContainer 不会确定它是否需要为特定请求使用欢迎页面。当 WebContainer 确定没有 servlet 映射到此请求时,它会将默认 servlet 设置为目标,然后检查是否需要欢迎页面。在为默认 servlet 提供服务之前,WebContainer 调用安全检查,这是将请求 URI 与定义的安全约束进行比较的地方。本场景的请求URI(/myApp)与定义的/*约束相匹配,因此会触发鉴权过程。
这是按设计工作的。为了获得所需的行为,安全约束需要更加具体,而不仅仅是 /*。一种可能性是将所有旨在保护的静态资源保存在一个单独的目录中,并为该目录定义一个约束,例如 /secured/*。对于 servlet,您可以定义一个 servlet 映射模式以用于安全的 servlet,并向您的安全配置添加更具体的约束以匹配该模式,类似于上面的静态资源示例。