author | weijun |
Wed, 26 Nov 2014 15:28:46 +0800 | |
changeset 27771 | 360714d431ab |
parent 25859 | 3317bb8137f4 |
child 29492 | a4bf9a570035 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
18830 | 2 |
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package javax.security.auth.kerberos; |
|
27 |
||
28 |
import java.util.Arrays; |
|
29 |
import javax.crypto.SecretKey; |
|
30 |
import javax.security.auth.DestroyFailedException; |
|
31 |
||
32 |
/** |
|
33 |
* This class encapsulates a long term secret key for a Kerberos |
|
34 |
* principal.<p> |
|
35 |
* |
|
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
23732
diff
changeset
|
36 |
* A {@code KerberosKey} object includes an EncryptionKey, a |
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
23732
diff
changeset
|
37 |
* {@link KerberosPrincipal} as its owner, and the version number |
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
23732
diff
changeset
|
38 |
* of the key.<p> |
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
23732
diff
changeset
|
39 |
* |
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
23732
diff
changeset
|
40 |
* An EncryptionKey is defined in Section 4.2.9 of the Kerberos Protocol |
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
23732
diff
changeset
|
41 |
* Specification (<a href=http://www.ietf.org/rfc/rfc4120.txt>RFC 4120</a>) as: |
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
23732
diff
changeset
|
42 |
* <pre> |
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
23732
diff
changeset
|
43 |
* EncryptionKey ::= SEQUENCE { |
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
23732
diff
changeset
|
44 |
* keytype [0] Int32 -- actually encryption type --, |
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
23732
diff
changeset
|
45 |
* keyvalue [1] OCTET STRING |
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
23732
diff
changeset
|
46 |
* } |
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
23732
diff
changeset
|
47 |
* </pre> |
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
23732
diff
changeset
|
48 |
* The key material of a {@code KerberosKey} is defined as the value |
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
23732
diff
changeset
|
49 |
* of the {@code keyValue} above.<p> |
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
23732
diff
changeset
|
50 |
* |
2 | 51 |
* All Kerberos JAAS login modules that obtain a principal's password and |
9499 | 52 |
* generate the secret key from it should use this class. |
53 |
* Sometimes, such as when authenticating a server in |
|
2 | 54 |
* the absence of user-to-user authentication, the login module will store |
55 |
* an instance of this class in the private credential set of a |
|
56 |
* {@link javax.security.auth.Subject Subject} during the commit phase of the |
|
57 |
* authentication process.<p> |
|
58 |
* |
|
9499 | 59 |
* A Kerberos service using a keytab to read secret keys should use |
60 |
* the {@link KeyTab} class, where latest keys can be read when needed.<p> |
|
61 |
* |
|
2 | 62 |
* It might be necessary for the application to be granted a |
63 |
* {@link javax.security.auth.PrivateCredentialPermission |
|
27771
360714d431ab
8061253: Spec cleanup for some security-related classes
weijun
parents:
25859
diff
changeset
|
64 |
* PrivateCredentialPermission} if it needs to access the {@code KerberosKey} |
2 | 65 |
* instance from a Subject. This permission is not needed when the |
66 |
* application depends on the default JGSS Kerberos mechanism to access the |
|
27771
360714d431ab
8061253: Spec cleanup for some security-related classes
weijun
parents:
25859
diff
changeset
|
67 |
* {@code KerberosKey}. In that case, however, the application will need an |
2 | 68 |
* appropriate |
23732
44fe768edfd2
8035986: KerberosKey algorithm names are not specified
weijun
parents:
18830
diff
changeset
|
69 |
* {@link javax.security.auth.kerberos.ServicePermission ServicePermission}.<p> |
44fe768edfd2
8035986: KerberosKey algorithm names are not specified
weijun
parents:
18830
diff
changeset
|
70 |
* |
44fe768edfd2
8035986: KerberosKey algorithm names are not specified
weijun
parents:
18830
diff
changeset
|
71 |
* When creating a {@code KerberosKey} using the |
44fe768edfd2
8035986: KerberosKey algorithm names are not specified
weijun
parents:
18830
diff
changeset
|
72 |
* {@link #KerberosKey(KerberosPrincipal, char[], String)} constructor, |
44fe768edfd2
8035986: KerberosKey algorithm names are not specified
weijun
parents:
18830
diff
changeset
|
73 |
* an implementation may accept non-IANA algorithm names (For example, |
44fe768edfd2
8035986: KerberosKey algorithm names are not specified
weijun
parents:
18830
diff
changeset
|
74 |
* "ArcFourMac" for "rc4-hmac"), but the {@link #getAlgorithm} method |
44fe768edfd2
8035986: KerberosKey algorithm names are not specified
weijun
parents:
18830
diff
changeset
|
75 |
* must always return the IANA algorithm name.<p> |
44fe768edfd2
8035986: KerberosKey algorithm names are not specified
weijun
parents:
18830
diff
changeset
|
76 |
* |
44fe768edfd2
8035986: KerberosKey algorithm names are not specified
weijun
parents:
18830
diff
changeset
|
77 |
* @implNote Old algorithm names used before JDK 9 are supported in the |
44fe768edfd2
8035986: KerberosKey algorithm names are not specified
weijun
parents:
18830
diff
changeset
|
78 |
* {@link #KerberosKey(KerberosPrincipal, char[], String)} constructor in this |
44fe768edfd2
8035986: KerberosKey algorithm names are not specified
weijun
parents:
18830
diff
changeset
|
79 |
* implementation for compatibility reasons, which are "DES" (and null) for |
44fe768edfd2
8035986: KerberosKey algorithm names are not specified
weijun
parents:
18830
diff
changeset
|
80 |
* "des-cbc-md5", "DESede" for "des3-cbc-sha1-kd", "ArcFourHmac" for "rc4-hmac", |
44fe768edfd2
8035986: KerberosKey algorithm names are not specified
weijun
parents:
18830
diff
changeset
|
81 |
* "AES128" for "aes128-cts-hmac-sha1-96", and "AES256" for |
44fe768edfd2
8035986: KerberosKey algorithm names are not specified
weijun
parents:
18830
diff
changeset
|
82 |
* "aes256-cts-hmac-sha1-96". |
2 | 83 |
* |
84 |
* @author Mayank Upadhyay |
|
85 |
* @since 1.4 |
|
86 |
*/ |
|
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
23732
diff
changeset
|
87 |
public class KerberosKey implements SecretKey { |
2 | 88 |
|
89 |
private static final long serialVersionUID = -4625402278148246993L; |
|
90 |
||
91 |
/** |
|
92 |
* The principal that this secret key belongs to. |
|
93 |
* |
|
94 |
* @serial |
|
95 |
*/ |
|
96 |
private KerberosPrincipal principal; |
|
97 |
||
98 |
/** |
|
99 |
* the version number of this secret key |
|
100 |
* |
|
101 |
* @serial |
|
102 |
*/ |
|
23732
44fe768edfd2
8035986: KerberosKey algorithm names are not specified
weijun
parents:
18830
diff
changeset
|
103 |
private final int versionNum; |
2 | 104 |
|
105 |
/** |
|
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
23732
diff
changeset
|
106 |
* {@code KeyImpl} is serialized by writing out the ASN.1 encoded bytes |
2 | 107 |
* of the encryption key. |
108 |
* |
|
109 |
* @serial |
|
110 |
*/ |
|
111 |
||
112 |
private KeyImpl key; |
|
113 |
private transient boolean destroyed = false; |
|
114 |
||
115 |
/** |
|
27771
360714d431ab
8061253: Spec cleanup for some security-related classes
weijun
parents:
25859
diff
changeset
|
116 |
* Constructs a {@code KerberosKey} from the given bytes when the key type |
360714d431ab
8061253: Spec cleanup for some security-related classes
weijun
parents:
25859
diff
changeset
|
117 |
* and key version number are known. This can be used when reading the |
360714d431ab
8061253: Spec cleanup for some security-related classes
weijun
parents:
25859
diff
changeset
|
118 |
* secret key information from a Kerberos "keytab". |
2 | 119 |
* |
120 |
* @param principal the principal that this secret key belongs to |
|
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
23732
diff
changeset
|
121 |
* @param keyBytes the key material for the secret key |
2 | 122 |
* @param keyType the key type for the secret key as defined by the |
123 |
* Kerberos protocol specification. |
|
124 |
* @param versionNum the version number of this secret key |
|
125 |
*/ |
|
126 |
public KerberosKey(KerberosPrincipal principal, |
|
127 |
byte[] keyBytes, |
|
128 |
int keyType, |
|
129 |
int versionNum) { |
|
130 |
this.principal = principal; |
|
131 |
this.versionNum = versionNum; |
|
132 |
key = new KeyImpl(keyBytes, keyType); |
|
133 |
} |
|
134 |
||
135 |
/** |
|
27771
360714d431ab
8061253: Spec cleanup for some security-related classes
weijun
parents:
25859
diff
changeset
|
136 |
* Constructs a {@code KerberosKey} from a principal's password using the |
360714d431ab
8061253: Spec cleanup for some security-related classes
weijun
parents:
25859
diff
changeset
|
137 |
* specified algorithm name. The algorithm name (case insensitive) should |
360714d431ab
8061253: Spec cleanup for some security-related classes
weijun
parents:
25859
diff
changeset
|
138 |
* be provided as the encryption type string defined on the IANA |
23732
44fe768edfd2
8035986: KerberosKey algorithm names are not specified
weijun
parents:
18830
diff
changeset
|
139 |
* <a href="https://www.iana.org/assignments/kerberos-parameters/kerberos-parameters.xhtml#kerberos-parameters-1">Kerberos Encryption Type Numbers</a> |
44fe768edfd2
8035986: KerberosKey algorithm names are not specified
weijun
parents:
18830
diff
changeset
|
140 |
* page. The version number of the key generated will be 0. |
2 | 141 |
* |
142 |
* @param principal the principal that this password belongs to |
|
143 |
* @param password the password that should be used to compute the key |
|
144 |
* @param algorithm the name for the algorithm that this key will be |
|
23732
44fe768edfd2
8035986: KerberosKey algorithm names are not specified
weijun
parents:
18830
diff
changeset
|
145 |
* used for |
2 | 146 |
* @throws IllegalArgumentException if the name of the |
147 |
* algorithm passed is unsupported. |
|
148 |
*/ |
|
149 |
public KerberosKey(KerberosPrincipal principal, |
|
150 |
char[] password, |
|
151 |
String algorithm) { |
|
152 |
||
153 |
this.principal = principal; |
|
23732
44fe768edfd2
8035986: KerberosKey algorithm names are not specified
weijun
parents:
18830
diff
changeset
|
154 |
this.versionNum = 0; |
2 | 155 |
// Pass principal in for salt |
156 |
key = new KeyImpl(principal, password, algorithm); |
|
157 |
} |
|
158 |
||
159 |
/** |
|
160 |
* Returns the principal that this key belongs to. |
|
161 |
* |
|
162 |
* @return the principal this key belongs to. |
|
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
23732
diff
changeset
|
163 |
* @throws IllegalStateException if the key is destroyed |
2 | 164 |
*/ |
165 |
public final KerberosPrincipal getPrincipal() { |
|
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
23732
diff
changeset
|
166 |
if (destroyed) { |
2 | 167 |
throw new IllegalStateException("This key is no longer valid"); |
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
23732
diff
changeset
|
168 |
} |
2 | 169 |
return principal; |
170 |
} |
|
171 |
||
172 |
/** |
|
173 |
* Returns the key version number. |
|
174 |
* |
|
175 |
* @return the key version number. |
|
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
23732
diff
changeset
|
176 |
* @throws IllegalStateException if the key is destroyed |
2 | 177 |
*/ |
178 |
public final int getVersionNumber() { |
|
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
23732
diff
changeset
|
179 |
if (destroyed) { |
2 | 180 |
throw new IllegalStateException("This key is no longer valid"); |
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
23732
diff
changeset
|
181 |
} |
2 | 182 |
return versionNum; |
183 |
} |
|
184 |
||
185 |
/** |
|
186 |
* Returns the key type for this long-term key. |
|
187 |
* |
|
188 |
* @return the key type. |
|
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
23732
diff
changeset
|
189 |
* @throws IllegalStateException if the key is destroyed |
2 | 190 |
*/ |
191 |
public final int getKeyType() { |
|
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
23732
diff
changeset
|
192 |
// KeyImpl already checked if destroyed |
2 | 193 |
return key.getKeyType(); |
194 |
} |
|
195 |
||
196 |
/* |
|
197 |
* Methods from java.security.Key |
|
198 |
*/ |
|
199 |
||
200 |
/** |
|
23732
44fe768edfd2
8035986: KerberosKey algorithm names are not specified
weijun
parents:
18830
diff
changeset
|
201 |
* Returns the standard algorithm name for this key. The algorithm names |
44fe768edfd2
8035986: KerberosKey algorithm names are not specified
weijun
parents:
18830
diff
changeset
|
202 |
* are the encryption type string defined on the IANA |
44fe768edfd2
8035986: KerberosKey algorithm names are not specified
weijun
parents:
18830
diff
changeset
|
203 |
* <a href="https://www.iana.org/assignments/kerberos-parameters/kerberos-parameters.xhtml#kerberos-parameters-1">Kerberos Encryption Type Numbers</a> |
44fe768edfd2
8035986: KerberosKey algorithm names are not specified
weijun
parents:
18830
diff
changeset
|
204 |
* page. |
44fe768edfd2
8035986: KerberosKey algorithm names are not specified
weijun
parents:
18830
diff
changeset
|
205 |
* <p> |
44fe768edfd2
8035986: KerberosKey algorithm names are not specified
weijun
parents:
18830
diff
changeset
|
206 |
* This method can return the following value not defined on the IANA page: |
44fe768edfd2
8035986: KerberosKey algorithm names are not specified
weijun
parents:
18830
diff
changeset
|
207 |
* <ol> |
44fe768edfd2
8035986: KerberosKey algorithm names are not specified
weijun
parents:
18830
diff
changeset
|
208 |
* <li>none: for etype equal to 0</li> |
44fe768edfd2
8035986: KerberosKey algorithm names are not specified
weijun
parents:
18830
diff
changeset
|
209 |
* <li>unknown: for etype greater than 0 but unsupported by |
44fe768edfd2
8035986: KerberosKey algorithm names are not specified
weijun
parents:
18830
diff
changeset
|
210 |
* the implementation</li> |
44fe768edfd2
8035986: KerberosKey algorithm names are not specified
weijun
parents:
18830
diff
changeset
|
211 |
* <li>private: for etype smaller than 0</li> |
44fe768edfd2
8035986: KerberosKey algorithm names are not specified
weijun
parents:
18830
diff
changeset
|
212 |
* </ol> |
2 | 213 |
* |
214 |
* @return the name of the algorithm associated with this key. |
|
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
23732
diff
changeset
|
215 |
* @throws IllegalStateException if the key is destroyed |
2 | 216 |
*/ |
217 |
public final String getAlgorithm() { |
|
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
23732
diff
changeset
|
218 |
// KeyImpl already checked if destroyed |
2 | 219 |
return key.getAlgorithm(); |
220 |
} |
|
221 |
||
222 |
/** |
|
223 |
* Returns the name of the encoding format for this secret key. |
|
224 |
* |
|
225 |
* @return the String "RAW" |
|
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
23732
diff
changeset
|
226 |
* @throws IllegalStateException if the key is destroyed |
2 | 227 |
*/ |
228 |
public final String getFormat() { |
|
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
23732
diff
changeset
|
229 |
// KeyImpl already checked if destroyed |
2 | 230 |
return key.getFormat(); |
231 |
} |
|
232 |
||
233 |
/** |
|
234 |
* Returns the key material of this secret key. |
|
235 |
* |
|
236 |
* @return the key material |
|
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
23732
diff
changeset
|
237 |
* @throws IllegalStateException if the key is destroyed |
2 | 238 |
*/ |
239 |
public final byte[] getEncoded() { |
|
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
23732
diff
changeset
|
240 |
// KeyImpl already checked if destroyed |
2 | 241 |
return key.getEncoded(); |
242 |
} |
|
243 |
||
244 |
/** |
|
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
23732
diff
changeset
|
245 |
* Destroys this key by clearing out the key material of this secret key. |
2 | 246 |
* |
247 |
* @throws DestroyFailedException if some error occurs while destorying |
|
248 |
* this key. |
|
249 |
*/ |
|
250 |
public void destroy() throws DestroyFailedException { |
|
251 |
if (!destroyed) { |
|
252 |
key.destroy(); |
|
253 |
principal = null; |
|
254 |
destroyed = true; |
|
255 |
} |
|
256 |
} |
|
257 |
||
258 |
||
259 |
/** Determines if this key has been destroyed.*/ |
|
260 |
public boolean isDestroyed() { |
|
261 |
return destroyed; |
|
262 |
} |
|
263 |
||
27771
360714d431ab
8061253: Spec cleanup for some security-related classes
weijun
parents:
25859
diff
changeset
|
264 |
/** |
360714d431ab
8061253: Spec cleanup for some security-related classes
weijun
parents:
25859
diff
changeset
|
265 |
* Returns an informative textual representation of this {@code KerberosKey}. |
360714d431ab
8061253: Spec cleanup for some security-related classes
weijun
parents:
25859
diff
changeset
|
266 |
* |
360714d431ab
8061253: Spec cleanup for some security-related classes
weijun
parents:
25859
diff
changeset
|
267 |
* @return an informative textual representation of this {@code KerberosKey}. |
360714d431ab
8061253: Spec cleanup for some security-related classes
weijun
parents:
25859
diff
changeset
|
268 |
*/ |
2 | 269 |
public String toString() { |
270 |
if (destroyed) { |
|
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
23732
diff
changeset
|
271 |
return "Destroyed KerberosKey"; |
2 | 272 |
} |
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
23732
diff
changeset
|
273 |
return "Kerberos Principal " + principal + |
2 | 274 |
"Key Version " + versionNum + |
275 |
"key " + key.toString(); |
|
276 |
} |
|
277 |
||
278 |
/** |
|
27771
360714d431ab
8061253: Spec cleanup for some security-related classes
weijun
parents:
25859
diff
changeset
|
279 |
* Returns a hash code for this {@code KerberosKey}. |
2 | 280 |
* |
27771
360714d431ab
8061253: Spec cleanup for some security-related classes
weijun
parents:
25859
diff
changeset
|
281 |
* @return a hash code for this {@code KerberosKey}. |
2 | 282 |
* @since 1.6 |
283 |
*/ |
|
284 |
public int hashCode() { |
|
285 |
int result = 17; |
|
286 |
if (isDestroyed()) { |
|
287 |
return result; |
|
288 |
} |
|
289 |
result = 37 * result + Arrays.hashCode(getEncoded()); |
|
290 |
result = 37 * result + getKeyType(); |
|
291 |
if (principal != null) { |
|
292 |
result = 37 * result + principal.hashCode(); |
|
293 |
} |
|
294 |
return result * 37 + versionNum; |
|
295 |
} |
|
296 |
||
297 |
/** |
|
27771
360714d431ab
8061253: Spec cleanup for some security-related classes
weijun
parents:
25859
diff
changeset
|
298 |
* Compares the specified object with this {@code KerberosKey} for |
360714d431ab
8061253: Spec cleanup for some security-related classes
weijun
parents:
25859
diff
changeset
|
299 |
* equality. Returns true if the given object is also a |
18830 | 300 |
* {@code KerberosKey} and the two |
301 |
* {@code KerberosKey} instances are equivalent. |
|
27771
360714d431ab
8061253: Spec cleanup for some security-related classes
weijun
parents:
25859
diff
changeset
|
302 |
* A destroyed {@code KerberosKey} object is only equal to itself. |
2 | 303 |
* |
27771
360714d431ab
8061253: Spec cleanup for some security-related classes
weijun
parents:
25859
diff
changeset
|
304 |
* @param other the object to compare to |
360714d431ab
8061253: Spec cleanup for some security-related classes
weijun
parents:
25859
diff
changeset
|
305 |
* @return true if the specified object is equal to this {@code KerberosKey}, |
360714d431ab
8061253: Spec cleanup for some security-related classes
weijun
parents:
25859
diff
changeset
|
306 |
* false otherwise. |
2 | 307 |
* @since 1.6 |
308 |
*/ |
|
309 |
public boolean equals(Object other) { |
|
310 |
||
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
23732
diff
changeset
|
311 |
if (other == this) { |
2 | 312 |
return true; |
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
23732
diff
changeset
|
313 |
} |
2 | 314 |
|
315 |
if (! (other instanceof KerberosKey)) { |
|
316 |
return false; |
|
317 |
} |
|
318 |
||
319 |
KerberosKey otherKey = ((KerberosKey) other); |
|
320 |
if (isDestroyed() || otherKey.isDestroyed()) { |
|
321 |
return false; |
|
322 |
} |
|
323 |
||
324 |
if (versionNum != otherKey.getVersionNumber() || |
|
325 |
getKeyType() != otherKey.getKeyType() || |
|
326 |
!Arrays.equals(getEncoded(), otherKey.getEncoded())) { |
|
327 |
return false; |
|
328 |
} |
|
329 |
||
330 |
if (principal == null) { |
|
331 |
if (otherKey.getPrincipal() != null) { |
|
332 |
return false; |
|
333 |
} |
|
334 |
} else { |
|
335 |
if (!principal.equals(otherKey.getPrincipal())) { |
|
336 |
return false; |
|
337 |
} |
|
338 |
} |
|
339 |
||
340 |
return true; |
|
341 |
} |
|
342 |
} |