1 /***
2 * The contents of this file are subject to the Mozilla Public
3 * License Version 1.1 (the "License"); you may not use this file
4 * except in compliance with the License. You may obtain a copy of
5 * the License at http://www.mozilla.org/MPL/
6 *
7 * Software distributed under the License is distributed on an "AS
8 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9 * implied. See the License for the specific language governing
10 * rights and limitations under the License.
11 *
12 * The Original Code is pow2toolkit library.
13 *
14 * The Initial Owner of the Original Code is
15 * Power Of Two S.R.L. (www.pow2.com)
16 *
17 * Portions created by Power Of Two S.R.L. are
18 * Copyright (C) Power Of Two S.R.L.
19 * All Rights Reserved.
20 *
21 * Contributor(s):
22 */
23
24 package com.pow2.user.dao;
25
26 import com.pow2.user.User;
27
28
29 /***
30 * Utility class for User management
31 *
32 * @author Luca Fossato
33 * @created 30 aprile 2002
34 */
35 public class UserDAOUtil
36 {
37 /***
38 * Update the input User object with the user informations
39 * retrieved from the data provider.
40 * <br>
41 * This method uses the User <code>login</code>
42 * and <code>passwd</code> properties to execute the login procedure.
43 *
44 * @param dao the UserDAO instance
45 * @param login the user login
46 * @param passwd the user password
47 * @return the retrieved User object if the login is succesfull;
48 * null if login fails
49 * @exception Exception if any error occurs
50 */
51 protected static User getUser(UserDAO dao, String login, String passwd) throws Exception
52 {
53 User user = new User();
54
55 user.setLogin(login);
56 user.setPasswd(passwd);
57 dao.getUser(user);
58
59
60 return (user.isAuthenticated()) ? user : null;
61 }
62
63
64 /***
65 * Get the log string about the user authentication procedure
66 *
67 * @param user the User object
68 * @return the log string about the user authentication procedure
69 */
70 protected static String getAuthenticationLog(User user)
71 {
72 if (user == null)
73 return("::getAuthenticationLog - input user is null. Why ?");
74
75 StringBuffer sb = new StringBuffer();
76
77 return ((user.isAuthenticated()) ?
78 sb.append("::getUser - returned user [")
79 .append(user.getFirstName()).append(", ")
80 .append(user.getLastName()).append("]")
81 .toString() :
82 sb.append("::getUser - cannot authenticate user with login [")
83 .append(user.getLogin())
84 .append("]")
85 .toString());
86 }
87 }