KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > quikj > application > communicator > admin > controller > LogonAction


1 package com.quikj.application.communicator.admin.controller;
2
3 import java.io.IOException JavaDoc;
4 import java.util.Locale JavaDoc;
5 import javax.servlet.ServletException JavaDoc;
6 import javax.servlet.http.HttpServletRequest JavaDoc;
7 import javax.servlet.http.HttpServletResponse JavaDoc;
8 import org.apache.struts.action.Action;
9 import org.apache.struts.action.ActionError;
10 import org.apache.struts.action.ActionErrors;
11 import org.apache.struts.action.ActionForm;
12 import org.apache.struts.action.ActionForward;
13 import org.apache.struts.action.ActionMapping;
14 import java.sql.*;
15 import com.quikj.application.communicator.admin.model.*;
16 import com.quikj.server.framework.*;
17 import com.quikj.client.raccess.*;
18
19 /**
20  * Implementation of <strong>Action</strong> that validates a user logon.
21  * Based on Apache Struts framework.
22  *
23  * @author Vinod Batra
24  * @version $Revision: 1.7 $ $Date: 2004/05/03 11:09:17 $
25  */

26
27 public final class LogonAction extends Action
28 {
29     /**
30      * Process the specified HTTP request, and create the corresponding HTTP
31      * response (or forward to another web component that will create it).
32      * Return an <code>ActionForward</code> instance describing where and how
33      * control should be forwarded, or <code>null</code> if the response has
34      * already been completed.
35      *
36      * @param mapping The ActionMapping used to select this instance
37      * @param actionForm The optional ActionForm bean for this request (if any)
38      * @param request The HTTP request we are processing
39      * @param response The HTTP response we are creating
40      *
41      * @exception IOException if an input/output error occurs
42      * @exception ServletException if a servlet exception occurs
43      */

44     public ActionForward execute(ActionMapping mapping,
45     ActionForm form,
46     HttpServletRequest JavaDoc request,
47     HttpServletResponse JavaDoc response)
48     throws IOException JavaDoc, ServletException JavaDoc
49     {
50         
51         // Extract attributes we will need
52
Locale JavaDoc locale = getLocale(request);
53         ActionErrors errors = new ActionErrors();
54         
55         // first check if the user already has a connection
56
Connection c = (Connection)request.getSession().getAttribute("connection");
57         if (c == null)
58         {
59             c = DBConnection.getInstance().getConnection();
60         }
61         
62         if (c == null) // could not obtain the connection
63
{
64             errors.add(ActionErrors.GLOBAL_ERROR,
65             new ActionError("error.database.error"));
66         }
67         
68         AccountElement userinfo = null;
69         String JavaDoc authcode = null;
70         
71         if (errors.isEmpty() == true)
72         {
73             AccountsTable accounts = new AccountsTable(AdminConfig.getInstance().getDBParams().getAdminDb());
74             accounts.setConnection(c);
75             
76             userinfo = accounts.authenticate(((LogonForm)form).getUsername(),
77             ((LogonForm) form).getPassword());
78             
79             if (userinfo == null)
80             {
81                 errors.add(ActionErrors.GLOBAL_ERROR,
82                 new ActionError("error.authentication.error"));
83                 
84                 try
85                 {
86                     c.close();
87                 }
88                 catch (SQLException ex)
89                 {
90                     ;
91                 }
92             }
93             else
94             {
95                 // register user login with the Ace Application Server
96
RemoteAccessClient cl = (RemoteAccessClient)request.getSession().getServletContext().getAttribute("remoteAccess");
97                 if (cl == null)
98                 {
99                     errors.add(ActionErrors.GLOBAL_ERROR,
100                     new ActionError("error.rmi.error"));
101                     
102                     AceLogger.Instance().log(AceLogger.ERROR, AceLogger.SYSTEM_LOG,
103                     "LogonAction.execute()/"
104                     + ((LogonForm)form).getUsername()
105                     + ": Could not obtain RMI client object");
106                 }
107                 else
108                 {
109                     try
110                     {
111                         authcode = cl.getRemoteAccess().getParam("com.quikj.application.web.oamp.plugin.CommunicatorClientList",
112                         "register:" + ((LogonForm)form).getUsername()
113                         + ':' + ((LogonForm) form).getPassword());
114                         if (authcode == null)
115                         {
116                             errors.add(ActionErrors.GLOBAL_ERROR,
117                             new ActionError("error.rmi.error"));
118                             
119                             AceLogger.Instance().log(AceLogger.ERROR, AceLogger.SYSTEM_LOG,
120                             "LogonAction.execute()/"
121                             + ((LogonForm)form).getUsername()
122                             + ": Could not obtain authcode from CommunicatorClientList");
123                         }
124                     }
125                     catch (Exception JavaDoc ex)
126                     {
127                         errors.add(ActionErrors.GLOBAL_ERROR,
128                             new ActionError("error.rmi.error"));
129                         
130                         AceLogger.Instance().log(AceLogger.ERROR, AceLogger.SYSTEM_LOG,
131                         "LogonAction.execute()/"
132                         + ((LogonForm)form).getUsername()
133                         + ": RMIException: " + ex.getMessage());
134                     }
135                 }
136             }
137         }
138         
139         if (errors.isEmpty() == true)
140         {
141             request.getSession().setAttribute("connection", c);
142             request.getSession().setAttribute("userInfo", userinfo);
143             
144             if (authcode != null)
145             {
146                 request.getSession().setAttribute("authCode", authcode);
147             }
148             
149             AceLogger.Instance().log(AceLogger.INFORMATIONAL, AceLogger.USER_LOG,
150             "User " + ((LogonForm)form).getUsername() + " logged in");
151             
152             return (mapping.findForward("main_menu"));
153         }
154         else
155         {
156             saveErrors(request, errors);
157             return (new ActionForward(mapping.getInput()));
158         }
159         
160     }
161 }
162
Popular Tags