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.usecases.logic;
19
20 import org.apache.shale.usecases.model.User;
21 import org.apache.shale.usecases.model.UsersDAO;
22
23 /***
24 * <p>Business logic for manipulating user profile information and
25 * validating logon credentials. The {@link UsersDAO} object used to
26 * access the underlying persistent data must be injected before
27 * any of the logic methods in this class may be used.</p>
28 *
29 * $Id: LogonLogic.java 464373 2006-10-16 04:21:54Z rahul $
30 */
31 public class LogonLogic {
32
33
34
35
36
37 /***
38 * <p>The {@link UsersDAO} object used to access our underlying
39 * persistent data.</p>
40 */
41 private UsersDAO dao = null;
42 public UsersDAO getDao() { return this.dao; }
43 public void setDao(UsersDAO dao) { this.dao = dao; }
44
45
46
47
48
49 /***
50 * <p>Validate the specified logon credientials. If valid credentials
51 * are specified, return the corresponding {@link User} instance.
52 * Otherwise, return <code>null</code>.</p>
53 *
54 * @param username Username creditial that was entered
55 * @param password Password credential that was entered
56 */
57 public User authenticate(String username, String password) {
58
59 if ((username == null) || (password == null)) {
60 return null;
61 }
62 User user = dao.findUser(username);
63 if (user == null) {
64 return null;
65 }
66 if (password.equals(user.getPassword())) {
67 return user;
68 } else {
69 return null;
70 }
71
72 }
73
74
75 /***
76 * <p>Create and return a {@link User} object that may be populated
77 * and then passed to <code>insertUser()</code> for persistence.</p>
78 */
79 public User createUser() {
80
81 return getDao().createUser();
82
83 }
84
85
86 /***
87 * <p>Pass-through method to retrieve a {@link User} by id.</p>
88 *
89 * @param id Identifier of the {@link User} to return
90 */
91 public User findUser(int id) {
92
93 return getDao().findUser(id);
94
95 }
96
97
98 /***
99 * <p>Pass-through method to retrieve a {@link User} by username.</p>
100 *
101 * @param username Username of the {@link User} to return
102 */
103 public User findUser(String username) {
104
105 return getDao().findUser(username);
106
107 }
108
109
110 /***
111 * <p>Insert a newly created {@link User} into persistent storage.</p>
112 *
113 * @param user Created {@link User} to be persisted
114 */
115 public void insertUser(User user) {
116
117 getDao().insertUser(user);
118
119 }
120
121
122 /***
123 * <p>Update an existing {@link User} into persistent storage.</p>
124 *
125 * @param user Updated {@link User} to be persisted
126 */
127 public void updateUser(User user) {
128
129 getDao().updateUser(user);
130
131 }
132
133
134 }