001: /*
002: * JOSSO: Java Open Single Sign-On
003: *
004: * Copyright 2004-2008, Atricore, Inc.
005: *
006: * This is free software; you can redistribute it and/or modify it
007: * under the terms of the GNU Lesser General Public License as
008: * published by the Free Software Foundation; either version 2.1 of
009: * the License, or (at your option) any later version.
010: *
011: * This software is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this software; if not, write to the Free
018: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
019: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
020: */
021:
022: package org.josso.gateway.signon;
023:
024: import org.apache.commons.logging.Log;
025: import org.apache.commons.logging.LogFactory;
026: import org.apache.struts.action.*;
027: import org.josso.Lookup;
028: import org.josso.gateway.SSOContext;
029: import org.josso.gateway.SSOException;
030: import org.josso.gateway.SSOGateway;
031: import org.josso.gateway.SSOWebConfiguration;
032: import org.josso.gateway.identity.SSOUser;
033: import org.josso.gateway.session.SSOSession;
034:
035: import javax.servlet.http.Cookie;
036: import javax.servlet.http.HttpServletRequest;
037: import javax.servlet.http.HttpServletResponse;
038:
039: /**
040: * @author <a href="mailto:sgonzalez@josso.org">Sebastian Gonzalez Oyuela</a>
041: * @version $Id: LogoutAction.java 508 2008-02-18 13:32:29Z sgonzalez $
042: */
043:
044: public class LogoutAction extends SignonBaseAction {
045:
046: private static final Log logger = LogFactory
047: .getLog(LogoutAction.class);
048:
049: public ActionForward execute(ActionMapping mapping,
050: ActionForm form, HttpServletRequest request,
051: HttpServletResponse response) throws Exception {
052: //SSOSession session = null;
053: //SSOUser user = null;
054:
055: try {
056:
057: // Logout user
058: SSOGateway g = getSSOGateway();
059: SSOContext ctx = getNewSSOContext(request);
060: ctx.getCurrentSession();
061: //user = g.findUserInSession(session.getId());
062:
063: // Clear josso cookie
064: Cookie ssoCookie = newJossoCookie(request.getContextPath(),
065: "-");
066: response.addCookie(ssoCookie);
067:
068: g.logout(ctx);
069:
070: } catch (SSOException e) {
071: if (logger.isDebugEnabled())
072: logger.debug(e.getMessage(), e);
073:
074: } catch (Exception e) {
075: logger.error(e.getMessage(), e);
076: ActionErrors errors = new ActionErrors();
077: errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(
078: "sso.login.failed"));
079: saveErrors(request, errors);
080: }
081:
082: // Redirect the user to the propper page, if any
083: String back_to = request.getParameter(PARAM_JOSSO_BACK_TO);
084:
085: if (back_to == null) {
086: // Try with the configured URL if any.
087: SSOWebConfiguration c = Lookup.getInstance()
088: .lookupSSOWebConfiguration();
089: back_to = c.getLogoutBackToURL();
090: }
091:
092: if (back_to != null) {
093: if (logger.isDebugEnabled())
094: logger.debug("[logout()], ok->redirecting to : "
095: + back_to);
096: response.sendRedirect(response.encodeRedirectURL(back_to));
097: return null; // No forward is needed.
098: }
099:
100: if (logger.isDebugEnabled())
101: logger.debug("[logout()], ok");
102:
103: return mapping.findForward("success");
104: }
105:
106: }
|