01: /*
02: * $Id: LogonAction.java 471754 2006-11-06 14:55:09Z husted $
03: *
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "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 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(ActionMapping mapping,
56: ActionForm form, HttpServletRequest request,
57: HttpServletResponse response) 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: }
|