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.events.ActionException;
019    import com.liferay.portal.kernel.log.Log;
020    import com.liferay.portal.kernel.log.LogFactoryUtil;
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.WebKeys;
027    
028    import javax.servlet.http.HttpServletRequest;
029    import javax.servlet.http.HttpServletResponse;
030    
031    /**
032     * @author Jerry Niu
033     */
034    public class DefaultLogoutPageAction extends Action {
035    
036            @Override
037            public void run(HttpServletRequest request, HttpServletResponse response)
038                    throws ActionException {
039    
040                    try {
041                            doRun(request, response);
042                    }
043                    catch (Exception e) {
044                            throw new ActionException(e);
045                    }
046            }
047    
048            protected void doRun(
049                            HttpServletRequest request, HttpServletResponse response)
050                    throws Exception {
051    
052                    long companyId = PortalUtil.getCompanyId(request);
053    
054                    String path = PrefsPropsUtil.getString(
055                            companyId, PropsKeys.DEFAULT_LOGOUT_PAGE_PATH);
056    
057                    if (_log.isInfoEnabled()) {
058                            _log.info(
059                                    PropsKeys.DEFAULT_LOGOUT_PAGE_PATH + StringPool.EQUAL + path);
060                    }
061    
062                    if (Validator.isNotNull(path)) {
063                            request.setAttribute(WebKeys.REFERER, path);
064                    }
065    
066                    // The commented code shows how you can programmaticaly set the user's
067                    // logout page. You can modify this class to utilize a custom algorithm
068                    // for forwarding a user to his logout page. See the references to this
069                    // class in portal.properties.
070    
071                    /*Map<String, String[]> params = new HashMap<String, String[]>();
072    
073                    params.put("p_l_id", new String[] {"1806"});
074    
075                    LastPath lastPath = new LastPath("/c", "/portal/layout", params);
076    
077                    session.setAttribute(WebKeys.LAST_PATH, lastPath);*/
078            }
079    
080            private static Log _log = LogFactoryUtil.getLog(
081                    DefaultLogoutPageAction.class);
082    
083    }