title: liferay: how to first force logout in autologin hook
body: <p>Apparantely liferay does not log the currently logged in user if you try to login again, and in fact even keeps the currently logged in user logged in.
  So I'm trying to force a logout.</p>
  
  <p>I tried:</p>
  
  <pre><code>request.getSession().invalidate();
  </code></pre>
  
  <p>But that does not seem to work besides somehow breaking the login functionality.</p>
  
  <p>I was wondering if anyone has any other idea how to force a logout.</p>
  
  <p>Edit:</p>
  
  <pre><code>try {
              HttpSession session = request.getSession();
  
              EventsProcessorUtil.process(PropsKeys.LOGOUT_EVENTS_PRE,
                      PropsUtil.getArray(PropsKeys.LOGOUT_EVENTS_PRE), request, response);
  
              String domain = CookieKeys.getDomain(request);
  
              Cookie companyIdCookie = new Cookie(CookieKeys.COMPANY_ID,
                      StringPool.BLANK);
  
              if (Validator.isNotNull(domain)) {
                  companyIdCookie.setDomain(domain);
              }
  
              companyIdCookie.setMaxAge(0);
              companyIdCookie.setPath(StringPool.SLASH);
  
              Cookie idCookie = new Cookie(CookieKeys.ID, StringPool.BLANK);
  
              if (Validator.isNotNull(domain)) {
                  idCookie.setDomain(domain);
              }
  
              idCookie.setMaxAge(0);
              idCookie.setPath(StringPool.SLASH);
  
              Cookie passwordCookie = new Cookie(CookieKeys.PASSWORD,
                      StringPool.BLANK);
  
              if (Validator.isNotNull(domain)) {
                  passwordCookie.setDomain(domain);
              }
  
              passwordCookie.setMaxAge(0);
              passwordCookie.setPath(StringPool.SLASH);
  
              CookieKeys.addCookie(request, response, companyIdCookie);
              CookieKeys.addCookie(request, response, idCookie);
              CookieKeys.addCookie(request, response, passwordCookie);
  
              try {
                  session.invalidate();
              } catch (Exception e) {
              }
  
              EventsProcessorUtil.process(PropsKeys.LOGOUT_EVENTS_POST,
                      PropsUtil.getArray(PropsKeys.LOGOUT_EVENTS_POST), request, response);
          } catch (Exception e) {
              try {
                  PortalUtil.sendError(e, request, response);
              } catch (IOException e1) {
                  // TODO Auto-generated catch block
                  e1.printStackTrace();
              } catch (ServletException e1) {
                  // TODO Auto-generated catch block
                  e1.printStackTrace();
              }
          }
  </code></pre>
  
  <p>Gives noclassdeffounderrors on cookiekeys/processorserviceutil/... depending on which I replace with a more base level. (like processorserviceutil with a processorserviceimpl and copy the function code from proeccesorserviceutil).</p>