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