5300
|
1 |
/*
|
|
2 |
* Copyright 2007-2010 Sun Microsystems, Inc. All Rights Reserved.
|
|
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
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
21 |
* have any questions.
|
|
22 |
*/
|
|
23 |
|
|
24 |
/*
|
|
25 |
* @bug 4634392
|
|
26 |
* @summary JDK code doesn't respect contract for equals and hashCode
|
|
27 |
* @author Andrew Fan
|
|
28 |
*/
|
|
29 |
|
|
30 |
import org.ietf.jgss.*;
|
|
31 |
|
|
32 |
public class Krb5NameEquals {
|
|
33 |
|
|
34 |
private static String NAME_STR1 = "service@host";
|
|
35 |
private static String NAME_STR2 = "service@host2";
|
|
36 |
private static final Oid MECH;
|
|
37 |
|
|
38 |
static {
|
|
39 |
Oid temp = null;
|
|
40 |
try {
|
|
41 |
temp = new Oid("1.2.840.113554.1.2.2"); // KRB5
|
|
42 |
} catch (Exception e) {
|
|
43 |
// should never happen
|
|
44 |
}
|
|
45 |
MECH = temp;
|
|
46 |
}
|
|
47 |
|
|
48 |
public static void main(String[] argv) throws Exception {
|
|
49 |
GSSManager mgr = GSSManager.getInstance();
|
|
50 |
|
|
51 |
boolean result = true;
|
|
52 |
// Create GSSName and check their equals(), hashCode() impl
|
|
53 |
GSSName name1 = mgr.createName(NAME_STR1,
|
|
54 |
GSSName.NT_HOSTBASED_SERVICE, MECH);
|
|
55 |
GSSName name2 = mgr.createName(NAME_STR2,
|
|
56 |
GSSName.NT_HOSTBASED_SERVICE, MECH);
|
|
57 |
GSSName name3 = mgr.createName(NAME_STR1,
|
|
58 |
GSSName.NT_HOSTBASED_SERVICE, MECH);
|
|
59 |
|
|
60 |
if (!name1.equals(name3) || !name1.equals(name3) ||
|
|
61 |
!name1.equals((Object) name1) ||
|
|
62 |
!name1.equals((Object) name3)) {
|
|
63 |
System.out.println("Error: should be the same name");
|
|
64 |
result = false;
|
|
65 |
} else if (name1.hashCode() != name3.hashCode()) {
|
|
66 |
System.out.println("Error: should have same hash");
|
|
67 |
result = false;
|
|
68 |
}
|
|
69 |
|
|
70 |
if (name1.equals(name2) || name1.equals((Object) name2)) {
|
|
71 |
System.out.println("Error: should be different names");
|
|
72 |
result = false;
|
|
73 |
}
|
|
74 |
if (result) {
|
|
75 |
System.out.println("Done");
|
|
76 |
} else System.exit(1);
|
|
77 |
}
|
|
78 |
}
|