Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/krb5/auto/OkAsDelegateXRealm.java
38854 views
1
/*
2
* Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
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.
22
*/
23
24
/*
25
* @test
26
* @bug 6853328 7172701
27
* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock OkAsDelegateXRealm false
28
* KDC no OK-AS-DELEGATE, fail
29
* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock -Dtest.kdc.policy.ok-as-delegate OkAsDelegateXRealm true
30
* KDC set OK-AS-DELEGATE for all, succeed
31
* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock -Dtest.kdc.policy.ok-as-delegate=host/host.r3.local OkAsDelegateXRealm false
32
* KDC set OK-AS-DELEGATE for host/host.r3.local only, fail
33
* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock -Dtest.kdc.policy.ok-as-delegate=host/host.r3.local,krbtgt/R2,krbtgt/R3 OkAsDelegateXRealm true
34
* KDC set OK-AS-DELEGATE for all three, succeed
35
* @summary Support OK-AS-DELEGATE flag
36
*/
37
import java.io.FileOutputStream;
38
import java.io.IOException;
39
import java.security.Security;
40
import javax.security.auth.callback.Callback;
41
import javax.security.auth.callback.CallbackHandler;
42
import javax.security.auth.callback.NameCallback;
43
import javax.security.auth.callback.PasswordCallback;
44
import javax.security.auth.callback.UnsupportedCallbackException;
45
import org.ietf.jgss.GSSException;
46
import sun.security.jgss.GSSUtil;
47
import sun.security.krb5.Config;
48
49
public class OkAsDelegateXRealm implements CallbackHandler {
50
51
/**
52
* @param args boolean if the program should succeed
53
*/
54
public static void main(String[] args)
55
throws Exception {
56
57
// Create and start the KDCs. Here we have 3 realms: R1, R2 and R3.
58
// R1 is trusted by R2, and R2 trusted by R3.
59
KDC kdc1 = KDC.create("R1");
60
kdc1.setOption(KDC.Option.OK_AS_DELEGATE,
61
System.getProperty("test.kdc.policy.ok-as-delegate"));
62
kdc1.addPrincipal("dummy", "bogus".toCharArray());
63
kdc1.addPrincipalRandKey("krbtgt/R1");
64
kdc1.addPrincipal("krbtgt/R2@R1", "r1->r2".toCharArray());
65
66
KDC kdc2 = KDC.create("R2");
67
kdc2.setOption(KDC.Option.OK_AS_DELEGATE,
68
System.getProperty("test.kdc.policy.ok-as-delegate"));
69
kdc2.addPrincipalRandKey("krbtgt/R2");
70
kdc2.addPrincipal("krbtgt/R2@R1", "r1->r2".toCharArray());
71
kdc2.addPrincipal("krbtgt/R3@R2", "r2->r3".toCharArray());
72
73
KDC kdc3 = KDC.create("R3");
74
kdc3.setOption(KDC.Option.OK_AS_DELEGATE,
75
System.getProperty("test.kdc.policy.ok-as-delegate"));
76
kdc3.addPrincipalRandKey("krbtgt/R3");
77
kdc3.addPrincipal("krbtgt/R3@R2", "r2->r3".toCharArray());
78
kdc3.addPrincipalRandKey("host/host.r3.local");
79
80
KDC.saveConfig("krb5-localkdc.conf", kdc1, kdc2, kdc3,
81
"forwardable=true",
82
"[capaths]",
83
"R1 = {",
84
" R2 = .",
85
" R3 = R2",
86
"}",
87
"[domain_realm]",
88
".r3.local=R3"
89
);
90
91
System.setProperty("java.security.krb5.conf", "krb5-localkdc.conf");
92
kdc3.writeKtab("localkdc.ktab");
93
94
FileOutputStream fos = new FileOutputStream("jaas-localkdc.conf");
95
96
// Defines the client and server on R1 and R3 respectively.
97
fos.write(("com.sun.security.jgss.krb5.initiate {\n" +
98
" com.sun.security.auth.module.Krb5LoginModule\n" +
99
" required\n" +
100
" principal=dummy\n" +
101
" doNotPrompt=false\n" +
102
" useTicketCache=false\n" +
103
" ;\n};\n" +
104
"com.sun.security.jgss.krb5.accept {\n" +
105
" com.sun.security.auth.module.Krb5LoginModule required\n" +
106
" principal=\"host/host.r3.local@R3\"\n" +
107
" useKeyTab=true\n" +
108
" keyTab=localkdc.ktab\n" +
109
" isInitiator=false\n" +
110
" storeKey=true;\n};\n" +
111
"\n").getBytes());
112
fos.close();
113
114
Security.setProperty("auth.login.defaultCallbackHandler",
115
"OkAsDelegateXRealm");
116
117
System.setProperty("java.security.auth.login.config", "jaas-localkdc.conf");
118
119
Config.refresh();
120
121
Context c = Context.fromJAAS("com.sun.security.jgss.krb5.initiate");
122
Context s = Context.fromJAAS("com.sun.security.jgss.krb5.accept");
123
124
// Test twice. The frist time the whole cross realm process is tried,
125
// the second time the cached service ticket is used. This is to make sure
126
// the behaviors are the same, especailly for the case when one of the
127
// cross-realm TGTs does not have OK-AS-DELEGATE on.
128
129
for (int i=0; i<2; i++) {
130
c.startAsClient("[email protected]", GSSUtil.GSS_KRB5_MECH_OID);
131
s.startAsServer(GSSUtil.GSS_KRB5_MECH_OID);
132
c.x().requestDelegPolicy(true);
133
134
Context.handshake(c, s);
135
boolean succeed = true;
136
try {
137
s.x().getDelegCred();
138
} catch (GSSException gsse) {
139
succeed = false;
140
}
141
if (succeed != Boolean.parseBoolean(args[0])) {
142
throw new Exception("Test fail at round #" + i);
143
}
144
}
145
}
146
147
@Override
148
public void handle(Callback[] callbacks)
149
throws IOException, UnsupportedCallbackException {
150
for (Callback callback : callbacks) {
151
if (callback instanceof NameCallback) {
152
((NameCallback) callback).setName("dummy");
153
}
154
if (callback instanceof PasswordCallback) {
155
((PasswordCallback) callback).setPassword("bogus".toCharArray());
156
}
157
}
158
}
159
}
160
161
162