KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ivata > groupware > admin > security > struts > LoginGuestAction


1 // Source file: h:/cvslocal/ivata groupware/src/com.ivata.groupware/admin/security/struts/LoginAction.java
2

3 /*
4  * Copyright (c) 2001 - 2005 ivata limited.
5  * All rights reserved.
6  * -----------------------------------------------------------------------------
7  * ivata groupware may be redistributed under the GNU General Public
8  * License as published by the Free Software Foundation;
9  * version 2 of the License.
10  *
11  * These programs are free software; you can redistribute them and/or
12  * modify them under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; version 2 of the License.
14  *
15  * These programs are distributed in the hope that they will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18  *
19  * See the GNU General Public License in the file LICENSE.txt for more
20  * details.
21  *
22  * If you would like a copy of the GNU General Public License write to
23  *
24  * Free Software Foundation, Inc.
25  * 59 Temple Place - Suite 330
26  * Boston, MA 02111-1307, USA.
27  *
28  *
29  * To arrange commercial support and licensing, contact ivata at
30  * http://www.ivata.com/contact.jsp
31  * -----------------------------------------------------------------------------
32  * $Log: LoginGuestAction.java,v $
33  * Revision 1.3 2005/04/10 19:38:21 colinmacleod
34  * Updated login pages to change theme.
35  *
36  * Revision 1.2 2005/04/09 17:19:57 colinmacleod
37  * Changed copyright text to GPL v2 explicitly.
38  *
39  * Revision 1.1.1.1 2005/03/10 17:51:40 colinmacleod
40  * Restructured ivata op around Hibernate/PicoContainer.
41  * Renamed ivata groupware.
42  *
43  * Revision 1.2 2004/12/31 18:27:44 colinmacleod
44  * Added MaskFactory to constructor of MaskAction.
45  *
46  * Revision 1.1 2004/12/23 20:50:58 colinmacleod
47  * Split off guest login from LoginAction into a new action.
48  * -----------------------------------------------------------------------------
49  */

50 package com.ivata.groupware.admin.security.struts;
51
52 import javax.servlet.http.HttpServletRequest JavaDoc;
53 import javax.servlet.http.HttpServletResponse JavaDoc;
54 import javax.servlet.http.HttpSession JavaDoc;
55
56 import org.apache.struts.action.ActionErrors;
57 import org.apache.struts.action.ActionForm;
58 import org.apache.struts.action.ActionForward;
59 import org.apache.struts.action.ActionMapping;
60 import org.apache.struts.util.RequestUtils;
61
62 import com.ivata.groupware.admin.security.Security;
63 import com.ivata.groupware.admin.security.server.SecuritySession;
64 import com.ivata.groupware.admin.setting.Settings;
65 import com.ivata.mask.MaskFactory;
66 import com.ivata.mask.util.SystemException;
67 import com.ivata.mask.web.browser.Browser;
68 import com.ivata.mask.web.struts.MaskAuthenticator;
69
70 /**
71  * <p>This <code>Action</code> is invoked whenever you don't have a valid
72  * session.</p>
73  *
74  * @since 2004-12-23
75  * @author Colin MacLeod
76  * <a HREF='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
77  * @version $Revision: 1.3 $
78  */

79 public class LoginGuestAction extends LoginAction {
80     private Security security;
81
82     /**
83      * TODO
84      * @param security
85      * @param maskFactory This factory is needed to access the masks and groups
86      * of masks.
87      * @param authenticator used to confirm whether or not the
88      * user should be allowed to continue, in the <code>execute</code> method.
89      */

90     public LoginGuestAction(final Security securityParam,
91             final Settings settingsParam,
92             final MaskFactory maskFactoryParam,
93             final MaskAuthenticator authenticatorParam) {
94         super(securityParam, settingsParam, maskFactoryParam,
95                 authenticatorParam);
96         this.security = securityParam;
97     }
98
99     /**
100      * Check the form is valid and, if not, return the action forward we should
101      * go to, to sort it out.
102      *
103      * @param mapping current action mapping from <em>Struts</em> config.
104      * @param formParam optional ActionForm bean for this request (if any).
105      * @return <code>null</code> if the action should continue, otherwise the
106      * name of a forward to pass control to.
107      */

108     protected String JavaDoc checkForm(final ActionMapping mappingParam,
109             final ActionForm formParam) {
110         if (!"loginForm".equals(mappingParam.getName())) {
111             return "loginGuest";
112         }
113         return null;
114     }
115
116     /**
117      * <p>Overridden from the default intranet implementation to
118      * manipulate user login.</p>
119      *
120      * @param mapping current action mapping from <em>Struts</em> config.
121      * @param log valid logging object to write messages to.
122      * @param errors valid errors object to append errors to. If there are
123      * any errors, the action will return to the input.
124      * @param formParam optional ActionForm bean for this request (if any)
125      * @param request non-HTTP request we are processing
126      * @param response The non-HTTP response we are creating
127      * @param session returned from the <code>request</code> parameter.
128      * @param guestUserName current user name from session. Not needed for
129      * this action.
130      * @param settings valid, non-null settings from session.
131      * @exception SystemException if there is any problem which
132      * prevents processing. It will result in the webapp being forwarded
133      * to
134      * the standard error page.
135      * @return this method returns the string used to identify the correct
136      * <em>Struts</em> <code>ActionForward</code> which should follow this
137      * page, or <code>null</code> if it should return to the input.
138      */

139     public String JavaDoc execute(final ActionMapping mapping,
140             final ActionErrors errors,
141             final ActionForm formParam,
142             final HttpServletRequest JavaDoc request,
143             final HttpServletResponse JavaDoc response,
144             final HttpSession JavaDoc session) throws SystemException {
145         // if this mapping is not _really_ for us, go 'round again...
146
String JavaDoc checkForward = checkForm(mapping, formParam);
147         if (checkForward != null) {
148             return checkForward;
149         }
150         SecuritySession securitySession;
151         ActionForm form = formParam;
152         securitySession = security.loginGuest();
153         session.setAttribute("securitySession", securitySession);
154         // for now, create a browser with no javascript support
155
Browser browser = new Browser(request.getHeader("User-Agent"), null);
156         session.setAttribute("browser", browser);
157
158         form = RequestUtils.createActionForm(request, mapping,
159                 mapping.getModuleConfig(), servlet);
160         if (form == null) {
161             request.setAttribute("exception",
162                     new NullPointerException JavaDoc(
163                             "createActionForm returned null form for mapping '"
164                             + mapping.getName()
165                             + "' in LoginGuestAction"));
166             return "error";
167         }
168         session.setAttribute("loginForm", form);
169         return "success";
170     }
171
172
173     /**
174      * <p>Overrides and extends (calls) the super class implementation to
175      * tell it not to check the session.</p>
176      *
177      * @param mapping The ActionMapping used to select this instance.
178      * @param form The optional ActionForm bean for this request (if any).
179      * @param request The non-HTTP request we are processing.
180      * @param response The non-HTTP response we are creating.
181      * @exception Exception if the application business logic throws
182      * an exception.
183      * @return this method returns a <code>"success"</code>
184      * <code>ActionForward</code> if the compose session is cancelled or
185      * successfully sent, otherwise a <code>"failure"</code>
186      * <code>ActionForward</code>.
187      *
188      */

189     public ActionForward execute(final ActionMapping mapping,
190             final ActionForm form,
191             final HttpServletRequest JavaDoc request,
192             final HttpServletResponse JavaDoc response) throws Exception JavaDoc {
193         // this prevents us always going around in circles!!
194
setLogin(true);
195         return super.execute(mapping, form, request, response);
196     }
197 }
198
Popular Tags