1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
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.auth.AuthSettingsUtil;
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 (!AuthSettingsUtil.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  }