KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > raptus > owxv3 > eadmin > EALoginAction


1 /*
2  * eAdmin/OWX
3  * Copyright (C) 1996-2003 OWX-Project Team <owx-team@gmx.net>
4  */

5
6 package com.raptus.owxv3.eadmin;
7
8 import java.io.IOException JavaDoc;
9
10 import javax.servlet.ServletException JavaDoc;
11 import javax.servlet.http.*;
12
13 import org.apache.struts.action.*;
14
15 import com.raptus.owxv3.*;
16 import com.raptus.owxv3.api.LoginAction;
17
18 /**
19  * Handles the login process for eAdmin
20  *
21  * <hr>
22  * <table width="100%" border="0">
23  * <tr>
24  * <td width="24%"><b>Filename</b></td><td width="76%">EALoginAction.java</td>
25  * </tr>
26  * <tr>
27  * <td width="24%"><b>Author</b></td><td width="76%">Guy Zürcher (gzuercher@raptus.com)</td>
28  * </tr>
29  * <tr>
30  * <td width="24%"><b>Date</b></td><td width="76%">17th of April 2001</td>
31  * </tr>
32  * </table>
33  * <hr>
34  * <table width="100%" border="0">
35  * <tr>
36  * <td width="24%"><b>Date / Author</b></td><td width="76%"><b>Changes</b></td>
37  * </tr>
38  * </table>
39  * <hr>
40  */

41 public class EALoginAction extends LoginAction
42 {
43     // --------------------------------------------------------- Public Methods
44

45     /**
46      * Process the specified HTTP request, and create the corresponding HTTP
47      * response (or forward to another web component that will create it).
48      * Return an <code>ActionForward</code> instance describing where and how
49      * control should be forwarded, or <code>null</code> if the response has
50      * already been completed.
51      *
52      * @param mapping The ActionMapping used to select this instance
53      * @param actionForm The optional ActionForm bean for this request (if any)
54      * @param request The HTTP request we are processing
55      * @param response The HTTP response we are creating
56      *
57      * @exception IOException if an input/output error occurs
58      * @exception ServletException if a servlet exception occurs
59      */

60     public ActionForward perform(ActionMapping mapping,
61                  ActionForm form,
62                  HttpServletRequest request,
63                  HttpServletResponse response)
64     throws IOException JavaDoc, ServletException JavaDoc
65     {
66         EALoginForm owaf = (EALoginForm) form;
67         String JavaDoc element = request.getParameter(Constants.HTTPGET_PARAM_ELEMENT);
68         if(element == null || element.length() == 0)
69             element = owaf.getElement();
70
71         if(element != null && element.length() > 0)
72         {
73             if(element.compareToIgnoreCase("login") == 0) // GET/POST
74
{
75                 return performLogin(mapping, owaf, request, response);
76             }
77             else if(element.compareToIgnoreCase("logout") == 0) // GET
78
{
79                 return performLogout(mapping, owaf, request, response);
80             }
81         }
82         else
83             LoggingManager.log("Unkown element " + element + " requested", this);
84
85         return mapping.findForward(Constants.SCREEN_ERROR_UNKNOWNELEMENT);
86     }
87
88     /**
89      *
90      */

91     public ActionForward performLogin(ActionMapping mapping,
92                       EALoginForm form,
93                       HttpServletRequest request,
94                       HttpServletResponse response)
95     throws IOException JavaDoc, ServletException JavaDoc
96     {
97         ActionErrors errors = new ActionErrors();
98
99         String JavaDoc username = form.getUsername();
100         String JavaDoc password = form.getPassword();
101
102         LoggingManager.log("A user <" + username + "> tries to log in.", this);
103
104         String JavaDoc nextView = Constants.SCREEN_LOGIN;
105         if(username != null && password != null)
106         {
107             if(loginUser(request, username, password))
108                 nextView = Constants.SCREEN_SUCCESS;
109             else
110                 errors.add("loginerrors", new ActionError(Constants.MESSAGE_I18N_LOGINFAILED));
111         }
112         else
113             errors.add("loginerrors", new ActionError(Constants.MESSAGE_I18N_LOGINWELCOME));
114
115         saveErrors(request, errors);
116         LoggingManager.log("Forwarding user to struts screen <" + nextView + ">", this);
117         LoggingManager.log(errors.size() + " errors during login phase.", this);
118         return mapping.findForward(nextView);
119     }
120
121     /**
122      * forward to logout screen no matter what happend
123      */

124     public ActionForward performLogout(ActionMapping mapping,
125                        EALoginForm form,
126                        HttpServletRequest request,
127                        HttpServletResponse response)
128     throws IOException JavaDoc, ServletException JavaDoc
129     {
130         //ADDEDBYJANCSI
131
//Virtualhost vh = new Virtualhost();
132
//Virtualhost vh = XMLVModuleManager.getInstance().getVirtualhost();
133
XMLConfigManager cm=XMLConfigManager.getInstance();
134         form.setWebsiteURL( cm.getPropertyByTree("virtualhost","hostname") );
135
136         HttpSession session = request.getSession();
137         logoutUser(session);
138
139         return mapping.findForward(Constants.SCREEN_LOGOUT);
140     }
141
142 }
143
144 // eof
145
Popular Tags