001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portal.action;
022:
023: import com.liferay.portal.events.EventsProcessor;
024: import com.liferay.portal.kernel.util.StringPool;
025: import com.liferay.portal.kernel.util.Validator;
026: import com.liferay.portal.struts.ActionConstants;
027: import com.liferay.portal.util.CookieKeys;
028: import com.liferay.portal.util.PropsUtil;
029:
030: import javax.servlet.http.Cookie;
031: import javax.servlet.http.HttpServletRequest;
032: import javax.servlet.http.HttpServletResponse;
033: import javax.servlet.http.HttpSession;
034: import javax.servlet.jsp.PageContext;
035:
036: import org.apache.struts.action.Action;
037: import org.apache.struts.action.ActionForm;
038: import org.apache.struts.action.ActionForward;
039: import org.apache.struts.action.ActionMapping;
040:
041: /**
042: * <a href="LogoutAction.java.html"><b><i>View Source</i></b></a>
043: *
044: * @author Brian Wing Shun Chan
045: *
046: */
047: public class LogoutAction extends Action {
048:
049: public ActionForward execute(ActionMapping mapping,
050: ActionForm form, HttpServletRequest req,
051: HttpServletResponse res) throws Exception {
052:
053: try {
054: HttpSession ses = req.getSession();
055:
056: EventsProcessor.process(PropsUtil
057: .getArray(PropsUtil.LOGOUT_EVENTS_PRE), req, res);
058:
059: String domain = CookieKeys.getDomain(req);
060:
061: Cookie companyIdCookie = new Cookie(CookieKeys.COMPANY_ID,
062: StringPool.BLANK);
063:
064: if (Validator.isNotNull(domain)) {
065: companyIdCookie.setDomain(domain);
066: }
067:
068: companyIdCookie.setMaxAge(0);
069: companyIdCookie.setPath(StringPool.SLASH);
070:
071: Cookie idCookie = new Cookie(CookieKeys.ID,
072: StringPool.BLANK);
073:
074: if (Validator.isNotNull(domain)) {
075: idCookie.setDomain(domain);
076: }
077:
078: idCookie.setMaxAge(0);
079: idCookie.setPath(StringPool.SLASH);
080:
081: Cookie passwordCookie = new Cookie(CookieKeys.PASSWORD,
082: StringPool.BLANK);
083:
084: if (Validator.isNotNull(domain)) {
085: passwordCookie.setDomain(domain);
086: }
087:
088: passwordCookie.setMaxAge(0);
089: passwordCookie.setPath(StringPool.SLASH);
090:
091: CookieKeys.addCookie(res, companyIdCookie);
092: CookieKeys.addCookie(res, idCookie);
093: CookieKeys.addCookie(res, passwordCookie);
094:
095: try {
096: ses.invalidate();
097: } catch (Exception e) {
098: }
099:
100: EventsProcessor.process(PropsUtil
101: .getArray(PropsUtil.LOGOUT_EVENTS_POST), req, res);
102:
103: return mapping.findForward(ActionConstants.COMMON_REFERER);
104: } catch (Exception e) {
105: req.setAttribute(PageContext.EXCEPTION, e);
106:
107: return mapping.findForward(ActionConstants.COMMON_ERROR);
108: }
109: }
110:
111: }
|