View Javadoc

1   /*
2    * Copyright (c) 2004 UNINETT FAS
3    *
4    * This program is free software; you can redistribute it and/or modify it
5    * under the terms of the GNU General Public License as published by the Free
6    * Software Foundation; either version 2 of the License, or (at your option)
7    * any later version.
8    *
9    * This program is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11   * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12   * more details.
13   *
14   * You should have received a copy of the GNU General Public License along with
15   * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
16   * Place - Suite 330, Boston, MA 02111-1307, USA.
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          // Sanity checks.
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  }