test/jdk/sun/security/krb5/auto/S4U2selfGSS.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 31474 jdk/test/sun/security/krb5/auto/S4U2selfGSS.java@7b79555b8073
child 48668 2da4a52715d8
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14413
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
     1
/*
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
     2
 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
     4
 *
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
     7
 * published by the Free Software Foundation.
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
     8
 *
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    13
 * accompanied this code).
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    14
 *
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    18
 *
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    21
 * questions.
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    22
 */
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    23
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    24
/*
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    25
 * @test
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    26
 * @bug 6355584
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    27
 * @summary Introduce constrained Kerberos delegation
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    28
 * @compile -XDignore.symbol.file S4U2selfGSS.java
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    29
 * @run main/othervm -Dsun.security.krb5.debug=false S4U2selfGSS krb5
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    30
 * @run main/othervm -Dsun.security.krb5.debug=false S4U2selfGSS spnego
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    31
 */
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    32
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    33
import java.util.Arrays;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    34
import java.util.HashMap;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    35
import java.util.List;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    36
import java.util.Map;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    37
import org.ietf.jgss.Oid;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    38
import sun.security.jgss.GSSUtil;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    39
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    40
public class S4U2selfGSS {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    41
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    42
    public static void main(String[] args) throws Exception {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    43
        Oid mech;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    44
        if (args[0].equals("spnego")) {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    45
            mech = GSSUtil.GSS_SPNEGO_MECH_OID;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    46
        } else if (args[0].contains("krb5")) {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    47
            mech = GSSUtil.GSS_KRB5_MECH_OID;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    48
        } else {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    49
            throw new Exception("Unknown mech");
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    50
        }
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    51
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    52
        OneKDC kdc = new OneKDC(null);
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    53
        kdc.writeJAASConf();
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    54
        kdc.setOption(KDC.Option.ALLOW_S4U2SELF, Arrays.asList(
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    55
                new String[]{OneKDC.USER + "@" + OneKDC.REALM}));
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    56
        Map<String,List<String>> map = new HashMap<>();
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    57
        map.put(OneKDC.USER + "@" + OneKDC.REALM, Arrays.asList(
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    58
                new String[]{OneKDC.SERVER + "@" + OneKDC.REALM}));
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    59
        kdc.setOption(KDC.Option.ALLOW_S4U2PROXY, map);
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    60
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    61
        Context c, s;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    62
        System.setProperty("javax.security.auth.useSubjectCredsOnly", "false");
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    63
        c = Context.fromThinAir();
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    64
        s = Context.fromThinAir();
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    65
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    66
        c = c.impersonate(OneKDC.USER2);
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    67
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    68
        c.startAsClient(OneKDC.SERVER, mech);
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    69
        s.startAsServer(mech);
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    70
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    71
        Context.handshake(c, s);
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    72
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    73
        String n1 = c.x().getSrcName().toString().split("@")[0];
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    74
        String n2 = s.x().getSrcName().toString().split("@")[0];
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    75
        if (!n1.equals(OneKDC.USER2) || !n2.equals(OneKDC.USER2)) {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    76
            throw new Exception("Impersonate failed");
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    77
        }
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    78
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    79
        s.dispose();
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    80
        c.dispose();
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    81
    }
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    82
}