001    /**
002     * Copyright (c) 2000-2013 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.StringPool;
022    import com.liferay.portal.kernel.util.Validator;
023    import com.liferay.portal.security.auth.AuthSettingsUtil;
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            @Override
036            public void run(HttpServletRequest request, HttpServletResponse response) {
037                    try {
038                            long companyId = PortalUtil.getCompanyId(request);
039    
040                            if (!AuthSettingsUtil.isSiteMinderEnabled(companyId)) {
041                                    return;
042                            }
043    
044                            String domain = CookieKeys.getDomain(request);
045    
046                            Cookie smSessionCookie = new Cookie(_SMSESSION, StringPool.BLANK);
047    
048                            if (Validator.isNotNull(domain)) {
049                                    smSessionCookie.setDomain(domain);
050                            }
051    
052                            smSessionCookie.setMaxAge(0);
053                            smSessionCookie.setPath(StringPool.SLASH);
054    
055                            Cookie smIdentityCookie = new Cookie(_SMIDENTITY, StringPool.BLANK);
056    
057                            if (Validator.isNotNull(domain)) {
058                                    smIdentityCookie.setDomain(domain);
059                            }
060    
061                            smIdentityCookie.setMaxAge(0);
062                            smIdentityCookie.setPath(StringPool.SLASH);
063    
064                            CookieKeys.addCookie(request, response, smSessionCookie);
065                            CookieKeys.addCookie(request, response, smIdentityCookie);
066                    }
067                    catch (Exception e) {
068                            _log.error(e, e);
069                    }
070            }
071    
072            private static final String _SMIDENTITY = "SMIDENTITY";
073    
074            private static final String _SMSESSION = "SMSESSION";
075    
076            private static Log _log = LogFactoryUtil.getLog(
077                    SiteMinderLogoutAction.class);
078    
079    }