我正在使用JDBCRealm在我的网络应用中进行身份验证和授权。关于身份验证,我使用FORM与j_security_check服务。我已经配置了所有内容,包括HTTP状态403错误页面,如果用户没有访问资源所需的权限,用户将被重定向。到目前为止,一切正常。返回HTTP状态403错误时会出现此问题。在我看来,尽管用户尚未获得授权,但只要他/她已成功通过身份验证,仍会为该用户创建JSF会话。现在,当我尝试返回登录页面并输入有权访问资源的用户的密码和用户名时,它无法授权,因为授权仍然被应用于持有当前会话但显然没有必要的许可。现在我需要知道的是如何销毁或无效返回HTTP状态403时创建的会话。谢谢
更新:我认为重要的是要提到当会话超时时,我现在能够登录具有所需权限的用户。只是一个提示...
答案 0 :(得分:1)
简单!! ...您可以在Web.xml
只需在Web.xml
中定义错误代码,那么当您的视图页面被加载时会发生什么?如果抛出403
意味着将自动调用定义的错误页面。
<强>代码:强>
<error-code>403</error-code>
<location>/error.xhtml</location>
</error-page>
在错误页面中..你可以做你想要的东西..
要杀死当前会话,最好的方法是invalidate session through FacesContext
HttpServletRequest request=HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
执行代码后,currect session
将被终止
答案 1 :(得分:0)
我遇到了同样的问题,但我使用了检票口。因此将以下JSP定义为错误页面:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>User Authorization Error (403)</title>
</head>
<body>
<%
String userName = "<No User>";
String contextPath = request.getContextPath ();
java.security.Principal principal = request.getUserPrincipal ();
if (principal != null) userName = principal.getName ();
request.getSession ().invalidate ();
%>
<h2>The user '<%=userName %>' is not authorized to access the page</h2>
<p>
<a href="<%= contextPath %>/protected">Login again with an authorized user</a>
</p>
</body>
</html>