test/jdk/sun/security/krb5/auto/UnboundService.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:
15649
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
     1
/*
48668
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
     2
 * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
15649
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
     4
 *
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
     7
 * published by the Free Software Foundation.
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
     8
 *
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    13
 * accompanied this code).
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    14
 *
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    18
 *
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    21
 * questions.
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    22
 */
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    23
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    24
/*
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    25
 * @test
48668
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
    26
 * @bug 8001104 8194486
15649
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    27
 * @summary Unbound SASL service: the GSSAPI/krb5 mech
48668
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
    28
 * @library /test/lib
15649
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    29
 * @compile -XDignore.symbol.file UnboundService.java
48668
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
    30
 * @run main jdk.test.lib.FileInstaller TestHosts TestHosts
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
    31
 * @run main/othervm -Djdk.net.hosts.file=TestHosts UnboundService null null
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
    32
 * @run main/othervm -Djdk.net.hosts.file=TestHosts UnboundService
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
    33
 *      server/host.rabbit.hole null
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
    34
 * @run main/othervm -Djdk.net.hosts.file=TestHosts UnboundService
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
    35
 *      server/host.rabbit.hole@RABBIT.HOLE null
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
    36
 * @run main/othervm/fail -Djdk.net.hosts.file=TestHosts UnboundService
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
    37
 *      backend/host.rabbit.hole null
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
    38
 * @run main/othervm -Djdk.net.hosts.file=TestHosts UnboundService
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
    39
 *      null server@host.rabbit.hole
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
    40
 * @run main/othervm -Djdk.net.hosts.file=TestHosts UnboundService
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
    41
 *      server/host.rabbit.hole server@host.rabbit.hole
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
    42
 * @run main/othervm -Djdk.net.hosts.file=TestHosts UnboundService
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
    43
 *      server/host.rabbit.hole@RABBIT.HOLE server@host.rabbit.hole
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
    44
 * @run main/othervm/fail -Djdk.net.hosts.file=TestHosts UnboundService
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
    45
 *      backend/host.rabbit.hole server@host.rabbit.hole
15649
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    46
 */
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    47
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    48
import java.io.File;
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    49
import java.io.FileOutputStream;
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    50
import sun.security.jgss.GSSUtil;
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    51
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    52
public class UnboundService {
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    53
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    54
    /**
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    55
     * @param args JAAS config pricipal and GSSCredential creation name
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    56
     */
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    57
    public static void main(String[] args) throws Exception {
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    58
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    59
        String principal = args[0];
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    60
        if (principal.equals("null")) principal = null;
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    61
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    62
        String server = args[1];
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    63
        if (server.equals("null")) server = null;
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    64
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    65
        new OneKDC(null).writeJAASConf();
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    66
        File f = new File(OneKDC.JAAS_CONF);
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    67
        try (FileOutputStream fos = new FileOutputStream(f)) {
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    68
            fos.write((
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    69
                "client {\n" +
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    70
                "    com.sun.security.auth.module.Krb5LoginModule required;\n};\n" +
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    71
                "unbound {\n" +
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    72
                "    com.sun.security.auth.module.Krb5LoginModule required\n" +
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    73
                "    useKeyTab=true\n" +
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    74
                "    principal=" +
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    75
                    (principal==null? "*" :("\"" + principal + "\"")) + "\n" +
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    76
                "    doNotPrompt=true\n" +
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    77
                "    isInitiator=false\n" +
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    78
                "    storeKey=true;\n};\n"
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    79
                ).getBytes());
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    80
        }
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    81
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    82
        Context c, s;
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    83
        c = Context.fromJAAS("client");
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    84
        s = Context.fromJAAS("unbound");
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    85
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    86
        c.startAsClient(OneKDC.SERVER, GSSUtil.GSS_KRB5_MECH_OID);
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    87
        s.startAsServer(server, GSSUtil.GSS_KRB5_MECH_OID);
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    88
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    89
        Context.handshake(c, s);
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    90
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    91
        s.dispose();
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    92
        c.dispose();
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    93
    }
f6bd3d34f844 8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
diff changeset
    94
}