1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package no.feide.moria.directory;
21
22 /***
23 * Represents a set of user credentials, that is, a username/password pair. Used
24 * for Moria authentication methods, and may be expanded to support other types
25 * of credentials in a future version <br>
26 * <br>
27 * Note that this is a subset of the functionality offered by the Moria 1
28 * <code>Credentials</code> class.
29 */
30 public class Credentials {
31
32 /*** Internal representation of the username. */
33 private final String username;
34
35 /*** Internal representation of the user's password. */
36 private final String password;
37
38
39 /***
40 * Constructor. Creates a new set of credentials consisting of a
41 * username/password pair.
42 * @param username
43 * The username. May not be <code>null</code> or an empty
44 * string.
45 * @param password
46 * The user's password. May not be <code>null</code> or an
47 * empty string.
48 * @throws IllegalArgumentException
49 * If <code>username</code> or <code>password</code> is null
50 * or an empty string.
51 */
52 public Credentials(final String username, final String password) {
53
54
55 if (username == null || username.length() == 0)
56 throw new IllegalArgumentException("User name must be a non-empty string.");
57 if (password == null || password.length() == 0)
58 throw new IllegalArgumentException("Password must be a non-empty string.");
59
60 this.username = username;
61 this.password = password;
62
63 }
64
65
66 /***
67 * Retrieves the username part of the credentials.
68 * @return A newly allocated <code>String</code> containing the username.
69 */
70 public final String getUsername() {
71
72 return new String(username);
73
74 }
75
76
77 /***
78 * Retrieves the password part of the credentials.
79 * @return A newly allocated <code>String</code> containing the password.
80 */
81 public final String getPassword() {
82
83 return new String(password);
84
85 }
86
87 }