View Javadoc

1   /*
2    * $Id: LogonAction.java 360442 2005-12-31 20:10:04Z husted $
3    *
4    * Copyright 2000-2004 Apache Software Foundation
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.struts.apps.mailreader.actions;
19  
20  import org.apache.struts.action.ActionForm;
21  import org.apache.struts.action.ActionForward;
22  import org.apache.struts.action.ActionMapping;
23  import org.apache.struts.action.ActionMessages;
24  import org.apache.struts.apps.mailreader.dao.User;
25  
26  import javax.servlet.http.HttpServletRequest;
27  import javax.servlet.http.HttpServletResponse;
28  
29  /***
30   * <p>
31   * Validate a user logon.
32   * </p>
33   *
34   * @version $Rev: 360442 $ $Date: 2005-12-31 13:10:04 -0700 (Sat, 31 Dec 2005) $
35   */
36  public final class LogonAction extends BaseAction {
37  
38      /***
39       * <p>
40       * Use "username" and "password" fields from ActionForm to retrieve a User
41       * object from the database. If credentials are not valid, or database
42       * has disappeared, post error messages and forward to input.
43       * </p>
44       *
45       * @param mapping  The ActionMapping used to select this instance
46       * @param form     The optional ActionForm bean for this request (if any)
47       * @param request  The HTTP request we are processing
48       * @param response The HTTP response we are creating
49       * @throws Exception if the application business logic throws
50       *                   an exception
51       */
52      public ActionForward execute(
53              ActionMapping mapping,
54              ActionForm form,
55              HttpServletRequest request,
56              HttpServletResponse response)
57              throws Exception {
58  
59          // Retrieve user
60          String username = doGet(form, USERNAME);
61          String password = doGet(form, PASSWORD);
62          ActionMessages errors = new ActionMessages();
63          User user = doGetUser(username, password, errors);
64  
65          // Report back any errors, and exit if any
66          if (!errors.isEmpty()) {
67              this.saveErrors(request, errors);
68              return (mapping.getInputForward());
69          }
70  
71          // Cache user object in session to signify logon
72          doCacheUser(request, user);
73  
74          // Done
75          return doFindSuccess(mapping);
76  
77      }
78  
79  }