1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.events;
16  
17  import com.liferay.portal.kernel.events.Action;
18  import com.liferay.portal.kernel.log.Log;
19  import com.liferay.portal.kernel.log.LogFactoryUtil;
20  import com.liferay.portal.kernel.util.StringPool;
21  import com.liferay.portal.kernel.util.Validator;
22  import com.liferay.portal.security.ldap.LDAPSettingsUtil;
23  import com.liferay.portal.util.CookieKeys;
24  import com.liferay.portal.util.PortalUtil;
25  
26  import javax.servlet.http.Cookie;
27  import javax.servlet.http.HttpServletRequest;
28  import javax.servlet.http.HttpServletResponse;
29  
30  /**
31   * <a href="SiteMinderLogoutAction.java.html"><b><i>View Source</i></b></a>
32   *
33   * @author Mika Koivisto
34   */
35  public class SiteMinderLogoutAction extends Action {
36  
37      public void run(HttpServletRequest request, HttpServletResponse response) {
38          try {
39              long companyId = PortalUtil.getCompanyId(request);
40  
41              if (!LDAPSettingsUtil.isSiteMinderEnabled(companyId)) {
42                  return;
43              }
44  
45              String domain = CookieKeys.getDomain(request);
46  
47              Cookie smSessionCookie = new Cookie(_SMSESSION, StringPool.BLANK);
48  
49              if (Validator.isNotNull(domain)) {
50                  smSessionCookie.setDomain(domain);
51              }
52  
53              smSessionCookie.setMaxAge(0);
54              smSessionCookie.setPath(StringPool.SLASH);
55  
56              Cookie smIdentityCookie = new Cookie(_SMIDENTITY, StringPool.BLANK);
57  
58              if (Validator.isNotNull(domain)) {
59                  smIdentityCookie.setDomain(domain);
60              }
61  
62              smIdentityCookie.setMaxAge(0);
63              smIdentityCookie.setPath(StringPool.SLASH);
64  
65              CookieKeys.addCookie(request, response, smSessionCookie);
66              CookieKeys.addCookie(request, response, smIdentityCookie);
67          }
68          catch (Exception e) {
69              _log.error(e, e);
70          }
71      }
72  
73      private static final String _SMSESSION = "SMSESSION";
74  
75      private static final String _SMIDENTITY = "SMIDENTITY";
76  
77      private static Log _log = LogFactoryUtil.getLog(
78          SiteMinderLogoutAction.class);
79  
80  }