Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/lilacsoftware/orca/LogonAction.java


1   /*
2    * $Header: /cvsroot/orca-system/orca-system/src/com/lilacsoftware/orca/LogonAction.java,v 1.1.1.1 2001/11/05 17:41:46 tomwadzinski Exp $
3    * $Revision: 1.1.1.1 $
4    * $Date: 2001/11/05 17:41:46 $
5    *
6    * ====================================================================
7    *
8    * The Apache Software License, Version 1.1
9    *
10   * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
11   * reserved.
12   *
13   * Redistribution and use in source and binary forms, with or without
14   * modification, are permitted provided that the following conditions
15   * are met:
16   *
17   * 1. Redistributions of source code must retain the above copyright
18   *    notice, this list of conditions and the following disclaimer.
19   *
20   * 2. Redistributions in binary form must reproduce the above copyright
21   *    notice, this list of conditions and the following disclaimer in
22   *    the documentation and/or other materials provided with the
23   *    distribution.
24   *
25   * 3. The end-user documentation included with the redistribution, if
26   *    any, must include the following acknowlegement:
27   *       "This product includes software developed by the
28   *        Apache Software Foundation (http://www.apache.org/)."
29   *    Alternately, this acknowlegement may appear in the software itself,
30   *    if and wherever such third-party acknowlegements normally appear.
31   *
32   * 4. The names "The Jakarta Project", "Struts", and "Apache Software
33   *    Foundation" must not be used to endorse or promote products derived
34   *    from this software without prior written permission. For written
35   *    permission, please contact apache@apache.org.
36   *
37   * 5. Products derived from this software may not be called "Apache"
38   *    nor may "Apache" appear in their names without prior written
39   *    permission of the Apache Group.
40   *
41   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
42   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
43   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
44   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
45   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
46   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
47   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
48   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
49   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
50   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
51   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
52   * SUCH DAMAGE.
53   * ====================================================================
54   *
55   * This software consists of voluntary contributions made by many
56   * individuals on behalf of the Apache Software Foundation.  For more
57   * information on the Apache Software Foundation, please see
58   * <http://www.apache.org/>.
59   *
60   */
61  
62  
63  package com.lilacsoftware.orca;
64  
65  import java.io.IOException;
66  import java.util.Hashtable;
67  import java.util.Locale;
68  import javax.servlet.RequestDispatcher;
69  import javax.servlet.ServletException;
70  import javax.servlet.http.HttpServletRequest;
71  import javax.servlet.http.HttpSession;
72  import javax.servlet.http.HttpServletResponse;
73  import org.apache.struts.action.Action;
74  import org.apache.struts.action.ActionError;
75  import org.apache.struts.action.ActionErrors;
76  import org.apache.struts.action.ActionForm;
77  import org.apache.struts.action.ActionForward;
78  import org.apache.struts.action.ActionMapping;
79  import org.apache.struts.action.ActionServlet;
80  import org.apache.struts.util.MessageResources;
81  import java.util.Properties;
82  
83  /**
84   * Implementation of <strong>Action</strong> that validates a user logon.
85   *
86   * @author Craig R. McClanahan
87   * @version $Revision: 1.1.1.1 $ $Date: 2001/11/05 17:41:46 $
88   */
89  
90  public final class LogonAction extends Action {
91  
92  
93      // --------------------------------------------------------- Public Methods
94  
95  
96      /**
97       * Process the specified HTTP request, and create the corresponding HTTP
98       * response (or forward to another web component that will create it).
99       * Return an <code>ActionForward</code> instance describing where and how
100      * control should be forwarded, or <code>null</code> if the response has
101      * already been completed.
102      *
103      * @param mapping The ActionMapping used to select this instance
104      * @param actionForm The optional ActionForm bean for this request (if any)
105      * @param request The HTTP request we are processing
106      * @param response The HTTP response we are creating
107      *
108      * @exception IOException if an input/output error occurs
109      * @exception ServletException if a servlet exception occurs
110      */
111     public ActionForward perform(ActionMapping mapping,
112          ActionForm form,
113          HttpServletRequest request,
114          HttpServletResponse response)
115   throws IOException, ServletException {
116 
117   // Extract attributes we will need
118   Locale locale = getLocale(request);
119   MessageResources messages = getResources();
120   User user = null;
121 
122   // Validate the request parameters specified by the user
123   ActionErrors errors = new ActionErrors();
124   String username = ((LogonForm) form).getUsername();
125   String password = ((LogonForm) form).getPassword();
126   //Hashtable database = (Hashtable)
127   //servlet.getServletContext().getAttribute(Constants.DATABASE_KEY);
128   //if (database == null)
129   //  errors.add(ActionErrors.GLOBAL_ERROR,
130   //             new ActionError("error.database.missing"));
131   //else {
132   //  user = (User) database.get(username);
133   //  if ((user != null) && !user.getPassword().equals(password))
134   //user = null;
135   //  if (user == null)
136   //      errors.add(ActionErrors.GLOBAL_ERROR,
137   //                 new ActionError("error.password.mismatch"));
138   //}
139 
140   
141   //Retrieve system password
142   String systemPassword = "bar";
143   Properties appProps = OrcaProperties.getInstance().getProperties();
144   if (appProps != null ) {
145       systemPassword = appProps.getProperty("systemPassword");
146   }
147   
148   //Allow any username for now
149   if ((username != null) && (password.equals(systemPassword)) ){
150       user = new User();
151       user.setUsername(username);
152   }
153   else {
154       errors.add(ActionErrors.GLOBAL_ERROR,
155            new ActionError("error.password.mismatch"));
156   }
157   // Report any errors we have discovered back to the original form
158   if (!errors.empty()) {
159       saveErrors(request, errors);
160       return (new ActionForward(mapping.getInput()));
161   }
162 
163   // Save our logged-in user in the session
164   HttpSession session = request.getSession();
165   session.setAttribute(Constants.USER_KEY, user);
166   //if (servlet.getDebug() >= 1)
167   trace(0,getClass().getName(), "LogonAction: User '" + user.getUsername() +
168                   "' logged on in session " + session.getId());
169 
170         // Remove the obsolete form bean
171   if (mapping.getAttribute() != null) {
172             if ("request".equals(mapping.getScope()))
173                 request.removeAttribute(mapping.getAttribute());
174             else
175                 session.removeAttribute(mapping.getAttribute());
176         }
177 
178   // Forward control to the specified index URI
179   //hack - check for Netscape 4.x, use different index.jsp
180   //String userAgent = request.getHeader("User-Agent").toLowerCase();
181   //trace(0,getClass().getName(), "useragent: " + userAgent);
182   //if(userAgent.indexOf("mozilla") >= 0) {
183   //    return (mapping.findForward("success-nn4"));
184   //}
185   
186   return (mapping.findForward("success"));
187 
188 
189 
190     }
191 
192 
193     /**
194      * Sends traces to Debug.
195      */
196     private void trace(int level, String msg1, String msg2)
197     {
198   Debug dbg = Debug.getInstance();
199   dbg.log(level,msg1+":"+msg2);
200     }
201 }