4336
|
1 |
/*
|
|
2 |
* Copyright 2009 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
21 |
* have any questions.
|
|
22 |
*/
|
|
23 |
|
|
24 |
import com.sun.security.jgss.ExtendedGSSContext;
|
|
25 |
import org.ietf.jgss.GSSCredential;
|
|
26 |
import org.ietf.jgss.GSSException;
|
|
27 |
import org.ietf.jgss.Oid;
|
|
28 |
import sun.security.jgss.GSSUtil;
|
|
29 |
import sun.security.krb5.Config;
|
|
30 |
|
|
31 |
public class OkAsDelegate {
|
|
32 |
|
|
33 |
public static void main(String[] args)
|
|
34 |
throws Exception {
|
|
35 |
OkAsDelegate ok = new OkAsDelegate();
|
|
36 |
ok.go(
|
|
37 |
Boolean.valueOf(args[0]), // FORWARDABLE in krb5.conf on?
|
|
38 |
Boolean.valueOf(args[1]), // requestDelegState
|
|
39 |
Boolean.valueOf(args[2]), // requestDelegPolicyState
|
|
40 |
Boolean.valueOf(args[3]), // DelegState in response
|
|
41 |
Boolean.valueOf(args[4]), // DelegPolicyState in response
|
|
42 |
Boolean.valueOf(args[5]) // getDelegCred OK?
|
|
43 |
);
|
|
44 |
}
|
|
45 |
|
|
46 |
void go(
|
|
47 |
boolean forwardable,
|
|
48 |
boolean requestDelegState,
|
|
49 |
boolean requestDelegPolicyState,
|
|
50 |
boolean delegState,
|
|
51 |
boolean delegPolicyState,
|
|
52 |
boolean delegated
|
|
53 |
) throws Exception {
|
|
54 |
OneKDC kdc = new OneKDC(null);
|
|
55 |
kdc.setPolicy("ok-as-delegate",
|
|
56 |
System.getProperty("test.kdc.policy.ok-as-delegate"));
|
|
57 |
kdc.writeJAASConf();
|
|
58 |
if (!forwardable) {
|
|
59 |
// The default OneKDC always includes "forwardable = true"
|
|
60 |
// in krb5.conf, override it.
|
|
61 |
KDC.saveConfig(OneKDC.KRB5_CONF, kdc,
|
|
62 |
"default_keytab_name = " + OneKDC.KTAB);
|
|
63 |
Config.refresh();
|
|
64 |
}
|
|
65 |
|
|
66 |
Context c, s;
|
|
67 |
c = Context.fromJAAS("client");
|
|
68 |
s = Context.fromJAAS("server");
|
|
69 |
|
|
70 |
Oid mech = GSSUtil.GSS_KRB5_MECH_OID;
|
|
71 |
if (System.getProperty("test.spnego") != null) {
|
|
72 |
mech = GSSUtil.GSS_SPNEGO_MECH_OID;
|
|
73 |
}
|
|
74 |
c.startAsClient(OneKDC.SERVER, mech);
|
|
75 |
ExtendedGSSContext cx = (ExtendedGSSContext)c.x();
|
|
76 |
cx.requestCredDeleg(requestDelegState);
|
|
77 |
cx.requestDelegPolicy(requestDelegPolicyState);
|
|
78 |
s.startAsServer(mech);
|
|
79 |
ExtendedGSSContext sx = (ExtendedGSSContext)s.x();
|
|
80 |
|
|
81 |
Context.handshake(c, s);
|
|
82 |
|
|
83 |
if (cx.getCredDelegState() != delegState) {
|
|
84 |
throw new Exception("Initiator cred state error");
|
|
85 |
}
|
|
86 |
if (sx.getCredDelegState() != delegState) {
|
|
87 |
throw new Exception("Acceptor cred state error");
|
|
88 |
}
|
|
89 |
if (cx.getDelegPolicyState() != delegPolicyState) {
|
|
90 |
throw new Exception("Initiator cred policy state error");
|
|
91 |
}
|
|
92 |
|
|
93 |
GSSCredential cred = null;
|
|
94 |
try {
|
|
95 |
cred = s.x().getDelegCred();
|
|
96 |
} catch (GSSException e) {
|
|
97 |
// leave cred as null
|
|
98 |
}
|
|
99 |
|
|
100 |
if (delegated != (cred != null)) {
|
|
101 |
throw new Exception("get cred error");
|
|
102 |
}
|
|
103 |
}
|
|
104 |
}
|