001: /*
002: * Copyright (c) 2001 - 2005 ivata limited.
003: * All rights reserved.
004: * -----------------------------------------------------------------------------
005: * ivata groupware may be redistributed under the GNU General Public
006: * License as published by the Free Software Foundation;
007: * version 2 of the License.
008: *
009: * These programs are free software; you can redistribute them and/or
010: * modify them under the terms of the GNU General Public License
011: * as published by the Free Software Foundation; version 2 of the License.
012: *
013: * These programs are distributed in the hope that they will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016: *
017: * See the GNU General Public License in the file LICENSE.txt for more
018: * details.
019: *
020: * If you would like a copy of the GNU General Public License write to
021: *
022: * Free Software Foundation, Inc.
023: * 59 Temple Place - Suite 330
024: * Boston, MA 02111-1307, USA.
025: *
026: *
027: * To arrange commercial support and licensing, contact ivata at
028: * http://www.ivata.com/contact.jsp
029: * -----------------------------------------------------------------------------
030: * $Log: JavaScriptAction.java,v $
031: * Revision 1.3 2005/10/03 10:21:15 colinmacleod
032: * Fixed some style and javadoc issues.
033: *
034: * Revision 1.2 2005/10/02 14:08:58 colinmacleod
035: * Added/improved log4j logging.
036: *
037: * Revision 1.1 2005/09/29 13:06:05 colinmacleod
038: * First version of setting subproject.
039: * Existing classes restructured, new setting user interface created.
040: * Flexible XML UI configuration makes it easy to reuse the same web pages in
041: * other projects.
042: * Web files work as stand-alone webapp for testing.
043: *
044: * Revision 1.3 2005/04/10 18:47:41 colinmacleod
045: * Changed i tag to em and b tag to strong.
046: *
047: * Revision 1.2 2005/04/09 17:19:57 colinmacleod
048: * Changed copyright text to GPL v2 explicitly.
049: *
050: * Revision 1.1.1.1 2005/03/10 17:51:40 colinmacleod
051: * Restructured ivata op around Hibernate/PicoContainer.
052: * Renamed ivata groupware.
053: *
054: * Revision 1.5 2004/12/31 18:27:44 colinmacleod
055: * Added MaskFactory to constructor of MaskAction.
056: *
057: * Revision 1.4 2004/12/23 21:01:30 colinmacleod
058: * Updated Struts to v1.2.4.
059: * Changed base classes to use ivata masks.
060: *
061: * Revision 1.3 2004/11/12 18:19:16 colinmacleod
062: * Change action and form classes to extend MaskAction, MaskForm respectively.
063: *
064: * Revision 1.2 2004/11/03 15:31:51 colinmacleod
065: * Change method interfaces to remove log.
066: *
067: * Revision 1.1 2004/09/30 15:15:59 colinmacleod
068: * Split off addressbook elements into security subproject.
069: *
070: * Revision 1.4 2004/07/13 19:41:12 colinmacleod
071: * Moved project to POJOs from EJBs.
072: * Applied PicoContainer to services layer (replacing session EJBs).
073: * Applied Hibernate to persistence layer (replacing entity EJBs).
074: *
075: * Revision 1.3 2004/03/21 21:16:05 colinmacleod
076: * Shortened name to ivata op.
077: *
078: * Revision 1.2 2004/02/01 22:00:32 colinmacleod
079: * Added full names to author tags
080: *
081: * Revision 1.1.1.1 2004/01/27 20:57:45 colinmacleod
082: * Moved ivata openportal to SourceForge..
083: *
084: * Revision 1.3 2003/11/13 16:03:15 jano
085: * commitng everything to CVS
086: * can deploy and application is ruuning, can login into
087: *
088: * Revision 1.2 2003/10/17 12:36:12 jano
089: * fixing problems with building
090: * converting intranet -> portal
091: * Eclipse building
092: *
093: * Revision 1.1.1.1 2003/10/13 20:50:06 colin
094: * Restructured portal into subprojects
095: *
096: * Revision 1.1 2003/02/24 18:53:57 colin
097: * added to admin
098: *
099: * Revision 1.2 2003/02/04 17:38:13 colin
100: * updated for new execute interface
101: *
102: * Revision 1.1 2003/01/18 20:29:42 colin
103: * converted login process to struts
104: * added checking for javascript at login
105: * -----------------------------------------------------------------------------
106: */
107: package com.ivata.groupware.admin.security.struts;
108:
109: import org.apache.log4j.Logger;
110:
111: import java.lang.reflect.InvocationTargetException;
112:
113: import javax.servlet.http.HttpServletRequest;
114: import javax.servlet.http.HttpServletResponse;
115: import javax.servlet.http.HttpSession;
116:
117: import org.apache.commons.beanutils.PropertyUtils;
118: import org.apache.struts.action.ActionForm;
119: import org.apache.struts.action.ActionMapping;
120: import org.sourceforge.clientsession.ClientSession;
121:
122: import com.ivata.groupware.admin.security.Security;
123: import com.ivata.groupware.admin.setting.Settings;
124: import com.ivata.mask.MaskFactory;
125: import com.ivata.mask.util.StringHandling;
126: import com.ivata.mask.util.SystemException;
127: import com.ivata.mask.web.struts.MaskAuthenticator;
128:
129: /**
130: * <p>Detects whether or not the browser has <em>JavaScript</em>.</p>
131: *
132: * @since 2003-01-18
133: * @author Colin MacLeod
134: * <a href='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
135: * @version $Revision: 1.3 $
136: */
137: public class JavaScriptAction extends LoginAction {
138: /**
139: * Logger for this class.
140: */
141: private static final Logger logger = Logger
142: .getLogger(JavaScriptAction.class);
143:
144: /**
145: * <p>
146: * Construct the javascript action.
147: * </p>
148: *
149: * @param security see {@link LoginAction}
150: * @param settings see {@link LoginAction}
151: * @param maskFactory This factory is needed to access the masks and groups
152: * of masks.
153: * @param authenticator used to confirm whether or not the
154: * user should be allowed to continue, in the <code>execute</code> method.
155: */
156: public JavaScriptAction(Security security, Settings settings,
157: MaskFactory maskFactory, MaskAuthenticator authenticator) {
158: super (security, settings, maskFactory, authenticator);
159: }
160:
161: /**
162: * <p>Overridden from the default intranet implementation to
163: * detect <em>JavaScript</em>.</p>
164: *
165: * @param mapping current action mapping from <em>Struts</em> config.
166: * @param form optional ActionForm bean for this request (if any)
167: * @param request non-HTTP request we are processing
168: * @param response The non-HTTP response we are creating
169: * @param session returned from the <code>request</code> parameter.
170: * @param log valid logging object to write messages to.
171: * @param guestUserName current user name from session. Not needed for
172: * this aciton.
173: * @param settings valid, non-null settings from session.
174: * @exception SystemException if there is any problem which
175: * prevents processing. It will result in the webapp being forwarded
176: * to
177: * the standard error page.
178: * @return this method returns the string used to identify the correct
179: * <em>Struts</em> <code>ActionForward</code> which should follow this
180: * page, or <code>null</code> if it should return to the input.
181: *
182: */
183: public String execute(final ActionMapping mapping,
184: final ActionForm form, final HttpServletRequest request,
185: final HttpServletResponse response,
186: final HttpSession session, ClientSession clientSession)
187: throws SystemException {
188: if (logger.isDebugEnabled()) {
189: logger.debug("execute(ActionMapping mapping = " + mapping
190: + ", ActionForm form = " + form
191: + ", HttpServletRequest request = " + request
192: + ", HttpServletResponse response = " + response
193: + ", HttpSession session = " + session
194: + ", ClientSession clientSession = "
195: + clientSession + ") - start");
196: }
197:
198: // if we don't have a form or the form doesn't have java script set
199: // then just forward to the intranet login - that's our input screen
200: if (form == null) {
201: if (logger.isDebugEnabled()) {
202: logger
203: .debug("execute(ActionMapping, ActionErrors, ActionForm, HttpServletRequest, HttpServletResponse, HttpSession, ClientSession) - end - return value = "
204: + null);
205: }
206: return null;
207: }
208: String javaScriptVersion = null;
209: ActionForm loginForm = (ActionForm) session
210: .getAttribute("loginForm");
211: try {
212: javaScriptVersion = (String) PropertyUtils
213: .getSimpleProperty(form, "javaScriptVersion");
214: } catch (NoSuchMethodException e) {
215: logger
216: .error(
217: "execute(ActionMapping, ActionErrors, ActionForm, HttpServletRequest, HttpServletResponse, HttpSession, ClientSession)",
218: e);
219:
220: throw new SystemException(e);
221: } catch (InvocationTargetException e) {
222: logger
223: .error(
224: "execute(ActionMapping, ActionErrors, ActionForm, HttpServletRequest, HttpServletResponse, HttpSession, ClientSession)",
225: e);
226:
227: throw new SystemException(e);
228: } catch (IllegalAccessException e) {
229: logger
230: .error(
231: "execute(ActionMapping, ActionErrors, ActionForm, HttpServletRequest, HttpServletResponse, HttpSession, ClientSession)",
232: e);
233:
234: throw new SystemException(e);
235: }
236: if (StringHandling.isNullOrEmpty(javaScriptVersion)) {
237: String returnString = super .execute(mapping, loginForm,
238: request, response, session, clientSession);
239: if (logger.isDebugEnabled()) {
240: logger
241: .debug("execute(ActionMapping, ActionErrors, ActionForm, HttpServletRequest, HttpServletResponse, HttpSession, ClientSession) - end - return value = "
242: + returnString);
243: }
244: return returnString;
245: }
246:
247: // if it gets here, set the javascript version in the login form
248: if (loginForm == null) {
249: String returnString = super .execute(mapping, loginForm,
250: request, response, session, clientSession);
251: if (logger.isDebugEnabled()) {
252: logger
253: .debug("execute(ActionMapping, ActionErrors, ActionForm, HttpServletRequest, HttpServletResponse, HttpSession, ClientSession) - end - return value = "
254: + returnString);
255: }
256: return returnString;
257: }
258: try {
259: PropertyUtils.setSimpleProperty(loginForm,
260: "javaScriptVersion", javaScriptVersion);
261: } catch (NoSuchMethodException e) {
262: logger
263: .error(
264: "execute(ActionMapping, ActionErrors, ActionForm, HttpServletRequest, HttpServletResponse, HttpSession, ClientSession)",
265: e);
266:
267: throw new SystemException(e);
268: } catch (InvocationTargetException e) {
269: logger
270: .error(
271: "execute(ActionMapping, ActionErrors, ActionForm, HttpServletRequest, HttpServletResponse, HttpSession, ClientSession)",
272: e);
273:
274: throw new SystemException(e);
275: } catch (IllegalAccessException e) {
276: logger
277: .error(
278: "execute(ActionMapping, ActionErrors, ActionForm, HttpServletRequest, HttpServletResponse, HttpSession, ClientSession)",
279: e);
280:
281: throw new SystemException(e);
282: }
283: String returnString = super .execute(mapping, loginForm,
284: request, response, session, clientSession);
285: if (logger.isDebugEnabled()) {
286: logger
287: .debug("execute(ActionMapping, ActionErrors, ActionForm, HttpServletRequest, HttpServletResponse, HttpSession, ClientSession) - end - return value = "
288: + returnString);
289: }
290: return returnString;
291: }
292: }
|