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