/*
 * JBoss, Home of Professional Open Source
 * Copyright 2005, JBoss Inc., and individual contributors as indicated
 * by the @authors tag. See the copyright.txt in the distribution for a
 * full listing of individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package javax.resource.spi.security;

import java.util.Arrays;

import javax.resource.spi.ManagedConnectionFactory;
import javax.resource.spi.SecurityException;

/**
 * The class PasswordCredential is a placeholder for username and password.
 */

public class PasswordCredential
   implements java.io.Serializable
{
   private String userName;
   private char[] password;

   private ManagedConnectionFactory mcf = null;

   /**
    * Constructor, creates a new password credential
    */
   public PasswordCredential( String userName, char[] password )
   {
      this.userName = userName;
      this.password = password;
   }

   /**
    * Returns the username
    * @return Username
    */
   public String getUserName()
   {
      return userName;
   }

   /**
    * Returns the password
    * @return password
    */
   public char[] getPassword()
   {
      return password;
   }

   /**
    * Get the managed connection factory associated with this username
    * password pair.
    */
   public ManagedConnectionFactory getManagedConnectionFactory()
   {
      return mcf;
   }

   /**
    * Set the managed connection factory associated with this username
    * password pair.
    */
   public void setManagedConnectionFactory( ManagedConnectionFactory mcf )
   {
      this.mcf = mcf;
   }

   /**
    * Tests object for equality
    */
   public boolean equals( Object other )
   {
      if (this == other)
         return true;
      if (other == null || getClass() != other.getClass() )
	      return false;
      final PasswordCredential otherCredential = (PasswordCredential) other;
      return userName.equals( otherCredential.userName ) &&
             Arrays.equals( password, otherCredential.password );
   }

   /**
    * Generates a hashCode for this object, the username should
    * be good enough to get a good distribution
    */
   public int hashCode()
   {
      return userName.hashCode();
   }
}
