author | weijun |
Thu, 18 Mar 2010 18:26:37 +0800 | |
changeset 5154 | 07af3c279166 |
parent 1575 | e0f1979051b5 |
child 5506 | 202f599c92aa |
permissions | -rw-r--r-- |
1575
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
1 |
/* |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
2 |
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. |
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 |
* |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
19 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
21 |
* have any questions. |
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 |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
26 |
* @bug 6765491 |
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. |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
28 |
*/ |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
29 |
import com.sun.security.auth.module.Krb5LoginModule; |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
30 |
import java.io.IOException; |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
31 |
import java.util.HashMap; |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
32 |
import java.util.Map; |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
33 |
import javax.security.auth.Subject; |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
34 |
import javax.security.auth.callback.Callback; |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
35 |
import javax.security.auth.callback.CallbackHandler; |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
36 |
import javax.security.auth.callback.NameCallback; |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
37 |
import javax.security.auth.callback.PasswordCallback; |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
38 |
import javax.security.auth.callback.UnsupportedCallbackException; |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
39 |
|
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
40 |
public class LoginModuleOptions { |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
41 |
|
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
42 |
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
|
43 |
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
|
44 |
|
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
45 |
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
|
46 |
OneKDC kdc = new OneKDC(null); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
47 |
kdc.addPrincipal("foo", "bar".toCharArray()); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
48 |
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
|
49 |
|
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
50 |
// 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
|
51 |
login(null, "useKeyTab", "true", "principal", "dummy"); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
52 |
login(null, "tryFirstPass", "true", NAME, OneKDC.USER, |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
53 |
PWD, OneKDC.PASS); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
54 |
System.setProperty("test.kdc.save.ccache", "krbcc"); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
55 |
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
|
56 |
System.clearProperty("test.kdc.save.ccache"); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
57 |
login(null, "useTicketCache", "true", "ticketCache", "krbcc"); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
58 |
|
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
59 |
// Fallbacks |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
60 |
// 1. ccache -> keytab |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
61 |
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
|
62 |
"useKeyTab", "true", "principal", "dummy"); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
63 |
// 2. keytab -> shared |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
64 |
login(null, "useKeyTab", "true", "principal", "dummy", |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
65 |
"keyTab", "ktab_non_exist", |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
66 |
"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
|
67 |
// 3. shared -> callback |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
68 |
// 3.1. useFirstPass, no callback |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
69 |
boolean failed = false; |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
70 |
try { |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
71 |
login(new MyCallback(OneKDC.USER, OneKDC.PASS), |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
72 |
"useFirstPass", "true", |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
73 |
NAME, OneKDC.USER, PWD, "haha".toCharArray()); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
74 |
} catch (Exception e) { |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
75 |
failed = true; |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
76 |
} |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
77 |
if (!failed) { |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
78 |
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
|
79 |
} |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
80 |
// 3.2. tryFirstPass, has callback |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
81 |
login(new MyCallback(OneKDC.USER, OneKDC.PASS), |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
82 |
"tryFirstPass", "true", |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
83 |
NAME, OneKDC.USER, PWD, "haha".toCharArray()); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
84 |
|
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
85 |
// Preferences of type |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
86 |
// 1. ccache preferred to keytab |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
87 |
login(new MyCallback("foo", null), |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
88 |
"useTicketCache", "true", "ticketCache", "krbcc", |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
89 |
"useKeyTab", "true"); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
90 |
// 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
|
91 |
// 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
|
92 |
// 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
|
93 |
// (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
|
94 |
// 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
|
95 |
login(null, "useKeyTab", "true", "principal", "dummy", |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
96 |
"tryFirstPass", "true", NAME, "foo", PWD, "bar".toCharArray()); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
97 |
// 3. shared preferred to callback |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
98 |
login(new MyCallback("foo", "bar".toCharArray()), |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
99 |
"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
|
100 |
|
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
101 |
// Preferences of username |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
102 |
// 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
|
103 |
login(null, "principal", OneKDC.USER, |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
104 |
"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
|
105 |
login(null, "principal", OneKDC.USER, |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
106 |
"tryFirstPass", "true", PWD, OneKDC.PASS); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
107 |
// 2. NAME preferred to callback |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
108 |
login(new MyCallback("someone_else", OneKDC.PASS), |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
109 |
"principal", OneKDC.USER); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
110 |
// 3. With tryFirstPass, 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", null), |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
112 |
"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
|
113 |
// 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
|
114 |
failed = false; |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
115 |
try { |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
116 |
login(new MyCallback(OneKDC.USER, null), |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
117 |
"tryFirstPass", "true", PWD, OneKDC.PASS); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
118 |
} catch (Exception e) { |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
119 |
failed = true; |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
120 |
} |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
121 |
if (!failed) { |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
122 |
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
|
123 |
} |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
124 |
// 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
|
125 |
// I don't think this is designed. |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
126 |
login(new MyCallback(OneKDC.USER, null), |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
127 |
"tryFirstPass", "true", NAME, "", PWD, OneKDC.PASS); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
128 |
|
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
129 |
// 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
|
130 |
login(null, "doNotPrompt", "true", "storeKey", "true", |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
131 |
"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
|
132 |
} |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
133 |
|
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
134 |
static void login(CallbackHandler callback, Object... options) |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
135 |
throws Exception { |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
136 |
Krb5LoginModule krb5 = new Krb5LoginModule(); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
137 |
Subject subject = new Subject(); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
138 |
Map<String, String> map = new HashMap<String, String>(); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
139 |
Map<String, Object> shared = new HashMap<String, Object>(); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
140 |
|
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
141 |
int count = options.length / 2; |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
142 |
for (int i = 0; i < count; i++) { |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
143 |
String key = (String) options[2 * i]; |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
144 |
Object value = options[2 * i + 1]; |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
145 |
if (key.startsWith("javax")) { |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
146 |
shared.put(key, value); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
147 |
} else { |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
148 |
map.put(key, (String) value); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
149 |
} |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
150 |
} |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
151 |
krb5.initialize(subject, callback, shared, map); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
152 |
krb5.login(); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
153 |
krb5.commit(); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
154 |
if (!subject.getPrincipals().iterator().next() |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
155 |
.getName().startsWith(OneKDC.USER)) { |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
156 |
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
|
157 |
} |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
158 |
} |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
159 |
|
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
160 |
static class MyCallback implements CallbackHandler { |
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 |
private String name; |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
163 |
private char[] password; |
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 |
public MyCallback(String name, char[] password) { |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
166 |
this.name = name; |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
167 |
this.password = password; |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
168 |
} |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
169 |
|
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
170 |
public void handle(Callback[] callbacks) { |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
171 |
for (Callback callback : callbacks) { |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
172 |
System.err.println(callback); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
173 |
if (callback instanceof NameCallback) { |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
174 |
System.err.println("name is " + name); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
175 |
((NameCallback) callback).setName(name); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
176 |
} |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
177 |
if (callback instanceof PasswordCallback) { |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
178 |
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
|
179 |
((PasswordCallback) callback).setPassword(password); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
180 |
} |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
181 |
} |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
182 |
} |
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 |
} |