001: // Source file: h:/cvslocal/ivata groupware/src/com.ivata.groupware/admin/security/struts/LoginAction.java
002:
003: /*
004: * Copyright (c) 2001 - 2005 ivata limited.
005: * All rights reserved.
006: * -----------------------------------------------------------------------------
007: * ivata groupware may be redistributed under the GNU General Public
008: * License as published by the Free Software Foundation;
009: * version 2 of the License.
010: *
011: * These programs are free software; you can redistribute them and/or
012: * modify them under the terms of the GNU General Public License
013: * as published by the Free Software Foundation; version 2 of the License.
014: *
015: * These programs are distributed in the hope that they will be useful,
016: * but WITHOUT ANY WARRANTY; without even the implied warranty of
017: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
018: *
019: * See the GNU General Public License in the file LICENSE.txt for more
020: * details.
021: *
022: * If you would like a copy of the GNU General Public License write to
023: *
024: * Free Software Foundation, Inc.
025: * 59 Temple Place - Suite 330
026: * Boston, MA 02111-1307, USA.
027: *
028: *
029: * To arrange commercial support and licensing, contact ivata at
030: * http://www.ivata.com/contact.jsp
031: * -----------------------------------------------------------------------------
032: * $Log: LoginGuestAction.java,v $
033: * Revision 1.3 2005/10/03 10:21:15 colinmacleod
034: * Fixed some style and javadoc issues.
035: *
036: * Revision 1.2 2005/10/02 14:08:58 colinmacleod
037: * Added/improved log4j logging.
038: *
039: * Revision 1.1 2005/09/29 13:06:05 colinmacleod
040: * First version of setting subproject.
041: * Existing classes restructured, new setting user interface created.
042: * Flexible XML UI configuration makes it easy to reuse the same web pages in
043: * other projects.
044: * Web files work as stand-alone webapp for testing.
045: *
046: * Revision 1.3 2005/04/10 19:38:21 colinmacleod
047: * Updated login pages to change theme.
048: *
049: * Revision 1.2 2005/04/09 17:19:57 colinmacleod
050: * Changed copyright text to GPL v2 explicitly.
051: *
052: * Revision 1.1.1.1 2005/03/10 17:51:40 colinmacleod
053: * Restructured ivata op around Hibernate/PicoContainer.
054: * Renamed ivata groupware.
055: *
056: * Revision 1.2 2004/12/31 18:27:44 colinmacleod
057: * Added MaskFactory to constructor of MaskAction.
058: *
059: * Revision 1.1 2004/12/23 20:50:58 colinmacleod
060: * Split off guest login from LoginAction into a new action.
061: * -----------------------------------------------------------------------------
062: */
063: package com.ivata.groupware.admin.security.struts;
064:
065: import org.apache.log4j.Logger;
066:
067: import javax.servlet.http.HttpServletRequest;
068: import javax.servlet.http.HttpServletResponse;
069: import javax.servlet.http.HttpSession;
070:
071: import org.apache.struts.action.ActionForm;
072: import org.apache.struts.action.ActionForward;
073: import org.apache.struts.action.ActionMapping;
074: import org.apache.struts.util.RequestUtils;
075: import org.sourceforge.clientsession.ClientSession;
076:
077: import com.ivata.groupware.admin.security.Security;
078: import com.ivata.groupware.admin.security.server.SecuritySession;
079: import com.ivata.groupware.admin.setting.Settings;
080: import com.ivata.mask.MaskFactory;
081: import com.ivata.mask.util.SystemException;
082: import com.ivata.mask.web.browser.Browser;
083: import com.ivata.mask.web.struts.MaskAuthenticator;
084:
085: /**
086: * <p>This <code>Action</code> is invoked whenever you don't have a valid
087: * session.</p>
088: *
089: * @since 2004-12-23
090: * @author Colin MacLeod
091: * <a href='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
092: * @version $Revision: 1.3 $
093: */
094: public class LoginGuestAction extends LoginAction {
095: /**
096: * Logger for this class.
097: */
098: private static final Logger logger = Logger
099: .getLogger(LoginGuestAction.class);
100:
101: private Security security;
102:
103: /**
104: * TODO
105: * @param security
106: * @param maskFactory This factory is needed to access the masks and groups
107: * of masks.
108: * @param authenticator used to confirm whether or not the
109: * user should be allowed to continue, in the <code>execute</code> method.
110: */
111: public LoginGuestAction(final Security securityParam,
112: final Settings settingsParam,
113: final MaskFactory maskFactoryParam,
114: final MaskAuthenticator authenticatorParam) {
115: super (securityParam, settingsParam, maskFactoryParam,
116: authenticatorParam);
117: this .security = securityParam;
118: }
119:
120: /**
121: * Check the form is valid and, if not, return the action forward we should
122: * go to, to sort it out.
123: *
124: * @param mapping current action mapping from <em>Struts</em> config.
125: * @param formParam optional ActionForm bean for this request (if any).
126: * @return <code>null</code> if the action should continue, otherwise the
127: * name of a forward to pass control to.
128: */
129: protected String checkForm(final ActionMapping mappingParam,
130: final ActionForm formParam) {
131: if (logger.isDebugEnabled()) {
132: logger.debug("checkForm(ActionMapping mappingParam = "
133: + mappingParam + ", ActionForm formParam = "
134: + formParam + ") - start");
135: }
136:
137: if (!"loginForm".equals(mappingParam.getName())) {
138: if (logger.isDebugEnabled()) {
139: logger
140: .debug("checkForm(ActionMapping, ActionForm) - end - return value = loginGuest");
141: }
142: return "loginGuest";
143: }
144:
145: if (logger.isDebugEnabled()) {
146: logger
147: .debug("checkForm(ActionMapping, ActionForm) - end - return value = "
148: + null);
149: }
150: return null;
151: }
152:
153: /**
154: * <p>Overridden from the default intranet implementation to
155: * manipulate user login.</p>
156: *
157: * @param mapping current action mapping from <em>Struts</em> config.
158: * @param request non-HTTP request we are processing
159: * @param response The non-HTTP response we are creating
160: * @param session returned from the <code>request</code> parameter.
161: * @param log valid logging object to write messages to.
162: * @param formParam optional ActionForm bean for this request (if any)
163: * @param guestUserName current user name from session. Not needed for
164: * this action.
165: * @param settings valid, non-null settings from session.
166: * @exception SystemException if there is any problem which
167: * prevents processing. It will result in the webapp being forwarded
168: * to
169: * the standard error page.
170: * @return this method returns the string used to identify the correct
171: * <em>Struts</em> <code>ActionForward</code> which should follow this
172: * page, or <code>null</code> if it should return to the input.
173: */
174: public String execute(final ActionMapping mapping,
175: final ActionForm formParam,
176: final HttpServletRequest request,
177: final HttpServletResponse response,
178: final HttpSession session, ClientSession clientSession)
179: throws SystemException {
180: if (logger.isDebugEnabled()) {
181: logger.debug("execute(ActionMapping mapping = " + mapping
182: + ", ActionForm formParam = " + formParam
183: + ", HttpServletRequest request = " + request
184: + ", HttpServletResponse response = " + response
185: + ", HttpSession session = " + session
186: + ", ClientSession clientSession = "
187: + clientSession + ") - start");
188: }
189:
190: // if this mapping is not _really_ for us, go 'round again...
191: String checkForward = checkForm(mapping, formParam);
192: if (checkForward != null) {
193: if (logger.isDebugEnabled()) {
194: logger
195: .debug("execute(ActionMapping, ActionErrors, ActionForm, HttpServletRequest, HttpServletResponse, HttpSession, ClientSession) - end - return value = "
196: + checkForward);
197: }
198: return checkForward;
199: }
200: SecuritySession securitySession;
201: ActionForm form = formParam;
202: securitySession = security.loginGuest();
203: session.setAttribute("securitySession", securitySession);
204: // for now, create a browser with no javascript support
205: Browser browser = new Browser(request.getHeader("User-Agent"),
206: null);
207: session.setAttribute("browser", browser);
208:
209: form = RequestUtils.createActionForm(request, mapping, mapping
210: .getModuleConfig(), servlet);
211: if (form == null) {
212: request.setAttribute("exception", new NullPointerException(
213: "createActionForm returned null form for mapping '"
214: + mapping.getName()
215: + "' in LoginGuestAction"));
216:
217: if (logger.isDebugEnabled()) {
218: logger
219: .debug("execute(ActionMapping, ActionErrors, ActionForm, HttpServletRequest, HttpServletResponse, HttpSession, ClientSession) - end - return value = error");
220: }
221: return "error";
222: }
223: session.setAttribute("loginForm", form);
224:
225: if (logger.isDebugEnabled()) {
226: logger
227: .debug("execute(ActionMapping, ActionErrors, ActionForm, HttpServletRequest, HttpServletResponse, HttpSession, ClientSession) - end - return value = success");
228: }
229: return "success";
230: }
231:
232: /**
233: * <p>Overrides and extends (calls) the super class implementation to
234: * tell it not to check the session.</p>
235: *
236: * @param mapping The ActionMapping used to select this instance.
237: * @param form The optional ActionForm bean for this request (if any).
238: * @param request The non-HTTP request we are processing.
239: * @param response The non-HTTP response we are creating.
240: * @exception Exception if the application business logic throws
241: * an exception.
242: * @return this method returns a <code>"success"</code>
243: * <code>ActionForward</code> if the compose session is cancelled or
244: * successfully sent, otherwise a <code>"failure"</code>
245: * <code>ActionForward</code>.
246: *
247: */
248: public ActionForward execute(final ActionMapping mapping,
249: final ActionForm form, final HttpServletRequest request,
250: final HttpServletResponse response) throws Exception {
251: if (logger.isDebugEnabled()) {
252: logger.debug("execute(ActionMapping mapping = " + mapping
253: + ", ActionForm form = " + form
254: + ", HttpServletRequest request = " + request
255: + ", HttpServletResponse response = " + response
256: + ") - start");
257: }
258:
259: // this prevents us always going around in circles!!
260: setLogin(true);
261: ActionForward returnActionForward = super .execute(mapping,
262: form, request, response);
263: if (logger.isDebugEnabled()) {
264: logger
265: .debug("execute(ActionMapping, ActionForm, HttpServletRequest, HttpServletResponse) - end - return value = "
266: + returnActionForward);
267: }
268: return returnActionForward;
269: }
270: }
|