author | stefank |
Mon, 25 Aug 2014 09:10:13 +0200 | |
changeset 26314 | f8bc1966fb30 |
parent 14413 | e954df027393 |
child 26629 | 3b9ed8175488 |
permissions | -rw-r--r-- |
4336 | 1 |
/* |
12867 | 2 |
* Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. |
4336 | 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 |
* |
|
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. |
|
4336 | 22 |
*/ |
23 |
||
12867 | 24 |
/* |
25 |
* @test |
|
26 |
* @bug 6853328 7172701 |
|
27 |
* @run main/othervm OkAsDelegate false true true false false false |
|
28 |
* FORWARDABLE ticket not allowed, always fail |
|
29 |
* @run main/othervm OkAsDelegate true false false false false false |
|
30 |
* Service ticket no OK-AS-DELEGATE. Request nothing, gain nothing |
|
31 |
* @run main/othervm OkAsDelegate true false true false false false |
|
32 |
* Service ticket no OK-AS-DELEGATE. Request deleg policy, gain nothing |
|
33 |
* @run main/othervm OkAsDelegate true true false true false true |
|
34 |
* Service ticket no OK-AS-DELEGATE. Request deleg, granted |
|
35 |
* @run main/othervm 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 -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 -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 -Dtest.spnego OkAsDelegate false true true false false false |
|
42 |
* @run main/othervm -Dtest.spnego OkAsDelegate true false false false false false |
|
43 |
* @run main/othervm -Dtest.spnego OkAsDelegate true false true false false false |
|
44 |
* @run main/othervm -Dtest.spnego OkAsDelegate true true false true false true |
|
45 |
* @run main/othervm -Dtest.spnego OkAsDelegate true true true true false true |
|
46 |
* @run main/othervm -Dtest.spnego -Dtest.kdc.policy.ok-as-delegate OkAsDelegate true false true true true true |
|
47 |
* @run main/othervm -Dtest.spnego -Dtest.kdc.policy.ok-as-delegate OkAsDelegate true true true true true true |
|
48 |
* @summary Support OK-AS-DELEGATE flag |
|
49 |
*/ |
|
4336 | 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); |
|
12867 | 81 |
kdc.setOption(KDC.Option.OK_AS_DELEGATE, |
4336 | 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"); |
|
14413
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
12867
diff
changeset
|
94 |
s = Context.fromJAAS("com.sun.security.jgss.krb5.accept"); |
4336 | 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 |
} |