jdk/test/sun/security/krb5/Krb5NameEquals.java
author stefank
Mon, 04 Apr 2016 09:15:01 +0200
changeset 37241 b9961c99c356
parent 14342 8435a30053c1
permissions -rw-r--r--
8152538: UL doesn't inline the LogTagSet::is_level check Reviewed-by: mlarsson, brutisso
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5300
a291a0bff79f 6944847: native gss lib names on linux
weijun
parents:
diff changeset
     1
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 10327
diff changeset
     2
 * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
5300
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5300
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5300
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5300
diff changeset
    21
 * questions.
5300
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
10327
37a3f951eb3a 7076415: sun/security/krb5/runNameEquals.sh failed on sles 10
weijun
parents: 5506
diff changeset
    34
    private static String NAME_STR1 = "service@localhost";
37a3f951eb3a 7076415: sun/security/krb5/runNameEquals.sh failed on sles 10
weijun
parents: 5506
diff changeset
    35
    private static String NAME_STR2 = "service2@localhost";
5300
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
10327
37a3f951eb3a 7076415: sun/security/krb5/runNameEquals.sh failed on sles 10
weijun
parents: 5506
diff changeset
    60
        if (!name1.equals(name1) || !name1.equals(name3) ||
5300
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
}