Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
Logon |
|
| 1.8;1.8 |
1 | /* | |
2 | * Licensed to the Apache Software Foundation (ASF) under one or more | |
3 | * contributor license agreements. See the NOTICE file distributed with | |
4 | * this work for additional information regarding copyright ownership. | |
5 | * The ASF licenses this file to you under the Apache License, Version 2.0 | |
6 | * (the "License"); you may not use this file except in compliance with | |
7 | * the License. You may obtain a copy of the License at | |
8 | * | |
9 | * http://www.apache.org/licenses/LICENSE-2.0 | |
10 | * | |
11 | * Unless required by applicable law or agreed to in writing, software | |
12 | * distributed under the License is distributed on an "AS IS" BASIS, | |
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 | * See the License for the specific language governing permissions and | |
15 | * limitations under the License. | |
16 | * | |
17 | * $Id: Logon.java 464373 2006-10-16 04:21:54Z rahul $ | |
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 | 0 | public class Logon extends BaseViewController { |
34 | ||
35 | ||
36 | // -------------------------------------------------------- Static Variables | |
37 | ||
38 | ||
39 | /** | |
40 | * <p><code>Log</code> instance for this class.</p> | |
41 | */ | |
42 | 0 | private static final Log log = LogFactory.getLog(Logon.class); |
43 | ||
44 | ||
45 | // -------------------------------------------------------------- Properties | |
46 | ||
47 | ||
48 | /** | |
49 | * <p>The password input field.</p> | |
50 | */ | |
51 | 0 | private String password = null; |
52 | ||
53 | ||
54 | /** | |
55 | * <p>The username input field.</p> | |
56 | */ | |
57 | 0 | private String username = null; |
58 | ||
59 | ||
60 | /** | |
61 | * @return Returns the password. | |
62 | */ | |
63 | public String getPassword() { | |
64 | 0 | return this.password; |
65 | } | |
66 | ||
67 | ||
68 | /** | |
69 | * @param password The password to set. | |
70 | */ | |
71 | public void setPassword(String password) { | |
72 | 0 | this.password = password; |
73 | 0 | } |
74 | ||
75 | ||
76 | /** | |
77 | * @return Returns the username. | |
78 | */ | |
79 | public String getUsername() { | |
80 | 0 | return this.username; |
81 | } | |
82 | ||
83 | ||
84 | /** | |
85 | * @param username The username to set. | |
86 | */ | |
87 | public void setUsername(String username) { | |
88 | 0 | this.username = username; |
89 | 0 | } |
90 | ||
91 | ||
92 | // ---------------------------------------------------------- Event Handlers | |
93 | ||
94 | ||
95 | /** | |
96 | * <p>Authenticate this user and proceed based on the results.</p> | |
97 | */ | |
98 | public String logon() { | |
99 | ||
100 | 0 | if (log.isDebugEnabled()) { |
101 | 0 | log.debug("logon(" + username + "," + password + ")"); |
102 | } | |
103 | ||
104 | 0 | User user = null; |
105 | try { | |
106 | 0 | user = getUserDatabase().findUser(username); |
107 | 0 | } catch (ExpiredPasswordException e) { |
108 | 0 | log.debug(e.getCause()); |
109 | 0 | } |
110 | 0 | if ((user != null) && (user.getPassword().equals(password))) { |
111 | 0 | getState().setUser(user); |
112 | 0 | return "success"; |
113 | } | |
114 | ||
115 | // Append an error message | |
116 | // FIXME - use Commons Resources to localize this message | |
117 | 0 | getFacesContext().addMessage(null, |
118 | new FacesMessage("Invalid username or password, please try again")); | |
119 | ||
120 | // Redisplay the logon page | |
121 | 0 | return null; |
122 | ||
123 | } | |
124 | ||
125 | ||
126 | // -------------------------------------------------- ViewController Methods | |
127 | ||
128 | ||
129 | } |