001: /**
002: * Sequoia: Database clustering technology.
003: * Copyright (C) 2002-2004 French National Institute For Research In Computer
004: * Science And Control (INRIA).
005: * Contact: sequoia@continuent.org
006: *
007: * Licensed under the Apache License, Version 2.0 (the "License");
008: * you may not use this file except in compliance with the License.
009: * You may obtain a copy of the License at
010: *
011: * http://www.apache.org/licenses/LICENSE-2.0
012: *
013: * Unless required by applicable law or agreed to in writing, software
014: * distributed under the License is distributed on an "AS IS" BASIS,
015: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016: * See the License for the specific language governing permissions and
017: * limitations under the License.
018: *
019: * Initial developer(s): Emmanuel Cecchet.
020: * Contributor(s): ______________________________________.
021: */package org.continuent.sequoia.common.users;
022:
023: import java.io.Serializable;
024: import java.security.Principal;
025:
026: /**
027: * An <code>AbstractDatabaseUser</code> is just a login/password combination
028: * to represent an abstract database user.
029: *
030: * @author <a href="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
031: * @version 1.0
032: */
033: public abstract class AbstractDatabaseUser implements Serializable,
034: Principal {
035: /** Login name. */
036: protected String login;
037:
038: /** Password. */
039: protected String password;
040:
041: /**
042: * Creates a new <code>AbstractDatabaseUser</code> instance. The caller must
043: * ensure that the parameters are not <code>null</code>.
044: *
045: * @param login the user name.
046: * @param password the password.
047: */
048: protected AbstractDatabaseUser(String login, String password) {
049: this .login = login;
050: this .password = password;
051: }
052:
053: /**
054: * Gets the login name.
055: *
056: * @return the login name.
057: */
058: public String getLogin() {
059: return login;
060: }
061:
062: /**
063: * Gets the login name.
064: *
065: * @return the login name.
066: */
067: public String getName() {
068: return getLogin();
069: }
070:
071: /**
072: * Gets the password.
073: *
074: * @return the password.
075: */
076: public String getPassword() {
077: return password;
078: }
079:
080: /**
081: * Tests if the login and password provided matches the login/password of this
082: * object.
083: *
084: * @param login a user name.
085: * @param password a password.
086: * @return <code>true</code> if it matches this object's login/password.
087: */
088: public boolean matches(String login, String password) {
089: return (this .login.equals(login) && this .password
090: .equals(password));
091: }
092:
093: /**
094: * Two <code>AbstractDatabaseUser</code> are equals if both objects have
095: * same login & password.
096: *
097: * @param other the object to compare with.
098: * @return <code>true</code> if both objects have same login & password.
099: */
100: public boolean equals(Object other) {
101: if ((other == null) || !(other instanceof AbstractDatabaseUser))
102: return false;
103:
104: AbstractDatabaseUser user = (AbstractDatabaseUser) other;
105: return matches(user.login, user.password);
106: }
107:
108: /**
109: * @see org.continuent.sequoia.common.xml.XmlComponent#getXml()
110: */
111: public abstract String getXml();
112: }
|