001    /**
002     * Copyright (c) 2000-present 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.CookieKeys;
021    import com.liferay.portal.kernel.util.PropsKeys;
022    import com.liferay.portal.kernel.util.StringPool;
023    import com.liferay.portal.kernel.util.Validator;
024    import com.liferay.portal.util.PortalUtil;
025    import com.liferay.portal.util.PrefsPropsUtil;
026    import com.liferay.portal.util.PropsValues;
027    
028    import javax.servlet.http.Cookie;
029    import javax.servlet.http.HttpServletRequest;
030    import javax.servlet.http.HttpServletResponse;
031    
032    /**
033     * @author Mika Koivisto
034     */
035    public class SiteMinderLogoutAction extends Action {
036    
037            @Override
038            public void run(HttpServletRequest request, HttpServletResponse response) {
039                    try {
040                            long companyId = PortalUtil.getCompanyId(request);
041    
042                            if (!PrefsPropsUtil.getBoolean(
043                                            companyId, PropsKeys.SITEMINDER_AUTH_ENABLED,
044                                            PropsValues.SITEMINDER_AUTH_ENABLED)) {
045    
046                                    return;
047                            }
048    
049                            String domain = CookieKeys.getDomain(request);
050    
051                            Cookie smSessionCookie = new Cookie(_SMSESSION, StringPool.BLANK);
052    
053                            if (Validator.isNotNull(domain)) {
054                                    smSessionCookie.setDomain(domain);
055                            }
056    
057                            smSessionCookie.setMaxAge(0);
058                            smSessionCookie.setPath(StringPool.SLASH);
059    
060                            Cookie smIdentityCookie = new Cookie(_SMIDENTITY, StringPool.BLANK);
061    
062                            if (Validator.isNotNull(domain)) {
063                                    smIdentityCookie.setDomain(domain);
064                            }
065    
066                            smIdentityCookie.setMaxAge(0);
067                            smIdentityCookie.setPath(StringPool.SLASH);
068    
069                            CookieKeys.addCookie(request, response, smSessionCookie);
070                            CookieKeys.addCookie(request, response, smIdentityCookie);
071                    }
072                    catch (Exception e) {
073                            _log.error(e, e);
074                    }
075            }
076    
077            private static final String _SMIDENTITY = "SMIDENTITY";
078    
079            private static final String _SMSESSION = "SMSESSION";
080    
081            private static final Log _log = LogFactoryUtil.getLog(
082                    SiteMinderLogoutAction.class);
083    
084    }