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 package org.apache.shale.examples.mailreaderjpa;
19
20 import org.apache.mailreaderjpa.User;
21 import org.apache.shale.view.AbstractViewController;
22
23 /***
24 * <p>Backing bean for <code>/logon.jsp</code> view. Upon completion of a
25 * successful logon, a <code>User</code> instance for the logged on user will
26 * be stored in the session-scoped <code>state</code> bean.</p>
27 */
28 public class Logon extends AbstractViewController {
29
30
31
32
33
34 /***
35 * <p>The business {@link Logic} for this application. This value
36 * will be injected, based on the managed bean configuration.</p>
37 */
38 private Logic logic = null;
39
40
41 /***
42 * <p>Return the business {@link Logic} for this application.</p>
43 */
44 public Logic getLogic() {
45 return this.logic;
46 }
47
48
49 /***
50 * <p>Set the business {@link Logic} for this application.</p>
51 *
52 * @param logic The new business logic instance
53 */
54 public void setLogic(Logic logic) {
55 this.logic = logic;
56 }
57
58
59 /***
60 * <p>The per-user {@link State} instance we are associated with. This
61 * value will be injected, based on the managed bean configuration.</p>
62 */
63 private State state = null;
64
65
66 /***
67 * <p>Return the per-user {@link State} instance we are associated with.</p>
68 */
69 public State getState() {
70 return this.state;
71 }
72
73
74 /***
75 * <p>Set the per-user {@link State} instance we are associated with.</p>
76 *
77 * @param state The new State instance
78 */
79 public void setState(State state) {
80 this.state = state;
81 }
82
83
84
85
86
87 private String username;
88
89 public String getUsername() {
90 return username;
91 }
92
93 public void setUsername(String username) {
94 this.username = username;
95 }
96
97 private String password;
98
99 public String getPassword() {
100 return password;
101 }
102
103 public void setPassword(String password) {
104 this.password = password;
105 }
106
107
108
109
110
111 /***
112 * <p>Ensure that the database content has been bootstrapped before
113 * we try to authenticate a user.</p>
114 */
115 public void preprocess() {
116 getLogic().bootstrap();
117 }
118
119
120
121
122
123 /***
124 * <p>Handle a request to log this user on.</p>
125 */
126 public String logon() {
127
128 try {
129 User user = getLogic().authenticate(getUsername(), getPassword());
130 if (user != null) {
131 if (user.getPassword().equals(getPassword())) {
132 getState().setUser(user);
133 return "success";
134 }
135 }
136 } catch (Exception e) {
137 log("Exception authenticating user", e);
138 error("Exception authenticating user: " + e);
139 return null;
140 }
141 error("Invalid username and/or password, please try again");
142 return null;
143
144 }
145
146
147 }