001: /*
002: * Copyright (C) 2006 Methodhead Software LLC. All rights reserved.
003: *
004: * This file is part of TransferCM.
005: *
006: * TransferCM is free software; you can redistribute it and/or modify it under the
007: * terms of the GNU General Public License as published by the Free Software
008: * Foundation; either version 2 of the License, or (at your option) any later
009: * version.
010: *
011: * TransferCM is distributed in the hope that it will be useful, but WITHOUT ANY
012: * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
013: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
014: * details.
015: *
016: * You should have received a copy of the GNU General Public License along with
017: * TransferCM; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
018: * Fifth Floor, Boston, MA 02110-1301 USA
019: */
020:
021: package com.methodhead.shim;
022:
023: import org.apache.struts.action.Action;
024: import org.apache.struts.action.ActionMapping;
025: import org.apache.struts.action.ActionForm;
026: import org.apache.struts.action.ActionForward;
027: import org.apache.log4j.Logger;
028:
029: import javax.servlet.http.HttpServletRequest;
030: import javax.servlet.http.HttpServletResponse;
031:
032: import com.methodhead.aikp.IntKey;
033: import com.methodhead.auth.AuthPolicy;
034: import com.methodhead.util.OperationContext;
035: import com.methodhead.sitecontext.SiteContext;
036: import com.methodhead.auth.AuthUtil;
037: import org.apache.commons.lang.StringUtils;
038:
039: public class LoginAction extends com.methodhead.auth.LoginAction {
040:
041: // constructors /////////////////////////////////////////////////////////////
042:
043: // constants ////////////////////////////////////////////////////////////////
044:
045: // classes //////////////////////////////////////////////////////////////////
046:
047: // methods //////////////////////////////////////////////////////////////////
048:
049: protected ActionForward doLogin(OperationContext op,
050: AuthPolicy policy) throws Exception {
051:
052: //
053: // log in as normal
054: //
055: ActionForward forward = super .doLogin(op, policy);
056:
057: //
058: // successful login?
059: //
060: if (AuthUtil.getUser(op.request) != null) {
061:
062: //
063: // has a site been specified?
064: //
065: String site = (String) op.form.get("site");
066:
067: if (!StringUtils.isBlank(site)) {
068:
069: if (logger_.isDebugEnabled()) {
070: logger_.debug("Setting up shim session for site \""
071: + site + "\"");
072: }
073:
074: //
075: // attempt to load a site context
076: //
077: SiteContext context = new SiteContext();
078:
079: String path = "";
080: if (site.indexOf("/") != -1) {
081: String[] strings = site.split("/");
082: if (strings.length == 2) {
083: site = strings[0];
084: path = strings[1];
085: }
086: }
087:
088: if (context.loadForDomainAndPath(site, path))
089: ShimUtils.setUpShimSession(op.request, context);
090: }
091: }
092:
093: return forward;
094: }
095:
096: protected ActionForward doLogout(OperationContext op,
097: AuthPolicy policy) throws Exception {
098:
099: ActionForward forward = super .doLogout(op, policy);
100:
101: if (logger_.isDebugEnabled()) {
102: logger_.debug("Tearing down shim session");
103: }
104:
105: ShimUtils.tearDownShimSession(op.request);
106:
107: return forward;
108: }
109:
110: // properties ///////////////////////////////////////////////////////////////
111:
112: // attributes ///////////////////////////////////////////////////////////////
113:
114: private static Logger logger_ = Logger.getLogger(LoginAction.class);
115: }
|