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