test/jdk/sun/security/krb5/auto/LoginModuleOptions.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:
1575
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
     1
/*
48668
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
     2
 * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
1575
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
     4
 *
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
     7
 * published by the Free Software Foundation.
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
     8
 *
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    13
 * accompanied this code).
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    14
 *
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1575
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1575
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1575
diff changeset
    21
 * questions.
1575
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    22
 */
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    23
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    24
/*
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    25
 * @test
48668
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
    26
 * @bug 6765491 8194486
1575
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    27
 * @summary Krb5LoginModule a little too restrictive, and the doc is not clear.
48668
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
    28
 * @library /test/lib
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
    29
 * @run main jdk.test.lib.FileInstaller TestHosts TestHosts
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
    30
 * @run main/othervm -Djdk.net.hosts.file=TestHosts LoginModuleOptions
1575
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    31
 */
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    32
import com.sun.security.auth.module.Krb5LoginModule;
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    33
import java.util.HashMap;
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    34
import java.util.Map;
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    35
import javax.security.auth.Subject;
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    36
import javax.security.auth.callback.Callback;
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    37
import javax.security.auth.callback.CallbackHandler;
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    38
import javax.security.auth.callback.NameCallback;
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    39
import javax.security.auth.callback.PasswordCallback;
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    40
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    41
public class LoginModuleOptions {
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    42
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    43
    private static final String NAME = "javax.security.auth.login.name";
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    44
    private static final String PWD = "javax.security.auth.login.password";
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    45
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    46
    public static void main(String[] args) throws Exception {
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    47
        OneKDC kdc = new OneKDC(null);
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    48
        kdc.addPrincipal("foo", "bar".toCharArray());
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    49
        kdc.writeKtab(OneKDC.KTAB); // rewrite to add foo
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    50
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    51
        // All 4 works: keytab, shared state, callback, cache
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    52
        login(null, "useKeyTab", "true", "principal", "dummy");
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    53
        login(null, "tryFirstPass", "true", NAME, OneKDC.USER,
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    54
                PWD, OneKDC.PASS);
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    55
        System.setProperty("test.kdc.save.ccache", "krbcc");
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    56
        login(new MyCallback(OneKDC.USER, OneKDC.PASS));    // save the cache
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    57
        System.clearProperty("test.kdc.save.ccache");
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    58
        login(null, "useTicketCache", "true", "ticketCache", "krbcc");
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    59
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    60
        // Fallbacks
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    61
        // 1. ccache -> keytab
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    62
        login(null, "useTicketCache", "true", "ticketCache", "krbcc_non_exists",
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    63
                "useKeyTab", "true", "principal", "dummy");
9499
f3115698a012 6894072: always refresh keytab
weijun
parents: 8396
diff changeset
    64
1575
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    65
        // 2. keytab -> shared
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    66
        login(null, "useKeyTab", "true", "principal", "dummy",
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    67
                "keyTab", "ktab_non_exist",
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    68
                "tryFirstPass", "true", NAME, OneKDC.USER, PWD, OneKDC.PASS);
9499
f3115698a012 6894072: always refresh keytab
weijun
parents: 8396
diff changeset
    69
1575
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    70
        // 3. shared -> callback
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    71
        // 3.1. useFirstPass, no callback
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    72
        boolean failed = false;
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    73
        try {
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    74
            login(new MyCallback(OneKDC.USER, OneKDC.PASS),
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    75
                    "useFirstPass", "true",
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    76
                    NAME, OneKDC.USER, PWD, "haha".toCharArray());
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    77
        } catch (Exception e) {
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    78
            failed = true;
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    79
        }
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    80
        if (!failed) {
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    81
            throw new Exception("useFirstPass should not fallback to callback");
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    82
        }
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    83
        // 3.2. tryFirstPass, has callback
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    84
        login(new MyCallback(OneKDC.USER, OneKDC.PASS),
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    85
                "tryFirstPass", "true",
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    86
                NAME, OneKDC.USER, PWD, "haha".toCharArray());
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    87
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    88
        // Preferences of type
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    89
        // 1. ccache preferred to keytab
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    90
        login(new MyCallback("foo", null),
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    91
                "useTicketCache", "true", "ticketCache", "krbcc",
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    92
                "useKeyTab", "true");
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    93
        // 2. keytab preferred to shared. This test case is not exactly correct,
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    94
        // because principal=dummy would shadow the PWD setting in the shared
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    95
        // state. So by only looking at the final authentication user name
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    96
        // (which is how this program does), there's no way to tell if keyTab
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    97
        // is picked first, or shared is tried first but fallback to keytab.
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    98
        login(null, "useKeyTab", "true", "principal", "dummy",
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
    99
                "tryFirstPass", "true", NAME, "foo", PWD, "bar".toCharArray());
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   100
        // 3. shared preferred to callback
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   101
        login(new MyCallback("foo", "bar".toCharArray()),
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   102
                "tryFirstPass", "true", NAME, OneKDC.USER, PWD, OneKDC.PASS);
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   103
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   104
        // Preferences of username
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   105
        // 1. principal preferred to NAME (NAME can be wrong or missing)
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   106
        login(null, "principal", OneKDC.USER,
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   107
                "tryFirstPass", "true", NAME, "someone_else", PWD, OneKDC.PASS);
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   108
        login(null, "principal", OneKDC.USER,
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   109
                "tryFirstPass", "true", PWD, OneKDC.PASS);
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   110
        // 2. NAME preferred to callback
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   111
        login(new MyCallback("someone_else", OneKDC.PASS),
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   112
                "principal", OneKDC.USER);
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   113
        // 3. With tryFirstPass, NAME preferred to callback
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   114
        login(new MyCallback("someone_else", null),
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   115
                "tryFirstPass", "true", NAME, OneKDC.USER, PWD, OneKDC.PASS);
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   116
        // 3.1. you must provide a NAME (when there's no principal)
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   117
        failed = false;
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   118
        try {
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   119
            login(new MyCallback(OneKDC.USER, null),
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   120
                    "tryFirstPass", "true", PWD, OneKDC.PASS);
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   121
        } catch (Exception e) {
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   122
            failed = true;
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   123
        }
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   124
        if (!failed) {
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   125
            throw new Exception("useFirstPass must provide a NAME");
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   126
        }
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   127
        // 3.2 Hybrid, you can use NAME as "", and provide it using callback.
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   128
        // I don't think this is designed.
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   129
        login(new MyCallback(OneKDC.USER, null),
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   130
                "tryFirstPass", "true", NAME, "", PWD, OneKDC.PASS);
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   131
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   132
        // Test for the bug fix: doNotPrompt can be true if tryFirstPass=true
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   133
        login(null, "doNotPrompt", "true", "storeKey", "true",
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   134
                "tryFirstPass", "true", NAME, OneKDC.USER, PWD, OneKDC.PASS);
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   135
    }
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   136
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   137
    static void login(CallbackHandler callback, Object... options)
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   138
            throws Exception {
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   139
        Krb5LoginModule krb5 = new Krb5LoginModule();
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   140
        Subject subject = new Subject();
7977
f47f211cd627 7008713: diamond conversion of kerberos5 and security tools
smarks
parents: 5506
diff changeset
   141
        Map<String, String> map = new HashMap<>();
f47f211cd627 7008713: diamond conversion of kerberos5 and security tools
smarks
parents: 5506
diff changeset
   142
        Map<String, Object> shared = new HashMap<>();
1575
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   143
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   144
        int count = options.length / 2;
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   145
        for (int i = 0; i < count; i++) {
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   146
            String key = (String) options[2 * i];
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   147
            Object value = options[2 * i + 1];
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   148
            if (key.startsWith("javax")) {
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   149
                shared.put(key, value);
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   150
            } else {
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   151
                map.put(key, (String) value);
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   152
            }
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   153
        }
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   154
        krb5.initialize(subject, callback, shared, map);
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   155
        krb5.login();
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   156
        krb5.commit();
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   157
        if (!subject.getPrincipals().iterator().next()
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   158
                .getName().startsWith(OneKDC.USER)) {
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   159
            throw new Exception("The authenticated is not " + OneKDC.USER);
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   160
        }
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   161
    }
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   162
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   163
    static class MyCallback implements CallbackHandler {
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   164
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   165
        private String name;
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   166
        private char[] password;
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   167
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   168
        public MyCallback(String name, char[] password) {
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   169
            this.name = name;
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   170
            this.password = password;
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   171
        }
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   172
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   173
        public void handle(Callback[] callbacks) {
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   174
            for (Callback callback : callbacks) {
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   175
                System.err.println(callback);
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   176
                if (callback instanceof NameCallback) {
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   177
                    System.err.println("name is " + name);
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   178
                    ((NameCallback) callback).setName(name);
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   179
                }
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   180
                if (callback instanceof PasswordCallback) {
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   181
                    System.err.println("pass is " + new String(password));
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   182
                    ((PasswordCallback) callback).setPassword(password);
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   183
                }
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   184
            }
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   185
        }
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   186
    }
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff changeset
   187
}