2
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
|
2
|
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.
|
2
|
22 |
*/
|
|
23 |
|
|
24 |
/*
|
|
25 |
* @test
|
|
26 |
* @bug 6268315
|
|
27 |
* @summary Configuration should be provider-based
|
|
28 |
* @build GetInstanceConfigSpi GetInstanceProvider
|
|
29 |
* @run main/othervm/policy=GetInstanceSecurity.policy GetInstanceSecurity
|
|
30 |
*/
|
|
31 |
|
|
32 |
import java.io.File;
|
|
33 |
import java.net.URI;
|
|
34 |
import java.security.*;
|
|
35 |
import javax.security.auth.login.*;
|
|
36 |
|
|
37 |
import sun.net.www.ParseUtil;
|
|
38 |
|
|
39 |
public class GetInstanceSecurity {
|
|
40 |
|
|
41 |
private static final String JAVA_CONFIG = "JavaLoginConfig";
|
|
42 |
|
|
43 |
public static void main(String[] args) throws Exception {
|
|
44 |
try {
|
|
45 |
Configuration c = Configuration.getInstance(JAVA_CONFIG, null);
|
|
46 |
throw new RuntimeException("did not catch security exception");
|
|
47 |
} catch (SecurityException se) {
|
|
48 |
// good
|
|
49 |
}
|
|
50 |
|
|
51 |
try {
|
|
52 |
Configuration c = Configuration.getInstance
|
|
53 |
(JAVA_CONFIG, null, "SUN");
|
|
54 |
throw new RuntimeException("did not catch security exception");
|
|
55 |
} catch (SecurityException se) {
|
|
56 |
// good
|
|
57 |
}
|
|
58 |
|
|
59 |
try {
|
|
60 |
Configuration c = Configuration.getInstance
|
|
61 |
(JAVA_CONFIG, null, Security.getProvider("SUN"));
|
|
62 |
throw new RuntimeException("did not catch security exception");
|
|
63 |
} catch (SecurityException se) {
|
|
64 |
// good
|
|
65 |
}
|
|
66 |
|
|
67 |
// set a new policy that grants the perms, and then re-check perms
|
|
68 |
|
|
69 |
File file = new File(System.getProperty("test.src", "."),
|
|
70 |
"GetInstanceSecurity.grantedPolicy");
|
|
71 |
URI uri = file.toURI();
|
|
72 |
URIParameter param = new URIParameter(uri);
|
|
73 |
Policy p = Policy.getInstance("JavaPolicy", param, "SUN");
|
|
74 |
Policy.setPolicy(p);
|
|
75 |
|
|
76 |
// retry operations
|
|
77 |
|
|
78 |
file = new File(System.getProperty("test.src", "."),
|
|
79 |
"GetInstance.config");
|
|
80 |
URIParameter uriParam = new URIParameter(file.toURI());
|
|
81 |
|
|
82 |
try {
|
|
83 |
Configuration c = Configuration.getInstance(JAVA_CONFIG, uriParam);
|
|
84 |
} catch (SecurityException se) {
|
|
85 |
throw new RuntimeException("unexpected SecurityException");
|
|
86 |
}
|
|
87 |
|
|
88 |
try {
|
|
89 |
Configuration c = Configuration.getInstance
|
|
90 |
(JAVA_CONFIG, uriParam, "SUN");
|
|
91 |
// good
|
|
92 |
} catch (SecurityException se) {
|
|
93 |
throw new RuntimeException("unexpected SecurityException");
|
|
94 |
}
|
|
95 |
|
|
96 |
try {
|
|
97 |
Configuration c = Configuration.getInstance
|
|
98 |
(JAVA_CONFIG, uriParam, Security.getProvider("SUN"));
|
|
99 |
// good
|
|
100 |
} catch (SecurityException se) {
|
|
101 |
throw new RuntimeException("unexpected SecurityException");
|
|
102 |
}
|
|
103 |
|
|
104 |
System.out.println("test passed");
|
|
105 |
}
|
|
106 |
}
|