2009/05/20 - Apache Shale has been retired.
For more information, please explore the Attic.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.shale.examples.mailreader;
21
22 import javax.faces.application.FacesMessage;
23
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26 import org.apache.struts.apps.mailreader.dao.ExpiredPasswordException;
27 import org.apache.struts.apps.mailreader.dao.User;
28
29 /***
30 * <p><code>ViewController</code> for the <code>logon</code> page.</p>
31 */
32
33 public class Logon extends BaseViewController {
34
35
36
37
38
39 /***
40 * <p><code>Log</code> instance for this class.</p>
41 */
42 private static final Log log = LogFactory.getLog(Logon.class);
43
44
45
46
47
48 /***
49 * <p>The password input field.</p>
50 */
51 private String password = null;
52
53
54 /***
55 * <p>The username input field.</p>
56 */
57 private String username = null;
58
59
60 /***
61 * @return Returns the password.
62 */
63 public String getPassword() {
64 return this.password;
65 }
66
67
68 /***
69 * @param password The password to set.
70 */
71 public void setPassword(String password) {
72 this.password = password;
73 }
74
75
76 /***
77 * @return Returns the username.
78 */
79 public String getUsername() {
80 return this.username;
81 }
82
83
84 /***
85 * @param username The username to set.
86 */
87 public void setUsername(String username) {
88 this.username = username;
89 }
90
91
92
93
94
95 /***
96 * <p>Authenticate this user and proceed based on the results.</p>
97 */
98 public String logon() {
99
100 if (log.isDebugEnabled()) {
101 log.debug("logon(" + username + "," + password + ")");
102 }
103
104 User user = null;
105 try {
106 user = getUserDatabase().findUser(username);
107 } catch (ExpiredPasswordException e) {
108 log.debug(e.getCause());
109 }
110 if ((user != null) && (user.getPassword().equals(password))) {
111 getState().setUser(user);
112 return "success";
113 }
114
115
116
117 getFacesContext().addMessage(null,
118 new FacesMessage("Invalid username or password, please try again"));
119
120
121 return null;
122
123 }
124
125
126
127
128
129 }