KickJava   Java API By Example, From Geeks To Geeks.

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


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.server.framework.*;
16 /**
17  * Implementation of <strong>Action</strong> that validates a user logon.
18  * Based on Apache Struts framework.
19  *
20  * @author Vinod Batra
21  * @version $Revision: 1.6 $ $Date: 2004/05/03 11:09:17 $
22  */

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

40     public ActionForward execute(ActionMapping mapping,
41     ActionForm form,
42     HttpServletRequest JavaDoc request,
43     HttpServletResponse JavaDoc response)
44     throws IOException JavaDoc, ServletException JavaDoc
45     {
46         // Extract attributes we will need
47
Locale JavaDoc locale = getLocale(request);
48         ActionErrors errors = new ActionErrors();
49         
50         // check if user is allowed to access from the client host
51
AceNetworkAccess access = (AceNetworkAccess)request.getSession().getServletContext().getAttribute("accessInfo");
52         if (access != null) // specified in the config file
53
{
54             if (access.match(request.getRemoteHost()) == false)
55             {
56                 // print warning message
57
AceLogger.Instance().log(AceLogger.WARNING, AceLogger.SYSTEM_LOG,
58                 "Unauthorized access attempt from host "
59                 + request.getRemoteHost());
60
61                 // forward control to the appropriate error page
62
return mapping.findForward("restricted_access_error");
63             }
64         }
65         
66         // check if the user already has a connection
67
Connection c = (Connection)request.getSession().getAttribute("connection");
68         if (c != null) {
69             errors.add(ActionErrors.GLOBAL_ERROR,
70             new ActionError("error.already.logged.in"));
71         }
72                 
73          java.util.Date JavaDoc date = new java.util.Date JavaDoc();
74          String JavaDoc today = date.toString();
75          request.getSession().setAttribute("today", today);
76         
77          if (errors.isEmpty() == false) {
78             saveErrors(request, errors);
79             return (mapping.findForward("main_menu"));
80         }
81         else {
82             return (new ActionForward(mapping.getInput()));
83         }
84     }
85 }
86
Popular Tags