jdk/test/sun/security/krb5/auto/UdpTcp.java
changeset 44203 d2d435372329
parent 44080 56713dcfe871
parent 43915 4a79ad46e578
child 44205 0c46195767fb
child 46327 91576389a517
equal deleted inserted replaced
44080:56713dcfe871 44203:d2d435372329
     1 /*
       
     2  * Copyright (c) 2014, 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 4966382 8039132
       
    27  * @run main/othervm UdpTcp UDP
       
    28  * @run main/othervm UdpTcp TCP
       
    29  * @summary udp or tcp
       
    30  */
       
    31 
       
    32 import java.io.ByteArrayOutputStream;
       
    33 import java.io.PrintStream;
       
    34 import sun.security.krb5.Config;
       
    35 
       
    36 public class UdpTcp {
       
    37 
       
    38     public static void main(String[] args)
       
    39             throws Exception {
       
    40 
       
    41         System.setProperty("sun.security.krb5.debug", "true");
       
    42 
       
    43         OneKDC kdc = new OneKDC(null);
       
    44         kdc.writeJAASConf();
       
    45 
       
    46         // Two styles of kdc_timeout setting. One global, one realm-specific.
       
    47         if (args[0].equals("UDP")) {
       
    48             KDC.saveConfig(OneKDC.KRB5_CONF, kdc,
       
    49                     "kdc_timeout = 10s");
       
    50         } else {
       
    51             kdc.addConf("kdc_timeout = 10s");
       
    52             KDC.saveConfig(OneKDC.KRB5_CONF, kdc,
       
    53                     "udp_preference_limit = 1");
       
    54         }
       
    55         Config.refresh();
       
    56 
       
    57         ByteArrayOutputStream bo = new ByteArrayOutputStream();
       
    58         PrintStream oldout = System.out;
       
    59         System.setOut(new PrintStream(bo));
       
    60         Context.fromUserPass(OneKDC.USER, OneKDC.PASS, false);
       
    61         System.setOut(oldout);
       
    62 
       
    63         for (String line: new String(bo.toByteArray()).split("\n")) {
       
    64             if (line.contains(">>> KDCCommunication")) {
       
    65                 if (!line.contains(args[0]) || !line.contains("timeout=10000")) {
       
    66                     throw new Exception("No " + args[0] + " in: " + line);
       
    67                 }
       
    68             }
       
    69         }
       
    70     }
       
    71 }