jdk/test/sun/security/krb5/auto/BasicKrb5Test.java
changeset 1454 d9b6f1de641f
child 1456 1d3c6724de2f
equal deleted inserted replaced
1453:d7e8bf374129 1454:d9b6f1de641f
       
     1 /*
       
     2  * Copyright 2008 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  * @test
       
    26  * @bug 6706974
       
    27  * @summary Add krb5 test infrastructure
       
    28  */
       
    29 
       
    30 import org.ietf.jgss.GSSName;
       
    31 import sun.security.jgss.GSSUtil;
       
    32 import sun.security.krb5.Config;
       
    33 import sun.security.krb5.internal.crypto.EType;
       
    34 
       
    35 /**
       
    36  * Basic JGSS/krb5 test with 3 parties: client, server, backend server. Each
       
    37  * party uses JAAS login to get subjects and executes JGSS calls using
       
    38  * Subject.doAs.
       
    39  */
       
    40 public class BasicKrb5Test {
       
    41 
       
    42     /**
       
    43      * @param args empty or etype
       
    44      */
       
    45     public static void main(String[] args)
       
    46             throws Exception {
       
    47 
       
    48         String etype = null;
       
    49         if (args.length > 0) {
       
    50             etype = args[0];
       
    51         }
       
    52         System.out.println("Testing etype " + etype);
       
    53         if (etype != null && !EType.isSupported(Config.getInstance().getType(etype))) {
       
    54             System.out.println("Not supported.");
       
    55             System.exit(0);
       
    56         }
       
    57 
       
    58         // Creates and starts the KDC
       
    59         new OneKDC(etype).writeJAASConf();
       
    60         new BasicKrb5Test().go(OneKDC.SERVER, OneKDC.BACKEND);
       
    61     }
       
    62 
       
    63     void go(final String server, final String backend) throws Exception {
       
    64         Context c, s, s2, b;
       
    65         c = Context.fromJAAS("client");
       
    66         s = Context.fromJAAS("server");
       
    67         b = Context.fromJAAS("backend");
       
    68 
       
    69         c.startAsClient(server, GSSUtil.GSS_KRB5_MECH_OID);
       
    70         c.x().requestCredDeleg(true);
       
    71         s.startAsServer(GSSUtil.GSS_KRB5_MECH_OID);
       
    72 
       
    73         c.status();
       
    74         s.status();
       
    75 
       
    76         Context.handshake(c, s);
       
    77         GSSName client = c.x().getSrcName();
       
    78 
       
    79         c.status();
       
    80         s.status();
       
    81 
       
    82         Context.transmit("i say high --", c, s);
       
    83         Context.transmit("   you say low", s, c);
       
    84 
       
    85         s2 = s.delegated();
       
    86         s.dispose();
       
    87         s = null;
       
    88 
       
    89         s2.startAsClient(backend, GSSUtil.GSS_KRB5_MECH_OID);
       
    90         b.startAsServer(GSSUtil.GSS_KRB5_MECH_OID);
       
    91 
       
    92         s2.status();
       
    93         b.status();
       
    94 
       
    95         Context.handshake(s2, b);
       
    96         GSSName client2 = b.x().getSrcName();
       
    97 
       
    98         if (!client.equals(client2)) {
       
    99             throw new Exception("Delegation failed");
       
   100         }
       
   101 
       
   102         s2.status();
       
   103         b.status();
       
   104 
       
   105         Context.transmit("you say hello --", s2, b);
       
   106         Context.transmit("   i say goodbye", b, s2);
       
   107 
       
   108         s2.dispose();
       
   109         b.dispose();
       
   110     }
       
   111 }