1   /**
2    * Copyright (c) 2000-2009 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   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portal.events;
21  
22  import com.liferay.portal.kernel.events.Action;
23  import com.liferay.portal.kernel.log.Log;
24  import com.liferay.portal.kernel.log.LogFactoryUtil;
25  import com.liferay.portal.kernel.util.StringPool;
26  import com.liferay.portal.kernel.util.Validator;
27  import com.liferay.portal.security.ldap.PortalLDAPUtil;
28  import com.liferay.portal.util.CookieKeys;
29  import com.liferay.portal.util.PortalUtil;
30  
31  import javax.servlet.http.Cookie;
32  import javax.servlet.http.HttpServletRequest;
33  import javax.servlet.http.HttpServletResponse;
34  
35  /**
36   * <a href="SiteMinderLogoutAction.java.html"><b><i>View Source</i></b></a>
37   *
38   * @author Mika Koivisto
39   *
40   */
41  public class SiteMinderLogoutAction extends Action {
42  
43      public void run(HttpServletRequest request, HttpServletResponse response) {
44          try {
45              long companyId = PortalUtil.getCompanyId(request);
46  
47              if (!PortalLDAPUtil.isSiteMinderEnabled(companyId)) {
48                  return;
49              }
50  
51              String domain = CookieKeys.getDomain(request);
52  
53              Cookie smSessionCookie = new Cookie(_SMSESSION, StringPool.BLANK);
54  
55              if (Validator.isNotNull(domain)) {
56                  smSessionCookie.setDomain(domain);
57              }
58  
59              smSessionCookie.setMaxAge(0);
60              smSessionCookie.setPath(StringPool.SLASH);
61  
62              Cookie smIdentityCookie = new Cookie(_SMIDENTITY, StringPool.BLANK);
63  
64              if (Validator.isNotNull(domain)) {
65                  smIdentityCookie.setDomain(domain);
66              }
67  
68              smIdentityCookie.setMaxAge(0);
69              smIdentityCookie.setPath(StringPool.SLASH);
70  
71              CookieKeys.addCookie(request, response, smSessionCookie);
72              CookieKeys.addCookie(request, response, smIdentityCookie);
73          }
74          catch (Exception e) {
75              _log.error(e, e);
76          }
77      }
78  
79      private static final String _SMSESSION = "SMSESSION";
80  
81      private static final String _SMIDENTITY = "SMIDENTITY";
82  
83      private static Log _log =
84          LogFactoryUtil.getLog(SiteMinderLogoutAction.class);
85  
86  }