1454
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
|
1454
|
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.
|
1454
|
22 |
*/
|
|
23 |
|
|
24 |
/*
|
|
25 |
* @test
|
|
26 |
* @bug 6706974
|
|
27 |
* @summary Add krb5 test infrastructure
|
|
28 |
*/
|
|
29 |
|
|
30 |
import org.ietf.jgss.GSSName;
|
|
31 |
import sun.security.jgss.GSSUtil;
|
|
32 |
import sun.security.krb5.Config;
|
|
33 |
import sun.security.krb5.internal.crypto.EType;
|
|
34 |
|
|
35 |
/**
|
|
36 |
* Basic JGSS/krb5 test with 3 parties: client, server, backend server. Each
|
|
37 |
* party uses JAAS login to get subjects and executes JGSS calls using
|
|
38 |
* Subject.doAs.
|
|
39 |
*/
|
|
40 |
public class BasicKrb5Test {
|
|
41 |
|
|
42 |
/**
|
|
43 |
* @param args empty or etype
|
|
44 |
*/
|
|
45 |
public static void main(String[] args)
|
|
46 |
throws Exception {
|
|
47 |
|
|
48 |
String etype = null;
|
|
49 |
if (args.length > 0) {
|
|
50 |
etype = args[0];
|
|
51 |
}
|
1456
|
52 |
|
|
53 |
// Creates and starts the KDC. This line must be put ahead of etype check
|
|
54 |
// since the check needs a krb5.conf.
|
|
55 |
new OneKDC(etype).writeJAASConf();
|
|
56 |
|
1454
|
57 |
System.out.println("Testing etype " + etype);
|
|
58 |
if (etype != null && !EType.isSupported(Config.getInstance().getType(etype))) {
|
|
59 |
System.out.println("Not supported.");
|
|
60 |
System.exit(0);
|
|
61 |
}
|
|
62 |
|
|
63 |
new BasicKrb5Test().go(OneKDC.SERVER, OneKDC.BACKEND);
|
|
64 |
}
|
|
65 |
|
|
66 |
void go(final String server, final String backend) throws Exception {
|
|
67 |
Context c, s, s2, b;
|
|
68 |
c = Context.fromJAAS("client");
|
|
69 |
s = Context.fromJAAS("server");
|
|
70 |
b = Context.fromJAAS("backend");
|
|
71 |
|
|
72 |
c.startAsClient(server, GSSUtil.GSS_KRB5_MECH_OID);
|
|
73 |
c.x().requestCredDeleg(true);
|
|
74 |
s.startAsServer(GSSUtil.GSS_KRB5_MECH_OID);
|
|
75 |
|
|
76 |
c.status();
|
|
77 |
s.status();
|
|
78 |
|
|
79 |
Context.handshake(c, s);
|
|
80 |
GSSName client = c.x().getSrcName();
|
|
81 |
|
|
82 |
c.status();
|
|
83 |
s.status();
|
|
84 |
|
|
85 |
Context.transmit("i say high --", c, s);
|
|
86 |
Context.transmit(" you say low", s, c);
|
|
87 |
|
|
88 |
s2 = s.delegated();
|
|
89 |
s.dispose();
|
|
90 |
s = null;
|
|
91 |
|
|
92 |
s2.startAsClient(backend, GSSUtil.GSS_KRB5_MECH_OID);
|
|
93 |
b.startAsServer(GSSUtil.GSS_KRB5_MECH_OID);
|
|
94 |
|
|
95 |
s2.status();
|
|
96 |
b.status();
|
|
97 |
|
|
98 |
Context.handshake(s2, b);
|
|
99 |
GSSName client2 = b.x().getSrcName();
|
|
100 |
|
|
101 |
if (!client.equals(client2)) {
|
|
102 |
throw new Exception("Delegation failed");
|
|
103 |
}
|
|
104 |
|
|
105 |
s2.status();
|
|
106 |
b.status();
|
|
107 |
|
|
108 |
Context.transmit("you say hello --", s2, b);
|
|
109 |
Context.transmit(" i say goodbye", b, s2);
|
|
110 |
|
|
111 |
s2.dispose();
|
|
112 |
b.dispose();
|
|
113 |
}
|
|
114 |
}
|