Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/provider/PolicyFile/SelfWildcard.java
41153 views
1
/*
2
* Copyright (c) 2002, 2003, 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 4510424
27
* @summary ${{self}} expansion fails for grants with wildcard principal names
28
*/
29
30
import java.util.*;
31
import java.security.*;
32
import javax.security.auth.Subject.*;
33
import javax.security.auth.x500.*;
34
35
public class SelfWildcard {
36
37
private static final String SELF_ONE =
38
"javax.security.auth.x500.X500Principal \"CN=foo\"";
39
private static final String SELF_TWOTHREE =
40
"javax.security.auth.x500.X500Principal \"CN=foo\", " +
41
"javax.security.auth.x500.X500Principal \"CN=bar\"";
42
private static final String SELF_FOURFIVE =
43
"javax.security.auth.x500.X500Principal \"CN=foo\", " +
44
"javax.security.auth.x500.X500Principal \"CN=bar\", " +
45
"com.sun.security.auth.UnixPrincipal \"foobar\"";
46
47
public static void main(String[] args) throws Exception {
48
if (System.getProperty("test.src") == null) {
49
System.setProperty("test.src", ".");
50
}
51
System.setProperty("java.security.policy",
52
"file:${test.src}/SelfWildcard.policy");
53
54
Principal[] ps = {
55
new X500Principal("CN=foo"),
56
new X500Principal("CN=bar"),
57
new com.sun.security.auth.UnixPrincipal("foobar") };
58
ProtectionDomain pd = new ProtectionDomain
59
(new CodeSource(null, (java.security.cert.Certificate[]) null),
60
null, null, ps);
61
PermissionCollection perms = Policy.getPolicy().getPermissions(pd);
62
System.out.println("perms = " + perms);
63
System.out.println();
64
65
Enumeration e = perms.elements();
66
while (e.hasMoreElements()) {
67
Permission p = (Permission)e.nextElement();
68
if (p instanceof UnresolvedPermission &&
69
p.toString().indexOf(SELF_ONE) < 0 &&
70
p.toString().indexOf(SELF_TWOTHREE) < 0 &&
71
p.toString().indexOf(SELF_FOURFIVE) < 0) {
72
throw new SecurityException("Test Failed");
73
}
74
}
75
76
System.out.println("Test Succeeded");
77
}
78
}
79
80