author | weijun |
Fri, 12 Aug 2011 11:20:45 +0800 | |
changeset 10327 | 37a3f951eb3a |
parent 9008 | 1c23e333dd76 |
child 14327 | c0d86f6f8be8 |
permissions | -rw-r--r-- |
3221
98ac5a3e79e9
6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff
changeset
|
1 |
/* |
9008
1c23e333dd76
7031536: test/sun/security/krb5/auto/HttpNegotiateServer.java should not use static ports
weijun
parents:
6123
diff
changeset
|
2 |
* Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. |
3221
98ac5a3e79e9
6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
98ac5a3e79e9
6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff
changeset
|
4 |
* |
98ac5a3e79e9
6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
98ac5a3e79e9
6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
98ac5a3e79e9
6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
98ac5a3e79e9
6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff
changeset
|
8 |
* |
98ac5a3e79e9
6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
98ac5a3e79e9
6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
98ac5a3e79e9
6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
98ac5a3e79e9
6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
98ac5a3e79e9
6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff
changeset
|
13 |
* accompanied this code). |
98ac5a3e79e9
6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff
changeset
|
14 |
* |
98ac5a3e79e9
6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
98ac5a3e79e9
6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
98ac5a3e79e9
6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
98ac5a3e79e9
6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff
changeset
|
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. |
|
3221
98ac5a3e79e9
6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff
changeset
|
22 |
*/ |
98ac5a3e79e9
6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff
changeset
|
23 |
/* |
98ac5a3e79e9
6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff
changeset
|
24 |
* @test |
98ac5a3e79e9
6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff
changeset
|
25 |
* @bug 6857795 |
3422
72bf5182bb8b
6867231: Regression: jdk/test/sun/security/krb5/ConfPlusProp.java error against jdk7/pit/b68
weijun
parents:
3315
diff
changeset
|
26 |
* @bug 6858589 |
6123
664a0a541d26
6972005: ConfPlusProp.java test failure when DNS has info for realm
weijun
parents:
5506
diff
changeset
|
27 |
* @bug 6972005 |
9008
1c23e333dd76
7031536: test/sun/security/krb5/auto/HttpNegotiateServer.java should not use static ports
weijun
parents:
6123
diff
changeset
|
28 |
* @run main/othervm ConfPlusProp |
3221
98ac5a3e79e9
6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff
changeset
|
29 |
* @summary krb5.conf ignored if system properties on realm and kdc are provided |
98ac5a3e79e9
6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff
changeset
|
30 |
*/ |
98ac5a3e79e9
6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff
changeset
|
31 |
|
98ac5a3e79e9
6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff
changeset
|
32 |
import sun.security.krb5.Config; |
98ac5a3e79e9
6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff
changeset
|
33 |
|
98ac5a3e79e9
6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff
changeset
|
34 |
public class ConfPlusProp { |
3315
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
35 |
Config config; |
3221
98ac5a3e79e9
6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff
changeset
|
36 |
public static void main(String[] args) throws Exception { |
3315
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
37 |
new ConfPlusProp().run(); |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
38 |
} |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
39 |
|
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
40 |
void refresh() throws Exception { |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
41 |
Config.refresh(); |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
42 |
config = Config.getInstance(); |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
43 |
} |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
44 |
|
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
45 |
void checkDefaultRealm(String r) throws Exception { |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
46 |
try { |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
47 |
if (!config.getDefaultRealm().equals(r)) { |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
48 |
throw new AssertionError("Default realm error"); |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
49 |
} |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
50 |
} catch (Exception e) { |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
51 |
if (r != null) throw e; |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
52 |
} |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
53 |
} |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
54 |
|
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
55 |
void check(String r, String k) throws Exception { |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
56 |
try { |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
57 |
if (!config.getKDCList(r).equals(k)) { |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
58 |
throw new AssertionError(r + " kdc not " + k); |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
59 |
} |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
60 |
} catch (Exception e) { |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
61 |
if (k != null) throw e; |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
62 |
} |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
63 |
} |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
64 |
|
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
65 |
void run() throws Exception { |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
66 |
|
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
67 |
// No prop, only conf |
3221
98ac5a3e79e9
6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff
changeset
|
68 |
|
98ac5a3e79e9
6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff
changeset
|
69 |
// Point to a file with existing default_realm |
98ac5a3e79e9
6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff
changeset
|
70 |
System.setProperty("java.security.krb5.conf", |
98ac5a3e79e9
6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff
changeset
|
71 |
System.getProperty("test.src", ".") +"/confplusprop.conf"); |
3315
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
72 |
refresh(); |
3221
98ac5a3e79e9
6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff
changeset
|
73 |
|
3315
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
74 |
checkDefaultRealm("R1"); |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
75 |
check("R1", "k1"); |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
76 |
check("R2", "old"); |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
77 |
check("R3", null); |
3221
98ac5a3e79e9
6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff
changeset
|
78 |
if (!config.getDefault("forwardable", "libdefaults").equals("well")) { |
98ac5a3e79e9
6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff
changeset
|
79 |
throw new Exception("Extra config error"); |
98ac5a3e79e9
6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff
changeset
|
80 |
} |
98ac5a3e79e9
6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff
changeset
|
81 |
|
98ac5a3e79e9
6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff
changeset
|
82 |
// Point to a file with no libdefaults |
98ac5a3e79e9
6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff
changeset
|
83 |
System.setProperty("java.security.krb5.conf", |
98ac5a3e79e9
6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff
changeset
|
84 |
System.getProperty("test.src", ".") +"/confplusprop2.conf"); |
3315
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
85 |
refresh(); |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
86 |
|
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
87 |
checkDefaultRealm(null); |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
88 |
check("R1", "k12"); |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
89 |
check("R2", "old"); |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
90 |
check("R3", null); |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
91 |
|
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
92 |
int version = System.getProperty("java.version").charAt(2) - '0'; |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
93 |
System.out.println("JDK version is " + version); |
3221
98ac5a3e79e9
6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff
changeset
|
94 |
|
3315
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
95 |
// Zero-config is supported since 1.7 |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
96 |
if (version >= 7) { |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
97 |
// Point to a non-existing file |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
98 |
System.setProperty("java.security.krb5.conf", "i-am-not-a file"); |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
99 |
refresh(); |
3221
98ac5a3e79e9
6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff
changeset
|
100 |
|
6123
664a0a541d26
6972005: ConfPlusProp.java test failure when DNS has info for realm
weijun
parents:
5506
diff
changeset
|
101 |
// Default realm might come from DNS |
664a0a541d26
6972005: ConfPlusProp.java test failure when DNS has info for realm
weijun
parents:
5506
diff
changeset
|
102 |
//checkDefaultRealm(null); |
3315
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
103 |
check("R1", null); |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
104 |
check("R2", null); |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
105 |
check("R3", null); |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
106 |
if (config.getDefault("forwardable", "libdefaults") != null) { |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
107 |
throw new Exception("Extra config error"); |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
108 |
} |
3221
98ac5a3e79e9
6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff
changeset
|
109 |
} |
3315
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
110 |
|
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
111 |
// Add prop |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
112 |
System.setProperty("java.security.krb5.realm", "R2"); |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
113 |
System.setProperty("java.security.krb5.kdc", "k2"); |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
114 |
|
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
115 |
// Point to a file with existing default_realm |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
116 |
System.setProperty("java.security.krb5.conf", |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
117 |
System.getProperty("test.src", ".") +"/confplusprop.conf"); |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
118 |
refresh(); |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
119 |
|
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
120 |
checkDefaultRealm("R2"); |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
121 |
check("R1", "k1"); |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
122 |
check("R2", "k2"); |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
123 |
check("R3", "k2"); |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
124 |
if (!config.getDefault("forwardable", "libdefaults").equals("well")) { |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
125 |
throw new Exception("Extra config error"); |
3221
98ac5a3e79e9
6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff
changeset
|
126 |
} |
3315
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
127 |
|
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
128 |
// Point to a file with no libdefaults |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
129 |
System.setProperty("java.security.krb5.conf", |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
130 |
System.getProperty("test.src", ".") +"/confplusprop2.conf"); |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
131 |
refresh(); |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
132 |
|
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
133 |
checkDefaultRealm("R2"); |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
134 |
check("R1", "k12"); |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
135 |
check("R2", "k2"); |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
136 |
check("R3", "k2"); |
3221
98ac5a3e79e9
6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff
changeset
|
137 |
|
98ac5a3e79e9
6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff
changeset
|
138 |
// Point to a non-existing file |
98ac5a3e79e9
6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff
changeset
|
139 |
System.setProperty("java.security.krb5.conf", "i-am-not-a file"); |
3315
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
140 |
refresh(); |
3221
98ac5a3e79e9
6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff
changeset
|
141 |
|
3315
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
142 |
checkDefaultRealm("R2"); |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
143 |
check("R1", "k2"); |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
144 |
check("R2", "k2"); |
2c61231c7973
6858589: more changes to Config on system properties
weijun
parents:
3221
diff
changeset
|
145 |
check("R3", "k2"); |
3221
98ac5a3e79e9
6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff
changeset
|
146 |
if (config.getDefault("forwardable", "libdefaults") != null) { |
98ac5a3e79e9
6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff
changeset
|
147 |
throw new Exception("Extra config error"); |
98ac5a3e79e9
6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff
changeset
|
148 |
} |
98ac5a3e79e9
6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff
changeset
|
149 |
} |
98ac5a3e79e9
6857795: krb5.conf ignored if system properties on realm and kdc are provided
weijun
parents:
diff
changeset
|
150 |
} |