test/jdk/sun/security/krb5/auto/Renew.java
author ssahoo
Thu, 25 Jan 2018 05:57:22 -0800
changeset 48668 2da4a52715d8
parent 47216 71c04702a3d5
permissions -rw-r--r--
8194486: Several krb5 tests failed in Mac. Summary: Several tests failed due to improper host service Reviewed-by: weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31643
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
     1
/*
48668
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
     2
 * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
31643
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
     4
 *
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
     7
 * published by the Free Software Foundation.
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
     8
 *
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    13
 * accompanied this code).
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    14
 *
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    18
 *
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    21
 * questions.
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    22
 */
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    23
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    24
/*
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    25
 * @test
48668
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
    26
 * @bug 8058290 8194486
31643
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    27
 * @summary JAAS Krb5LoginModule has suspect ticket-renewal logic,
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    28
 *          relies on clockskew grace
48668
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
    29
 * @library /test/lib
31643
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    30
 * @compile -XDignore.symbol.file Renew.java
48668
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
    31
 * @run main jdk.test.lib.FileInstaller TestHosts TestHosts
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
    32
 * @run main/othervm -Djdk.net.hosts.file=TestHosts Renew 1
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
    33
 * @run main/othervm -Djdk.net.hosts.file=TestHosts Renew 2
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
    34
 * @run main/othervm -Djdk.net.hosts.file=TestHosts Renew 3
31643
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    35
 */
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    36
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    37
import sun.security.krb5.Config;
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    38
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    39
import java.nio.file.Files;
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    40
import java.nio.file.Paths;
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    41
import java.util.Arrays;
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    42
import java.util.Date;
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    43
import javax.security.auth.kerberos.KerberosTicket;
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    44
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    45
public class Renew {
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    46
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    47
    public static void main(String[] args) throws Exception {
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    48
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    49
        // Three test cases:
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    50
        // 1. renewTGT=false
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    51
        // 2. renewTGT=true with a short life time, renew will happen
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    52
        // 3. renewTGT=true with a long life time, renew won't happen
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    53
        int test = Integer.parseInt(args[0]);
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    54
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    55
        OneKDC k = new OneKDC(null);
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    56
        KDC.saveConfig(OneKDC.KRB5_CONF, k,
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    57
                "renew_lifetime = 1d",
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    58
                "ticket_lifetime = " + (test == 2? "10s": "8h"));
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    59
        Config.refresh();
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    60
        k.writeJAASConf();
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    61
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    62
        // KDC would save ccache in a file
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    63
        System.setProperty("test.kdc.save.ccache", "cache.here");
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    64
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    65
        Files.write(Paths.get(OneKDC.JAAS_CONF), Arrays.asList(
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    66
                "first {",
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    67
                "   com.sun.security.auth.module.Krb5LoginModule required;",
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    68
                "};",
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    69
                "second {",
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    70
                "   com.sun.security.auth.module.Krb5LoginModule required",
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    71
                "   doNotPrompt=true",
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    72
                "   renewTGT=" + (test != 1),
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    73
                "   useTicketCache=true",
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    74
                "   ticketCache=cache.here;",
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    75
                "};"
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    76
        ));
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    77
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    78
        Context c;
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    79
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    80
        // The first login uses username and password
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    81
        c = Context.fromUserPass(OneKDC.USER, OneKDC.PASS, false);
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    82
        Date d1 = c.s().getPrivateCredentials(KerberosTicket.class).iterator().next().getAuthTime();
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    83
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    84
        // 6s is longer than half of 10s
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    85
        Thread.sleep(6000);
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    86
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    87
        // The second login uses the cache
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    88
        c = Context.fromJAAS("second");
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    89
        Date d2 = c.s().getPrivateCredentials(KerberosTicket.class).iterator().next().getAuthTime();
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    90
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    91
        if (test == 2) {
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    92
            if (d1.equals(d2)) {
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    93
                throw new Exception("Ticket not renewed");
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    94
            }
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    95
        } else {
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    96
            if (!d1.equals(d2)) {
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    97
                throw new Exception("Ticket renewed");
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    98
            }
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
    99
        }
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
   100
    }
abad00f2c027 8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
diff changeset
   101
}