首页 文章

如何破坏Http状态403后创建的JSF会话

提问于
浏览
0

我正在使用JDBCRealm在我的Web应用程序中进行身份验证和授权 . 关于身份验证,我使用FORM与j_security_check服务 . 我已经配置了所有内容,包括HTTP状态403错误页面,如果用户没有访问资源所需的权限,用户将被重定向 . 到目前为止,一切正常 . 返回HTTP状态403错误时会出现此问题 . 在我看来,尽管用户尚未获得授权,但只要他/她已成功通过身份验证,仍会为该用户创建JSF会话 . 现在,当我尝试返回登录页面并输入有权访问资源的用户的密码和用户名时,它无法授权,因为授权仍然被应用于持有当前会话但显然没有必要的许可 . 现在我需要知道的是如何销毁或无效返回HTTP状态403时创建的会话 . 谢谢

更新:我认为重要的是要提到当会话超时时,我现在能够登录具有所需权限的用户 . 只是一个提示......

2 回答

  • 1

    简单!! ...你可以在 Web.xml 配置它

    只需在 Web.xml 中定义错误代码,那么当您加载视图页面时会发生什么情况如果抛出 403 意味着将自动调用定义的错误页面 .

    Code:

    <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 将被终止

  • 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>
    

相关问题