test/jdk/sun/security/krb5/auto/S4U2selfGSS.java
changeset 47216 71c04702a3d5
parent 31474 7b79555b8073
child 48668 2da4a52715d8
equal deleted inserted replaced
47215:4ebc2e2fb97c 47216:71c04702a3d5
       
     1 /*
       
     2  * Copyright (c) 2012, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 
       
    24 /*
       
    25  * @test
       
    26  * @bug 6355584
       
    27  * @summary Introduce constrained Kerberos delegation
       
    28  * @compile -XDignore.symbol.file S4U2selfGSS.java
       
    29  * @run main/othervm -Dsun.security.krb5.debug=false S4U2selfGSS krb5
       
    30  * @run main/othervm -Dsun.security.krb5.debug=false S4U2selfGSS spnego
       
    31  */
       
    32 
       
    33 import java.util.Arrays;
       
    34 import java.util.HashMap;
       
    35 import java.util.List;
       
    36 import java.util.Map;
       
    37 import org.ietf.jgss.Oid;
       
    38 import sun.security.jgss.GSSUtil;
       
    39 
       
    40 public class S4U2selfGSS {
       
    41 
       
    42     public static void main(String[] args) throws Exception {
       
    43         Oid mech;
       
    44         if (args[0].equals("spnego")) {
       
    45             mech = GSSUtil.GSS_SPNEGO_MECH_OID;
       
    46         } else if (args[0].contains("krb5")) {
       
    47             mech = GSSUtil.GSS_KRB5_MECH_OID;
       
    48         } else {
       
    49             throw new Exception("Unknown mech");
       
    50         }
       
    51 
       
    52         OneKDC kdc = new OneKDC(null);
       
    53         kdc.writeJAASConf();
       
    54         kdc.setOption(KDC.Option.ALLOW_S4U2SELF, Arrays.asList(
       
    55                 new String[]{OneKDC.USER + "@" + OneKDC.REALM}));
       
    56         Map<String,List<String>> map = new HashMap<>();
       
    57         map.put(OneKDC.USER + "@" + OneKDC.REALM, Arrays.asList(
       
    58                 new String[]{OneKDC.SERVER + "@" + OneKDC.REALM}));
       
    59         kdc.setOption(KDC.Option.ALLOW_S4U2PROXY, map);
       
    60 
       
    61         Context c, s;
       
    62         System.setProperty("javax.security.auth.useSubjectCredsOnly", "false");
       
    63         c = Context.fromThinAir();
       
    64         s = Context.fromThinAir();
       
    65 
       
    66         c = c.impersonate(OneKDC.USER2);
       
    67 
       
    68         c.startAsClient(OneKDC.SERVER, mech);
       
    69         s.startAsServer(mech);
       
    70 
       
    71         Context.handshake(c, s);
       
    72 
       
    73         String n1 = c.x().getSrcName().toString().split("@")[0];
       
    74         String n2 = s.x().getSrcName().toString().split("@")[0];
       
    75         if (!n1.equals(OneKDC.USER2) || !n2.equals(OneKDC.USER2)) {
       
    76             throw new Exception("Impersonate failed");
       
    77         }
       
    78 
       
    79         s.dispose();
       
    80         c.dispose();
       
    81     }
       
    82 }