View Javadoc

1   /*
2   Karma core - Core of the Karma application
3   Copyright (C) 2004  Toolforge <www.toolforge.nl>
4   
5   This library is free software; you can redistribute it and/or
6   modify it under the terms of the GNU Lesser General Public
7   License as published by the Free Software Foundation; either
8   version 2.1 of the License, or (at your option) any later version.
9   
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  Lesser General Public License for more details.
14  
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  */
19  package nl.toolforge.karma.core.vc;
20  
21  
22  
23  /***
24   * @author D.A. Smedes
25   * @version $Id: Authenticator.java,v 1.9 2004/11/02 22:26:44 asmedes Exp $
26   */
27  public final class Authenticator {
28  
29    private String workingContext = null;
30    private String id = null;
31    private String username = null;
32    private String password = null;
33  
34    public Authenticator(String id) {
35      setId(id);
36    }
37  
38    /***
39     * Empty constructor (generally only used by Digesters).
40     */
41    public Authenticator() {
42      // Empty
43    }
44  
45    public String getWorkingContext() {
46      return workingContext;
47    }
48  
49    public void setWorkingContext(String workingContext) {
50  
51      if ("".equals(workingContext) || workingContext == null) {
52        throw new IllegalArgumentException(
53            "The `working-context`-attribute for an authenticator cannot be null or an empty string.");
54      }
55      this.workingContext = workingContext;
56    }
57  
58    public String getId() {
59  
60      return id;
61    }
62  
63    public void setId(String id) {
64  
65      if ("".equals(id) || id == null) {
66        throw new IllegalArgumentException(
67            "The `id`-attribute for an authenticator cannot be null or an empty string.");
68      }
69      this.id = id;
70    }
71  
72    public String getUsername() {
73      return username;
74    }
75  
76    public void setUsername(String username) {
77      this.username = username;
78    }
79  
80    /***
81     * Returns the password (encrypted) or an empty String if the password is null.
82     *
83     * @return
84     */
85    public String getPassword() {
86      return (password == null ? "" : password);
87    }
88  
89    public void setPassword(String password) {
90      this.password = password;
91    }
92  
93    public AuthenticatorKey getAuthenticatorKey() {
94      return new AuthenticatorKey(workingContext, id);
95    }
96  }