author | weijun |
Fri, 12 Aug 2011 11:20:45 +0800 | |
changeset 10327 | 37a3f951eb3a |
parent 9499 | f3115698a012 |
child 30820 | 0d4717a011d3 |
permissions | -rw-r--r-- |
1575
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
1 |
/* |
8396
587947f96036
7018928: test failure: sun/security/krb5/auto/SSL.java
weijun
parents:
7977
diff
changeset
|
2 |
* Copyright (c) 2008, 2011, 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 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
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 |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
26 |
* @bug 6765491 |
8396
587947f96036
7018928: test failure: sun/security/krb5/auto/SSL.java
weijun
parents:
7977
diff
changeset
|
27 |
* @run main/othervm LoginModuleOptions |
1575
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
28 |
* @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
|
29 |
*/ |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
30 |
import com.sun.security.auth.module.Krb5LoginModule; |
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 |
|
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
39 |
public class LoginModuleOptions { |
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 |
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
|
42 |
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
|
43 |
|
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
44 |
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
|
45 |
OneKDC kdc = new OneKDC(null); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
46 |
kdc.addPrincipal("foo", "bar".toCharArray()); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
47 |
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
|
48 |
|
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
49 |
// 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
|
50 |
login(null, "useKeyTab", "true", "principal", "dummy"); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
51 |
login(null, "tryFirstPass", "true", NAME, OneKDC.USER, |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
52 |
PWD, OneKDC.PASS); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
53 |
System.setProperty("test.kdc.save.ccache", "krbcc"); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
54 |
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
|
55 |
System.clearProperty("test.kdc.save.ccache"); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
56 |
login(null, "useTicketCache", "true", "ticketCache", "krbcc"); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
57 |
|
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
58 |
// Fallbacks |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
59 |
// 1. ccache -> keytab |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
60 |
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
|
61 |
"useKeyTab", "true", "principal", "dummy"); |
9499 | 62 |
|
1575
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); |
9499 | 67 |
|
1575
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
68 |
// 3. shared -> callback |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
69 |
// 3.1. useFirstPass, no callback |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
70 |
boolean failed = false; |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
71 |
try { |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
72 |
login(new MyCallback(OneKDC.USER, OneKDC.PASS), |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
73 |
"useFirstPass", "true", |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
74 |
NAME, OneKDC.USER, PWD, "haha".toCharArray()); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
75 |
} catch (Exception e) { |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
76 |
failed = true; |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
77 |
} |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
78 |
if (!failed) { |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
79 |
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
|
80 |
} |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
81 |
// 3.2. tryFirstPass, has callback |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
82 |
login(new MyCallback(OneKDC.USER, OneKDC.PASS), |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
83 |
"tryFirstPass", "true", |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
84 |
NAME, OneKDC.USER, PWD, "haha".toCharArray()); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
85 |
|
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
86 |
// Preferences of type |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
87 |
// 1. ccache preferred to keytab |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
88 |
login(new MyCallback("foo", null), |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
89 |
"useTicketCache", "true", "ticketCache", "krbcc", |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
90 |
"useKeyTab", "true"); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
91 |
// 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
|
92 |
// 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
|
93 |
// 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
|
94 |
// (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
|
95 |
// 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
|
96 |
login(null, "useKeyTab", "true", "principal", "dummy", |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
97 |
"tryFirstPass", "true", NAME, "foo", PWD, "bar".toCharArray()); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
98 |
// 3. shared preferred to callback |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
99 |
login(new MyCallback("foo", "bar".toCharArray()), |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
100 |
"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
|
101 |
|
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
102 |
// Preferences of username |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
103 |
// 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
|
104 |
login(null, "principal", OneKDC.USER, |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
105 |
"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
|
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", PWD, OneKDC.PASS); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
108 |
// 2. NAME preferred to callback |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
109 |
login(new MyCallback("someone_else", OneKDC.PASS), |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
110 |
"principal", OneKDC.USER); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
111 |
// 3. With tryFirstPass, NAME preferred to callback |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
112 |
login(new MyCallback("someone_else", null), |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
113 |
"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
|
114 |
// 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
|
115 |
failed = false; |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
116 |
try { |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
117 |
login(new MyCallback(OneKDC.USER, null), |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
118 |
"tryFirstPass", "true", PWD, OneKDC.PASS); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
119 |
} catch (Exception e) { |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
120 |
failed = true; |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
121 |
} |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
122 |
if (!failed) { |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
123 |
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
|
124 |
} |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
125 |
// 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
|
126 |
// I don't think this is designed. |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
127 |
login(new MyCallback(OneKDC.USER, null), |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
128 |
"tryFirstPass", "true", NAME, "", PWD, OneKDC.PASS); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
129 |
|
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
130 |
// 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
|
131 |
login(null, "doNotPrompt", "true", "storeKey", "true", |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
132 |
"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
|
133 |
} |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
134 |
|
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
135 |
static void login(CallbackHandler callback, Object... options) |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
136 |
throws Exception { |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
137 |
Krb5LoginModule krb5 = new Krb5LoginModule(); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
138 |
Subject subject = new Subject(); |
7977
f47f211cd627
7008713: diamond conversion of kerberos5 and security tools
smarks
parents:
5506
diff
changeset
|
139 |
Map<String, String> map = new HashMap<>(); |
f47f211cd627
7008713: diamond conversion of kerberos5 and security tools
smarks
parents:
5506
diff
changeset
|
140 |
Map<String, Object> shared = new HashMap<>(); |
1575
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
141 |
|
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
142 |
int count = options.length / 2; |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
143 |
for (int i = 0; i < count; i++) { |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
144 |
String key = (String) options[2 * i]; |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
145 |
Object value = options[2 * i + 1]; |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
146 |
if (key.startsWith("javax")) { |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
147 |
shared.put(key, value); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
148 |
} else { |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
149 |
map.put(key, (String) value); |
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 |
} |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
152 |
krb5.initialize(subject, callback, shared, map); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
153 |
krb5.login(); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
154 |
krb5.commit(); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
155 |
if (!subject.getPrincipals().iterator().next() |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
156 |
.getName().startsWith(OneKDC.USER)) { |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
157 |
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
|
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 |
|
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
161 |
static class MyCallback implements CallbackHandler { |
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 |
private String name; |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
164 |
private char[] password; |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
165 |
|
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
166 |
public MyCallback(String name, char[] password) { |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
167 |
this.name = name; |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
168 |
this.password = password; |
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 |
|
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
171 |
public void handle(Callback[] callbacks) { |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
172 |
for (Callback callback : callbacks) { |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
173 |
System.err.println(callback); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
174 |
if (callback instanceof NameCallback) { |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
175 |
System.err.println("name is " + name); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
176 |
((NameCallback) callback).setName(name); |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
177 |
} |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
178 |
if (callback instanceof PasswordCallback) { |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
179 |
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
|
180 |
((PasswordCallback) callback).setPassword(password); |
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 |
} |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
diff
changeset
|
185 |
} |