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/OkAsDelegate.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 OkAsDelegate false true true false false false
28
* FORWARDABLE ticket not allowed, always fail
29
* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock OkAsDelegate true false false false false false
30
* Service ticket no OK-AS-DELEGATE. Request nothing, gain nothing
31
* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock OkAsDelegate true false true false false false
32
* Service ticket no OK-AS-DELEGATE. Request deleg policy, gain nothing
33
* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock OkAsDelegate true true false true false true
34
* Service ticket no OK-AS-DELEGATE. Request deleg, granted
35
* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock OkAsDelegate true true true true false true
36
* Service ticket no OK-AS-DELEGATE. Request deleg and deleg policy, granted, with info not by policy
37
* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock -Dtest.kdc.policy.ok-as-delegate OkAsDelegate true false true true true true
38
* Service ticket has OK-AS-DELEGATE. Request deleg policy, granted
39
* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock -Dtest.kdc.policy.ok-as-delegate OkAsDelegate true true true true true true
40
* Service ticket has OK-AS-DELEGATE. granted, with info by policy
41
* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock -Dtest.spnego OkAsDelegate false true true false false false
42
* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock -Dtest.spnego OkAsDelegate true false false false false false
43
* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock -Dtest.spnego OkAsDelegate true false true false false false
44
* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock -Dtest.spnego OkAsDelegate true true false true false true
45
* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock -Dtest.spnego OkAsDelegate true true true true false true
46
* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock -Dtest.spnego -Dtest.kdc.policy.ok-as-delegate OkAsDelegate true false true true true true
47
* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock -Dtest.spnego -Dtest.kdc.policy.ok-as-delegate OkAsDelegate true true true true true true
48
* @summary Support OK-AS-DELEGATE flag
49
*/
50
import com.sun.security.jgss.ExtendedGSSContext;
51
import org.ietf.jgss.GSSCredential;
52
import org.ietf.jgss.GSSException;
53
import org.ietf.jgss.Oid;
54
import sun.security.jgss.GSSUtil;
55
import sun.security.krb5.Config;
56
57
public class OkAsDelegate {
58
59
public static void main(String[] args)
60
throws Exception {
61
OkAsDelegate ok = new OkAsDelegate();
62
ok.go(
63
Boolean.valueOf(args[0]), // FORWARDABLE in krb5.conf on?
64
Boolean.valueOf(args[1]), // requestDelegState
65
Boolean.valueOf(args[2]), // requestDelegPolicyState
66
Boolean.valueOf(args[3]), // DelegState in response
67
Boolean.valueOf(args[4]), // DelegPolicyState in response
68
Boolean.valueOf(args[5]) // getDelegCred OK?
69
);
70
}
71
72
void go(
73
boolean forwardable,
74
boolean requestDelegState,
75
boolean requestDelegPolicyState,
76
boolean delegState,
77
boolean delegPolicyState,
78
boolean delegated
79
) throws Exception {
80
OneKDC kdc = new OneKDC(null);
81
kdc.setOption(KDC.Option.OK_AS_DELEGATE,
82
System.getProperty("test.kdc.policy.ok-as-delegate"));
83
kdc.writeJAASConf();
84
if (!forwardable) {
85
// The default OneKDC always includes "forwardable = true"
86
// in krb5.conf, override it.
87
KDC.saveConfig(OneKDC.KRB5_CONF, kdc,
88
"default_keytab_name = " + OneKDC.KTAB);
89
Config.refresh();
90
}
91
92
Context c, s;
93
c = Context.fromJAAS("client");
94
s = Context.fromJAAS("com.sun.security.jgss.krb5.accept");
95
96
Oid mech = GSSUtil.GSS_KRB5_MECH_OID;
97
if (System.getProperty("test.spnego") != null) {
98
mech = GSSUtil.GSS_SPNEGO_MECH_OID;
99
}
100
c.startAsClient(OneKDC.SERVER, mech);
101
ExtendedGSSContext cx = (ExtendedGSSContext)c.x();
102
cx.requestCredDeleg(requestDelegState);
103
cx.requestDelegPolicy(requestDelegPolicyState);
104
s.startAsServer(mech);
105
ExtendedGSSContext sx = (ExtendedGSSContext)s.x();
106
107
Context.handshake(c, s);
108
109
if (cx.getCredDelegState() != delegState) {
110
throw new Exception("Initiator cred state error");
111
}
112
if (sx.getCredDelegState() != delegState) {
113
throw new Exception("Acceptor cred state error");
114
}
115
if (cx.getDelegPolicyState() != delegPolicyState) {
116
throw new Exception("Initiator cred policy state error");
117
}
118
119
GSSCredential cred = null;
120
try {
121
cred = s.x().getDelegCred();
122
} catch (GSSException e) {
123
// leave cred as null
124
}
125
126
if (delegated != (cred != null)) {
127
throw new Exception("get cred error");
128
}
129
}
130
}
131
132