9499
|
1 |
/*
|
|
2 |
* Copyright (c) 2011, 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 6894072
|
|
27 |
* @compile -XDignore.symbol.file KeyTabCompat.java
|
|
28 |
* @run main/othervm KeyTabCompat
|
|
29 |
* @summary always refresh keytab
|
|
30 |
*/
|
|
31 |
|
|
32 |
import javax.security.auth.kerberos.KerberosKey;
|
|
33 |
import sun.security.jgss.GSSUtil;
|
|
34 |
|
|
35 |
/*
|
|
36 |
* There are 2 compat issues to check:
|
|
37 |
*
|
|
38 |
* 1. If there is only KerberosKeys in private credential set and no
|
|
39 |
* KerberosPrincipal. JAAS login should go on.
|
|
40 |
* 2. Even if KeyTab is used, user can still get KerberosKeys from
|
|
41 |
* private credentials set.
|
|
42 |
*/
|
|
43 |
public class KeyTabCompat {
|
|
44 |
|
|
45 |
public static void main(String[] args)
|
|
46 |
throws Exception {
|
|
47 |
OneKDC kdc = new OneKDC("aes128-cts");
|
|
48 |
kdc.writeJAASConf();
|
|
49 |
kdc.addPrincipal(OneKDC.SERVER, "pass1".toCharArray());
|
|
50 |
kdc.writeKtab(OneKDC.KTAB);
|
|
51 |
|
|
52 |
Context c, s;
|
|
53 |
|
|
54 |
// Part 1
|
|
55 |
c = Context.fromUserPass(OneKDC.USER, OneKDC.PASS, false);
|
|
56 |
s = Context.fromUserPass(OneKDC.USER2, OneKDC.PASS2, true);
|
|
57 |
|
|
58 |
s.s().getPrincipals().clear();
|
|
59 |
|
|
60 |
c.startAsClient(OneKDC.USER2, GSSUtil.GSS_KRB5_MECH_OID);
|
|
61 |
s.startAsServer(GSSUtil.GSS_KRB5_MECH_OID);
|
|
62 |
|
|
63 |
Context.handshake(c, s);
|
|
64 |
|
|
65 |
// Part 2
|
|
66 |
c = Context.fromJAAS("client");
|
|
67 |
s = Context.fromJAAS("server");
|
|
68 |
|
|
69 |
c.startAsClient(OneKDC.SERVER, GSSUtil.GSS_KRB5_MECH_OID);
|
|
70 |
s.startAsServer(GSSUtil.GSS_KRB5_MECH_OID);
|
|
71 |
s.status();
|
|
72 |
|
|
73 |
if (s.s().getPrivateCredentials(KerberosKey.class).size() != 1) {
|
|
74 |
throw new Exception("There should be one KerberosKey");
|
|
75 |
}
|
|
76 |
|
|
77 |
Thread.sleep(2000); // make sure ktab timestamp is different
|
|
78 |
|
|
79 |
kdc.addPrincipal(OneKDC.SERVER, "pass2".toCharArray());
|
|
80 |
kdc.writeKtab(OneKDC.KTAB);
|
|
81 |
|
|
82 |
Context.handshake(c, s);
|
|
83 |
s.status();
|
|
84 |
|
|
85 |
if (s.s().getPrivateCredentials(KerberosKey.class).size() != 1) {
|
|
86 |
throw new Exception("There should be only one KerberosKey");
|
|
87 |
}
|
|
88 |
|
|
89 |
}
|
|
90 |
}
|