KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > raptus > owxv3 > pub > pubLoginAction


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

5
6 package com.raptus.owxv3.pub;
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 pubLoginAction 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         pubLoginForm owaf = (pubLoginForm) 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                       pubLoginForm 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             {
109                 nextView = Constants.SCREEN_SUCCESS;
110             }
111             else
112             {
113                 errors.add("loginerrors", new ActionError(Constants.MESSAGE_I18N_LOGINFAILED));
114                 nextView = Constants.SCREEN_FAILED;
115             }
116         }
117         else
118         {
119             errors.add("loginerrors", new ActionError(Constants.MESSAGE_I18N_LOGINWELCOME));
120             //nextView = Constants.SCREEN_LOGIN;
121
}
122
123         saveErrors(request, errors);
124         LoggingManager.log("Forwarding user to struts screen <" + nextView + ">", this);
125         LoggingManager.log(errors.size() + " errors during login phase.", this);
126         return mapping.findForward(nextView);
127     }
128
129     /**
130      * forward to logout screen no matter what happend
131      */

132     public ActionForward performLogout(ActionMapping mapping,
133                        pubLoginForm form,
134                        HttpServletRequest request,
135                        HttpServletResponse response)
136     throws IOException JavaDoc, ServletException JavaDoc
137     {
138         //ADDEDBYJANCSI
139
//Virtualhost vh = new Virtualhost();
140
//Virtualhost vh = XMLVModuleManager.getInstance().getVirtualhost();
141
XMLConfigManager cm=XMLConfigManager.getInstance();
142         form.setWebsiteURL( cm.getPropertyByTree("virtualhost","hostname") );
143
144         HttpSession session = request.getSession();
145         logoutUser(session);
146
147         return mapping.findForward(Constants.SCREEN_LOGOUT);
148     }
149
150 }
151
152 // eof
153
Popular Tags