【问题标题】:How to signout programmatically from Liferay custom portlet如何以编程方式从 Liferay 自定义 portlet 中注销
【发布时间】:2012-10-12 10:39:03
【问题描述】:

我正在创建一个自定义 portlet。

在用户在我的自定义 portlet 中执行某些操作后,我需要从门户中注销用户。我正在扩展 liferay 的MVCPortlet

MyPortlet 的一种操作方法中,我需要编写代码以注销用户,然后将其重定向到主页。

更新:
我尝试了以下我认为注销用户但在注销后不会重定向到主页的方法:

actionResponse.sendRedirect(PortalUtil.getPortalURL(actionRequest) + "/c/portal/logout");

谢谢大家

【问题讨论】:

    标签: liferay logout liferay-6


    【解决方案1】:

    嗯,这可能是一个很晚的回复,但它可能会对某人有所帮助

    首先,您必须验证会话并重定向到注销 URL。否则,即使我们重定向到注销 url,会话仍然存在并且用户被移动到登录页面。所以,这是一个人应该做的事情

    HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest);
    request.getSession().invalidate();
    actionResponse.sendRedirect(themeDisplay.getURLSignOut());
    

    希望这会有所帮助。

    【讨论】:

      【解决方案2】:

      我也没有找到使用 liferay 的默认注销 (/c/portal/logout) 发送特定重定向的方法。因此,我使用 util 类 AuthenticatedSessionManagerUtil 以编程方式注销了用户,并且 之后在响应对象中发送特定的重定向位置,例如response.sendRedirect(yourLocation)

      注意: 在 Liferay 7.2 中,我使用了 AuthenticatedSessionManagerUtil.signOutSimultaneousLogins(userId) 而不是 AuthenticatedSessionManagerUtil.logout(userId),这对我不起作用。 hth

      【讨论】:

      • 请在回答问题时尽量说得更清楚。
      【解决方案3】:

      您可以重定向到 c/portal/logout 更准确地说:

      actionResponse.sendRedirect("/c/portal/logout/");

      【讨论】:

      • 我尝试了这个的变体(请参阅我更新的问题),但在调用注销操作后它不会重定向到主页。
      • 然后你必须为你的门户设置默认的注销页面。为此,请转到 Control-->PanelPortal-->Portal Settings,进行编辑,您将看到设置。
      【解决方案4】:

      遇到这个问题(LR7)后就离开这里:

          try {
              AuthenticatedSessionManagerUtil.logout(request, response);
      
              request.setAttribute(WebKeys.LOGOUT, true);
      
          }
      

      【讨论】:

        【解决方案5】:

        你要做的就是

        执行操作:在操作结束时使用:

        HttpSession session = PortalUtil.getHttpServletRequest(request).getSession();
        session.invalidate();
        
        
        try {
            System.out.println(" redirecting to the required page");
                            response.sendRedirect(themeDisplay.getPortalURL() + "/page-on-which-to-be-redirected");
        
            } catch (IOException e1) {
        
                  e1.printStackTrace();
                }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2015-08-07
          • 1970-01-01
          • 2017-08-19
          • 1970-01-01
          • 2013-06-17
          • 1970-01-01
          • 2015-06-19
          • 2011-07-24
          相关资源
          最近更新 更多