【问题标题】:SessionListener sessionDestroyed not called未调用 SessionListener sessionDestroyed
【发布时间】:2014-02-20 14:39:02
【问题描述】:

似乎我在 XPages 中遇到了 SessionListener 实现。创建会话时,侦听器将输出打印到日志中,因此我知道它已正确注册。但是,它不会在注销时调用 sessionDestroyed。是否需要执行任何特殊的 URL 重定向才能在注销后立即销毁 Domino / XPage 会话?如您所见,我已尝试清除范围,并清除 cookie 以尝试触发 sessionDestroyed 方法。请注意,当我重新启动 http 服务器任务时确实会调用 sessionDestroyed,因此会话可能会一直持续到不活动超时。

Dev Server 为:9.0.1(64 位,Win7 本地运行) 运行基于会话的身份验证单服务器(注意:我尝试了基本身份验证,同样的问题)

注销实用方法(由 SSJS 调用):

    public static void logout(){


    String url = XSPUtils.externalContext().getRequestContextPath() + "?logout&redirectto=" + externalContext().getRequestContextPath();
    XSPUtils.getRequest().getSession(false).invalidate();

    //wipe out the cookies
    for(Cookie cookie : getCookies()){
        cookie.setValue("");
        cookie.setPath("/");
        cookie.setMaxAge(0);
        XSPUtils.getResponse().addCookie(cookie);
    }

    try {
        XSPUtils.externalContext().redirect(url);
    } catch (IOException e) {
        logger.log(Level.SEVERE,null,e);
    }
}

简单的会话监听器:

public class MySessionListener implements SessionListener {

public void sessionCreated(ApplicationEx arg0, HttpSessionEvent event) {
    System.out.println("***sessionCreated***");

}

public void sessionDestroyed(ApplicationEx arg0, HttpSessionEvent event) {
    System.out.println("***sessionDestroyed***");
}

}

【问题讨论】:

  • 感谢您的反馈。我在研究这个问题时确实找到了那个帖子。我的问题不在于会话创建或注册侦听器(sessionCreated 正在触发)。在使 HttpSession 无效并执行注销重定向后与 sessionDestroy 相关。在我重新启动 http 和/或等待超时之前,该方法不会触发。
  • 你试过ExtLib Logout Control吗?
  • 感谢您的信息。我循环浏览了本教程,并在 ExtLib 登录/注销时遇到了同样的问题(调用了 sessionCreated,未调用 sessionDestroyed)。注销控件使用我已经调用的相同 URL。 Domino 会按计划收回 httpsession,还是应该立即发生?

标签: xpages


【解决方案1】:

我们正在考虑将传统的 http 堆栈“?logout”行为与 XPages 运行时会话管理层相结合。目前,会话会根据会话超时到期和/或 http 堆栈重新启动而被丢弃。如果您想强制删除会话并调用 SessionListener.sessionDestroyed,请参阅以下 XSP 片段 - 这同样适用于移植到 Java:

<xp:button value="Logout" id="button2">
    <xp:eventHandler event="onclick" submit="true"
        refreshMode="complete">
        <xp:this.action>
            <![CDATA[#{javascript:
                // things we need...
                var externalContext = facesContext.getExternalContext();
                var request = externalContext.getRequest();
                var response = externalContext.getResponse();
                var currentContext = com.ibm.domino.xsp.module.nsf.NotesContext.getCurrent();
                var session = request.getSession(false);
                var sessionId = session.getId();

                // flush the cookies and invalidate the HTTP session...
                for(var cookie in request.getCookies()){
                    cookie.setValue("");
                    cookie.setPath("/");
                    cookie.setMaxAge(0);
                    response.addCookie(cookie);
                }
                session.invalidate();

                // now nuke the XSP session from RAM, then jump to logout...
                currentContext.getModule().removeSession(sessionId);
                externalContext.redirect("http://foo/bar.nsf?logout");
            }]]>
        </xp:this.action>
    </xp:eventHandler>
</xp:button>

【讨论】:

  • 将您的 ssjs sn-p 移植到我的注销 java 方法中,现在在注销时调用我的侦听器。谢谢!您也应该在 XSnippets 上发布此内容。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-12-29
  • 1970-01-01
  • 2017-05-27
  • 2014-02-06
  • 1970-01-01
  • 2011-09-21
  • 2013-10-03
相关资源
最近更新 更多