001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package javax.resource.spi.security;
023:
024: import java.io.Serializable;
025: import java.util.Arrays;
026:
027: import javax.resource.spi.ManagedConnectionFactory;
028:
029: /**
030: * The class PasswordCredential is a placeholder for username and password.
031: */
032: public final class PasswordCredential implements Serializable {
033: /** @since 4.0.0 */
034: static final long serialVersionUID = -1770833344350711674L;
035:
036: /** The userName */
037: private String userName;
038: /** The password */
039: private char[] password;
040:
041: /** The managed connection factory */
042: private ManagedConnectionFactory mcf = null;
043:
044: /**
045: * Constructor, creates a new password credential
046: *
047: * @param userName the user name
048: * @param password the password
049: */
050: public PasswordCredential(String userName, char[] password) {
051: this .userName = userName;
052: this .password = password;
053: }
054:
055: /**
056: * Returns the username
057: *
058: * @return Username
059: */
060: public String getUserName() {
061: return userName;
062: }
063:
064: /**
065: * Returns the password
066: *
067: * @return password
068: */
069: public char[] getPassword() {
070: return password;
071: }
072:
073: /**
074: * Get the managed connection factory associated with this username password
075: * pair.
076: *
077: * @return the managed connection factory
078: */
079: public ManagedConnectionFactory getManagedConnectionFactory() {
080: return mcf;
081: }
082:
083: /**
084: * Set the managed connection factory associated with this username password
085: * pair.
086: *
087: * @param mcf the managed connection factory
088: */
089: public void setManagedConnectionFactory(ManagedConnectionFactory mcf) {
090: this .mcf = mcf;
091: }
092:
093: public boolean equals(Object other) {
094: if (this == other)
095: return true;
096: if (other == null || getClass() != other.getClass())
097: return false;
098: final PasswordCredential otherCredential = (PasswordCredential) other;
099: return userName.equals(otherCredential.userName)
100: && Arrays.equals(password, otherCredential.password);
101: }
102:
103: public int hashCode() {
104: return userName.hashCode();
105: }
106: }
|