1 /**
2 *
3 * Copyright 2003-2004 The Apache Software Foundation
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18
19
20
21
22
23
24 package javax.resource.spi.security;
25
26 import java.io.Serializable;
27 import java.util.Arrays;
28 import javax.resource.spi.ManagedConnectionFactory;
29
30 /**
31 *
32 *
33 *
34 * @version $Rev: 46019 $ $Date: 2004-09-14 02:56:06 -0700 (Tue, 14 Sep 2004) $
35 */
36 public final class PasswordCredential implements Serializable {
37 private String userName;
38 private char[] password;
39 private ManagedConnectionFactory mcf;
40
41 public PasswordCredential(String userName, char[] password) {
42 this.userName = userName;
43 this.password = (char[]) password.clone();
44 }
45
46 public String getUserName() {
47 return userName;
48 }
49
50 public char[] getPassword() {
51 return (char[]) password.clone();
52 }
53
54 public ManagedConnectionFactory getManagedConnectionFactory() {
55 return mcf;
56 }
57
58 public void setManagedConnectionFactory(ManagedConnectionFactory mcf) {
59 this.mcf = mcf;
60 }
61
62 public boolean equals(Object o) {
63 if (this == o) return true;
64 if (!(o instanceof PasswordCredential)) return false;
65
66 final PasswordCredential credential = (PasswordCredential) o;
67
68 if (!Arrays.equals(password, credential.password)) return false;
69 if (!userName.equals(credential.userName)) return false;
70
71 return true;
72 }
73
74 public int hashCode() {
75
76 int result = userName.hashCode();
77 for (int i=0; i<password.length; i++) {
78 result *= password[i];
79 }
80 return result;
81 }
82 }