01 package com.bea.medrec.beans;
02
03 import javax.servlet.http.HttpServletRequest;
04 import org.apache.struts.action.ActionErrors;
05 import org.apache.struts.action.ActionMapping;
06 import com.bea.medrec.utils.MedRecLog4jFactory;
07 import org.apache.log4j.Logger;
08 import org.apache.struts.validator.Resources;
09
10 /**
11 * Form bean for the user login page. This form has the following fields,
12 * with default values in square brackets:
13 * <ul>
14 * <li><b>password</b> - Entered password value
15 * <li><b>username</b> - Entered username value
16 * </ul>
17 *
18 *
19 * @author Copyright (c) 2006 by BEA Systems. All Rights Reserved.
20 */
21 public final class LoginBean extends BaseBean {
22 private static Logger logger =
23 MedRecLog4jFactory.getLogger(LoginBean.class.getName());
24
25 // Instance Variables
26 private String j_username = "";
27 private String j_password = "";
28
29 // Constructors
30 public LoginBean() {
31 }
32
33 // Getters
34 public String getJ_username() {
35 return (this.j_username);
36 }
37
38 public String getJ_password() {
39 return (this.j_password);
40 }
41
42 // Setters
43 public void setJ_username(String j_username) {
44 this.j_username = j_username;
45 }
46
47 public void setJ_password(String j_password) {
48 this.j_password = j_password;
49 }
50
51 // Public Methods
52 public void reset() {
53 this.j_password = "";
54 this.j_username = "";
55 }
56
57 /**
58 * <p>Validate login.</p>
59 *
60 * @param mapping
61 * @param request
62 *
63 * @return ActionErrors
64 */
65 public ActionErrors validate(ActionMapping mapping,
66 HttpServletRequest request) {
67 ActionErrors errors = new ActionErrors();
68 // only validate if the user has clicked "Login"
69 String loginSubmit = Resources.getMessage(request, "button.Login");
70 if (loginSubmit.equals(request.getParameter("action"))) {
71 errors = super.validate(mapping, request);
72 }
73 return errors;
74 }
75
76 public String toString() {
77 StringBuffer str = new StringBuffer();
78 str.append("LoginBean [");
79 str.append("Username: " + j_username);
80 str.append(" | Password: " + printPassword());
81 str.append("]");
82
83 return str.toString();
84 }
85
86 private String printPassword() {
87 String pwd = "";
88 for (int i = 0; i < j_password.length(); i++) pwd += "*";
89 return pwd;
90 }
91 }
|