Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/provider/PolicyFile/WildcardPrincipalName.java
41153 views
1
/*
2
* Copyright (c) 2013, 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 8008908
27
* @summary wildcard principal names are not processed correctly
28
* @run main/othervm/policy=wildcard.policy WildcardPrincipalName
29
*/
30
31
import java.security.AccessController;
32
import java.security.Permission;
33
import java.security.Principal;
34
import java.security.PrivilegedAction;
35
import java.util.HashSet;
36
import java.util.PropertyPermission;
37
import java.util.Set;
38
import javax.security.auth.Subject;
39
import javax.security.auth.x500.X500Principal;
40
41
public class WildcardPrincipalName {
42
43
public static void main(String[] args) throws Exception {
44
45
X500Principal duke = new X500Principal("CN=Duke");
46
PropertyPermission pp = new PropertyPermission("user.home", "read");
47
RunAsPrivilegedUserAction runAsPrivilegedUserAction
48
= new RunAsPrivilegedUserAction(duke,
49
new CheckPermissionAction(pp));
50
AccessController.doPrivileged(runAsPrivilegedUserAction);
51
System.out.println("test PASSED");
52
}
53
54
private static class RunAsPrivilegedUserAction
55
implements PrivilegedAction<Void> {
56
private final PrivilegedAction<Void> action;
57
private final Principal principal;
58
59
RunAsPrivilegedUserAction(Principal principal,
60
PrivilegedAction<Void> action) {
61
this.principal = principal;
62
this.action = action;
63
}
64
65
@Override public Void run() {
66
Set<Principal> principals = new HashSet<>();
67
Set<Object> publicCredentials = new HashSet<>();
68
Set<Object> privateCredentials = new HashSet<>();
69
70
principals.add(principal);
71
Subject subject = new Subject(true,
72
principals,
73
publicCredentials,
74
privateCredentials);
75
76
Subject.doAsPrivileged(subject, action, null);
77
return null;
78
}
79
}
80
81
private static class CheckPermissionAction
82
implements PrivilegedAction<Void> {
83
private final Permission permission;
84
85
CheckPermissionAction(Permission permission) {
86
this.permission = permission;
87
}
88
89
@Override public Void run() {
90
AccessController.checkPermission(permission);
91
return null;
92
}
93
}
94
}
95
96