Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

AbstractDatabaseUser.java

00001 /**
00002  * C-JDBC: Clustered JDBC.
00003  * Copyright (C) 2002-2004 French National Institute For Research In Computer
00004  * Science And Control (INRIA).
00005  * Contact: c-jdbc@objectweb.org
00006  * 
00007  * This library is free software; you can redistribute it and/or modify it
00008  * under the terms of the GNU Lesser General Public License as published by the
00009  * Free Software Foundation; either version 2.1 of the License, or any later
00010  * version.
00011  * 
00012  * This library is distributed in the hope that it will be useful, but WITHOUT
00013  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
00015  * for more details.
00016  * 
00017  * You should have received a copy of the GNU Lesser General Public License
00018  * along with this library; if not, write to the Free Software Foundation,
00019  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00020  *
00021  * Initial developer(s): Emmanuel Cecchet.
00022  * Contributor(s): ______________________________________.
00023  */
00024 
00025 package org.objectweb.cjdbc.common.users;
00026 
00027 import java.io.Serializable;
00028 import java.security.Principal;
00029 
00030 /**
00031  * An <code>AbstractDatabaseUser</code> is just a login/password combination
00032  * to represent an abstract database user.
00033  * 
00034  * @author <a href="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
00035  * @version 1.0
00036  */
00037 public abstract class AbstractDatabaseUser implements Serializable, Principal
00038 {
00039   /** Login name. */
00040   protected String login;
00041 
00042   /** Password. */
00043   protected String password;
00044 
00045   /**
00046    * Creates a new <code>AbstractDatabaseUser</code> instance. The caller must
00047    * ensure that the parameters are not <code>null</code>.
00048    * 
00049    * @param login the user name.
00050    * @param password the password.
00051    */
00052   protected AbstractDatabaseUser(String login, String password)
00053   {
00054     this.login = login;
00055     this.password = password;
00056   }
00057 
00058   /**
00059    * Gets the login name.
00060    * 
00061    * @return the login name.
00062    */
00063   public String getLogin()
00064   {
00065     return login;
00066   }
00067 
00068   /**
00069    * Gets the login name.
00070    * 
00071    * @return the login name.
00072    */
00073   public String getName()
00074   {
00075     return getLogin();
00076   }
00077 
00078   /**
00079    * Gets the password.
00080    * 
00081    * @return the password.
00082    */
00083   public String getPassword()
00084   {
00085     return password;
00086   }
00087 
00088   /**
00089    * Tests if the login and password provided matches the login/password of this
00090    * object.
00091    * 
00092    * @param login a user name.
00093    * @param password a password.
00094    * @return <code>true</code> if it matches this object's login/password.
00095    */
00096   public boolean matches(String login, String password)
00097   {
00098     return (this.login.equals(login) && this.password.equals(password));
00099   }
00100 
00101   /**
00102    * Two <code>AbstractDatabaseUser</code> are equals if both objects have
00103    * same login & password.
00104    * 
00105    * @param other the object to compare with.
00106    * @return <code>true</code> if both objects have same login & password.
00107    */
00108   public boolean equals(Object other)
00109   {
00110     if ((other == null) || !(other instanceof AbstractDatabaseUser))
00111       return false;
00112 
00113     AbstractDatabaseUser user = (AbstractDatabaseUser) other;
00114     return matches(user.login, user.password);
00115   }
00116 
00117   /**
00118    * @see org.objectweb.cjdbc.common.xml.XmlComponent#getXml()
00119    */
00120   public abstract String getXml();
00121 }

Generated on Mon Apr 11 22:01:28 2005 for C-JDBC by  doxygen 1.3.9.1