jdk/test/sun/security/krb5/auto/TwoTab.java
author weijun
Thu, 02 Jul 2015 16:20:43 +0800
changeset 31474 7b79555b8073
parent 30820 0d4717a011d3
permissions -rw-r--r--
8130112: Create a common TEST.properties for @modules in test/sun/security/krb5/auto Reviewed-by: alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12199
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
     1
/*
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
     2
 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
     4
 *
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
     7
 * published by the Free Software Foundation.
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
     8
 *
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    13
 * accompanied this code).
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    14
 *
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    18
 *
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    21
 * questions.
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    22
 */
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    23
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    24
/*
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    25
 * @test
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    26
 * @bug 7152176
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    27
 * @summary More krb5 tests
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    28
 * @compile -XDignore.symbol.file TwoTab.java
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    29
 * @run main/othervm TwoTab
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    30
 */
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    31
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    32
import java.io.File;
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    33
import java.io.FileOutputStream;
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    34
import java.nio.file.Files;
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    35
import java.security.Security;
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    36
import sun.security.jgss.GSSUtil;
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    37
import sun.security.krb5.PrincipalName;
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    38
import sun.security.krb5.internal.ktab.KeyTab;
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    39
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    40
// Two services using their own keytab.
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    41
public class TwoTab {
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    42
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    43
    public static void main(String[] args) throws Exception {
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    44
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    45
        KDC k = new OneKDC(null);
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    46
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    47
        // Write JAAS conf, two service using different keytabs
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    48
        System.setProperty("java.security.auth.login.config", OneKDC.JAAS_CONF);
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    49
        File f = new File(OneKDC.JAAS_CONF);
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    50
        try (FileOutputStream fos = new FileOutputStream(f)) {
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    51
            fos.write((
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    52
                "server {\n" +
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    53
                "    com.sun.security.auth.module.Krb5LoginModule required\n" +
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    54
                "    principal=\"" + OneKDC.SERVER + "\"\n" +
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    55
                "    useKeyTab=true\n" +
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    56
                "    keyTab=server.keytab\n" +
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    57
                "    storeKey=true;\n};\n" +
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    58
                "server2 {\n" +
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    59
                "    com.sun.security.auth.module.Krb5LoginModule required\n" +
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    60
                "    principal=\"" + OneKDC.BACKEND + "\"\n" +
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    61
                "    useKeyTab=true\n" +
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    62
                "    keyTab=backend.keytab\n" +
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    63
                "    storeKey=true;\n};\n"
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    64
                ).getBytes());
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    65
        }
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    66
        f.deleteOnExit();
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    67
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    68
        k.writeKtab("server.keytab", false, "server/host.rabbit.hole@RABBIT.HOLE");
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    69
        k.writeKtab("backend.keytab", false, "backend/host.rabbit.hole@RABBIT.HOLE");
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    70
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    71
        Context c, s, s2;
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    72
        c = Context.fromUserPass(OneKDC.USER, OneKDC.PASS, false);
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    73
        s = Context.fromJAAS("server");
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    74
        s2 = Context.fromJAAS("server2");
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    75
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    76
        c.startAsClient(OneKDC.SERVER, GSSUtil.GSS_KRB5_MECH_OID);
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    77
        s.startAsServer(GSSUtil.GSS_KRB5_MECH_OID);
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    78
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    79
        Context.handshake(c, s);
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    80
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    81
        Context.transmit("i say high --", c, s);
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    82
        Context.transmit("   you say low", s, c);
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    83
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    84
        s.dispose();
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    85
        c.dispose();
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    86
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    87
        c = Context.fromUserPass(OneKDC.USER, OneKDC.PASS, false);
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    88
        c.startAsClient(OneKDC.BACKEND, GSSUtil.GSS_KRB5_MECH_OID);
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    89
        s2.startAsServer(GSSUtil.GSS_KRB5_MECH_OID);
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    90
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    91
        Context.handshake(c, s2);
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    92
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    93
        Context.transmit("i say high --", c, s2);
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    94
        Context.transmit("   you say low", s2, c);
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    95
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    96
        s2.dispose();
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    97
        c.dispose();
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    98
    }
3de38eedde69 7152176: More krb5 tests
weijun
parents:
diff changeset
    99
}