001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.events;
016    
017    import com.liferay.portal.kernel.events.Action;
018    import com.liferay.portal.kernel.log.Log;
019    import com.liferay.portal.kernel.log.LogFactoryUtil;
020    import com.liferay.portal.kernel.util.StringPool;
021    import com.liferay.portal.kernel.util.Validator;
022    import com.liferay.portal.security.ldap.LDAPSettingsUtil;
023    import com.liferay.portal.util.CookieKeys;
024    import com.liferay.portal.util.PortalUtil;
025    
026    import javax.servlet.http.Cookie;
027    import javax.servlet.http.HttpServletRequest;
028    import javax.servlet.http.HttpServletResponse;
029    
030    /**
031     * @author Mika Koivisto
032     */
033    public class SiteMinderLogoutAction extends Action {
034    
035            public void run(HttpServletRequest request, HttpServletResponse response) {
036                    try {
037                            long companyId = PortalUtil.getCompanyId(request);
038    
039                            if (!LDAPSettingsUtil.isSiteMinderEnabled(companyId)) {
040                                    return;
041                            }
042    
043                            String domain = CookieKeys.getDomain(request);
044    
045                            Cookie smSessionCookie = new Cookie(_SMSESSION, StringPool.BLANK);
046    
047                            if (Validator.isNotNull(domain)) {
048                                    smSessionCookie.setDomain(domain);
049                            }
050    
051                            smSessionCookie.setMaxAge(0);
052                            smSessionCookie.setPath(StringPool.SLASH);
053    
054                            Cookie smIdentityCookie = new Cookie(_SMIDENTITY, StringPool.BLANK);
055    
056                            if (Validator.isNotNull(domain)) {
057                                    smIdentityCookie.setDomain(domain);
058                            }
059    
060                            smIdentityCookie.setMaxAge(0);
061                            smIdentityCookie.setPath(StringPool.SLASH);
062    
063                            CookieKeys.addCookie(request, response, smSessionCookie);
064                            CookieKeys.addCookie(request, response, smIdentityCookie);
065                    }
066                    catch (Exception e) {
067                            _log.error(e, e);
068                    }
069            }
070    
071            private static final String _SMSESSION = "SMSESSION";
072    
073            private static final String _SMIDENTITY = "SMIDENTITY";
074    
075            private static Log _log = LogFactoryUtil.getLog(
076                    SiteMinderLogoutAction.class);
077    
078    }