1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.struts.apps.mailreader.actions;
22
23 import org.apache.struts.action.ActionForm;
24 import org.apache.struts.action.ActionForward;
25 import org.apache.struts.action.ActionMapping;
26 import org.apache.struts.action.ActionMessages;
27 import org.apache.struts.apps.mailreader.dao.User;
28
29 import javax.servlet.http.HttpServletRequest;
30 import javax.servlet.http.HttpServletResponse;
31
32 /**
33 * <p>
34 * Validate a user logon.
35 * </p>
36 *
37 * @version $Rev: 471754 $ $Date: 2006-11-06 08:55:09 -0600 (Mon, 06 Nov 2006) $
38 */
39 public final class LogonAction extends BaseAction {
40
41 /**
42 * <p>
43 * Use "username" and "password" fields from ActionForm to retrieve a User
44 * object from the database. If credentials are not valid, or database
45 * has disappeared, post error messages and forward to input.
46 * </p>
47 *
48 * @param mapping The ActionMapping used to select this instance
49 * @param form The optional ActionForm bean for this request (if any)
50 * @param request The HTTP request we are processing
51 * @param response The HTTP response we are creating
52 * @throws Exception if the application business logic throws
53 * an exception
54 */
55 public ActionForward execute(
56 ActionMapping mapping,
57 ActionForm form,
58 HttpServletRequest request,
59 HttpServletResponse response)
60 throws Exception {
61
62
63 String username = doGet(form, USERNAME);
64 String password = doGet(form, PASSWORD);
65 ActionMessages errors = new ActionMessages();
66 User user = doGetUser(username, password, errors);
67
68
69 if (!errors.isEmpty()) {
70 this.saveErrors(request, errors);
71 return (mapping.getInputForward());
72 }
73
74
75 doCacheUser(request, user);
76
77
78 return doFindSuccess(mapping);
79
80 }
81
82 }