我的应用程序是一个 Java EE 6 应用程序,在 Glassfish 3.0.1 上运行。
我正在使用带有 JDBC 领域的 Java EE Security。所以我对我的一些网页添加了限制。我在 web.xml 中添加了以下登录配置和安全约束:
<!-- Redirect access of restricted pages to index.jsp -->
<login-config>
<auth-method>FORM</auth-method>
<realm-name>jdbc</realm-name>
<form-login-config>
<form-login-page>/index.jsp?login=login</form-login-page>
<form-error-page>/index.jsp?login=error</form-error-page>
</form-login-config>
</login-config>
<!-- Restrict access for deanery related resources -->
<security-constraint>
<display-name>Deanery Constraint</display-name>
<web-resource-collection>
<web-resource-name>Deanery Content</web-resource-name>
<description />
<url-pattern>/deanery/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<description />
<role-name>DEANERY</role-name>
</auth-constraint>
</security-constraint>
如果用户注销,这可以正常工作。如果他试图访问 /deanery/ 中的页面,他会被重定向到 index.jsp(重定向到 jsf)。
当用户登录并获得正确的角色时,他可以成功访问受限资源。所以一切都很好,直到这里。
现在的问题:当具有较少权限的用户(在我的示例中为学生)登录应用程序并尝试访问受限页面时,他不会被重定向到我的 web.xml 中配置的错误页面。相反,他看到的是一个丑陋的 Glassfish 403 页面:
HTTP 状态 403 - 访问请求的资源已被拒绝
不幸的是,似乎没有选项可以在我的CustomExceptionHandler中捕获异常。它甚至没有显示在我的 server.log 中(尽管我切换到了最好的级别)。
我该怎么做才能将用户重定向到我的错误页面,而不是显示 403 页面?为什么用户没有被重定向到 index.jsp,就像他退出时一样???
编辑:
刚刚尝试将带有相应代码的错误页面添加到我的 web.xml 中。
<error-page>
<error-code>403</error-code>
<location>/index.jsp?login=login</location>
</error-page>
没有效果,仍然是 Glassfish 错误页面而不是我自己的。