Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 从支持bean导航到外部URL?_Java_Jsf_Jsf 2_Primefaces_Siteminder - Fatal编程技术网

Java 从支持bean导航到外部URL?

Java 从支持bean导航到外部URL?,java,jsf,jsf-2,primefaces,siteminder,Java,Jsf,Jsf 2,Primefaces,Siteminder,我正在尝试为我的JavaEE/JSF2应用程序实现正确的注销 它需要两件事: 我需要从JAAS注销并使会话无效 然后,我必须导航到一个外部URL以启动Siteminder注销 Siteminder注销URL(在策略服务器上配置->我无法更改)不在我的应用程序上下文中。如果我的webapp URL为,则注销URL为 这是当前本地注销代码: public void logout() { System.out.println("Logging out..."); HttpServlet

我正在尝试为我的JavaEE/JSF2应用程序实现正确的注销

它需要两件事:

  • 我需要从JAAS注销并使会话无效
  • 然后,我必须导航到一个外部URL以启动Siteminder注销
  • Siteminder注销URL(在策略服务器上配置->我无法更改)不在我的应用程序上下文中。如果我的webapp URL为,则注销URL为

    这是当前本地注销代码:

    public void logout() {
        System.out.println("Logging out...");
        HttpServletRequest request = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
        try {
            request.logout();
        } catch (ServletException e) {
            e.printStackTrace();
        }
        HttpSession session = (HttpSession)FacesContext.getCurrentInstance().getExternalContext().getSession(false);
        if (session != null) {
            session.invalidate();
        }
    }
    
    以下是生成注销URL的属性:

    public String getLogoutUrl() {
        HttpServletRequest request = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
        String requestServer = request.getServerName();
        String requestScheme = request.getScheme();
        int serverPort = request.getServerPort();
        String logoutUrl = requestScheme + "://" + requestServer + ":" + Integer.toString(serverPort) + "/anotherwebapp/logout.html";
        return logoutUrl;
    }
    
    但是,我找不到可以调用logout()然后打开外部URL的JSF2/Primefaces组件。例如,如果我有:

    <h:outputLink value="#{authBean.logoutUrl}" onclick="#{authBean.logout()}">[Logout]</h:outputLink>
    
    [注销]
    
    那么onclick似乎没有被调用

    我尝试的另一种方法是将外部URL放在注销函数的末尾,使其作为导航字符串返回,但无法识别(也尝试了使用“?faces redirect=true”…)


    非常感谢您的帮助。

    您可以创建一个logout.xhtml页面,因此代码如下所示:

    public String getLogoutUrl() {
        return "/logout.jsf";
    }
    
    并在页面中添加:

    <META HTTP-EQUIV="Refresh" CONTENT="0;URL=https://localhost:8080/anotherwebapp/logout.html">
    
    
    
    您也可以直接使用

    不需要中间页面和元刷新

    public void logout() throws ServletException, IOException {
        ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
        ((HttpServletRequest) ec.getRequest()).logout();
        ec.invalidateSession();
        ec.redirect("http://example.com/anothercontext/logout");
    }