KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > struts > faces > systest1 > LogonAction


1 /*
2  * Copyright 2002,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * $Id: LogonAction.java 54934 2004-10-16 17:07:50Z germuska $
17  */

18
19 package org.apache.struts.faces.systest1;
20
21 import javax.servlet.http.HttpServletRequest JavaDoc;
22 import javax.servlet.http.HttpServletResponse JavaDoc;
23
24 import org.apache.commons.beanutils.PropertyUtils;
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27
28 import org.apache.struts.action.Action;
29 import org.apache.struts.action.ActionForm;
30 import org.apache.struts.action.ActionForward;
31 import org.apache.struts.action.ActionMapping;
32 import org.apache.struts.action.ActionError;
33 import org.apache.struts.action.ActionErrors;
34
35
36 /**
37  * <p>Action to process logon attempts. It accepts only the combination
38  * "gooduser" and "goodpass", while rejecting all others. Successful
39  * login requests a logical forward "login1", while unsuccessful login
40  * returns to the input form.</p>
41  */

42
43 public class LogonAction extends Action {
44
45
46     private static final Log log = LogFactory.getLog(LogonAction.class);
47
48
49     /**
50      * <p>Process an attempted logon.</p>
51      */

52     public ActionForward execute(ActionMapping mapping,
53                                  ActionForm form,
54                                  HttpServletRequest JavaDoc request,
55                                  HttpServletResponse JavaDoc response)
56         throws Exception JavaDoc {
57
58         ActionErrors errors = new ActionErrors();
59         String JavaDoc username = (String JavaDoc)
60             PropertyUtils.getSimpleProperty(form, "username");
61         if ((username == null) || ("".equals(username))) {
62             errors.add("username",
63                          new ActionError("logon.username"));
64         }
65         String JavaDoc password = (String JavaDoc)
66             PropertyUtils.getSimpleProperty(form, "password");
67         if ((password == null) || ("".equals(password))) {
68             errors.add("password",
69                          new ActionError("logon.password"));
70         }
71         if (log.isTraceEnabled()) {
72             log.trace("username=" + username + ",password=" + password);
73         }
74         if (errors.isEmpty() &&
75             (!"gooduser".equals(username) || !"goodpass".equals(password))) {
76             errors.add(ActionErrors.GLOBAL_ERROR,
77                          new ActionError("logon.mismatch"));
78         }
79         if (errors.isEmpty()) {
80             if (log.isDebugEnabled()) {
81                 log.debug("Successful logon, forwarding to logon1");
82             }
83             return (mapping.findForward("logon1"));
84         } else {
85             if (log.isDebugEnabled()) {
86                 log.debug("Unsuccessful logon, returning to input");
87             }
88             saveErrors(request, errors);
89             return (mapping.getInputForward());
90         }
91
92
93
94     }
95
96
97 }
98
Popular Tags