KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > continuent > sequoia > common > users > AbstractDatabaseUser


1 /**
2  * Sequoia: Database clustering technology.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: sequoia@continuent.org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  * Initial developer(s): Emmanuel Cecchet.
20  * Contributor(s): ______________________________________.
21  */

22
23 package org.continuent.sequoia.common.users;
24
25 import java.io.Serializable JavaDoc;
26 import java.security.Principal JavaDoc;
27
28 import org.continuent.sequoia.controller.authentication.AccessControl;
29
30 /**
31  * An <code>AbstractDatabaseUser</code> is just a login/password combination
32  * to represent an abstract database user.
33  *
34  * @author <a HREF="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
35  * @version 1.0
36  */

37 public abstract class AbstractDatabaseUser implements Serializable JavaDoc, Principal JavaDoc
38 {
39   /** Login name. */
40   protected String JavaDoc login;
41
42   /** Password. */
43   protected String JavaDoc password;
44
45   /** Access control list */
46   private AccessControl accessControl;
47
48   /**
49    * Creates a new <code>AbstractDatabaseUser</code> instance. The caller must
50    * ensure that the parameters are not <code>null</code>.
51    *
52    * @param login the user name.
53    * @param password the password.
54    */

55   protected AbstractDatabaseUser(String JavaDoc login, String JavaDoc password)
56   {
57     this.login = login;
58     this.password = password;
59   }
60
61   /**
62    * Returns the accessControl value.
63    *
64    * @return Returns the accessControl.
65    */

66   public AccessControl getAccessControl()
67   {
68     return accessControl;
69   }
70
71   /**
72    * Sets the accessControl value.
73    *
74    * @param accessControl The accessControl to set.
75    */

76   public void setAccessControl(AccessControl accessControl)
77   {
78     this.accessControl = accessControl;
79   }
80
81   /**
82    * Gets the login name.
83    *
84    * @return the login name.
85    */

86   public String JavaDoc getLogin()
87   {
88     return login;
89   }
90
91   /**
92    * Gets the login name.
93    *
94    * @return the login name.
95    */

96   public String JavaDoc getName()
97   {
98     return getLogin();
99   }
100
101   /**
102    * Gets the password.
103    *
104    * @return the password.
105    */

106   public String JavaDoc getPassword()
107   {
108     return password;
109   }
110
111   /**
112    * Tests if the login and password provided matches the login/password of this
113    * object.
114    *
115    * @param login a user name.
116    * @param password a password.
117    * @return <code>true</code> if it matches this object's login/password.
118    */

119   public boolean matches(String JavaDoc login, String JavaDoc password)
120   {
121     return (this.login.equals(login) && this.password.equals(password));
122   }
123
124   /**
125    * Two <code>AbstractDatabaseUser</code> are equals if both objects have
126    * same login & password.
127    *
128    * @param other the object to compare with.
129    * @return <code>true</code> if both objects have same login & password.
130    */

131   public boolean equals(Object JavaDoc other)
132   {
133     if ((other == null) || !(other instanceof AbstractDatabaseUser))
134       return false;
135
136     AbstractDatabaseUser user = (AbstractDatabaseUser) other;
137     return matches(user.login, user.password);
138   }
139
140   /**
141    * @see org.continuent.sequoia.common.xml.XmlComponent#getXml()
142    */

143   public abstract String JavaDoc getXml();
144 }
145
Popular Tags