Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/krb5/auto/AcceptPermissions.java
41152 views
1
/*
2
* Copyright (c) 2012, 2018, 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 8005447 8194486
27
* @summary default principal can act as anyone
28
* @library /test/lib
29
* @compile -XDignore.symbol.file AcceptPermissions.java
30
* @run main jdk.test.lib.FileInstaller TestHosts TestHosts
31
* @run main/othervm -Djava.security.manager=allow -Djdk.net.hosts.file=TestHosts AcceptPermissions two
32
* @run main/othervm -Djava.security.manager=allow -Djdk.net.hosts.file=TestHosts AcceptPermissions unbound
33
*/
34
35
import java.nio.file.Files;
36
import java.nio.file.Paths;
37
import java.nio.file.StandardOpenOption;
38
import java.security.Permission;
39
import javax.security.auth.kerberos.ServicePermission;
40
import sun.security.jgss.GSSUtil;
41
import java.util.*;
42
43
public class AcceptPermissions extends SecurityManager {
44
45
private static Map<Permission,String> perms = new HashMap<>();
46
@Override
47
public void checkPermission(Permission perm) {
48
if (!(perm instanceof ServicePermission)) {
49
return;
50
}
51
ServicePermission sp = (ServicePermission)perm;
52
if (!sp.getActions().equals("accept")) {
53
return;
54
}
55
// We only care about accept ServicePermission in this test
56
try {
57
super.checkPermission(sp);
58
} catch (SecurityException se) {
59
if (perms.containsKey(sp)) {
60
perms.put(sp, "checked");
61
} else {
62
throw se; // We didn't expect this is needed
63
}
64
}
65
}
66
67
// Fills in permissions we are expecting
68
private static void initPerms(String... names) {
69
perms.clear();
70
for (String name: names) {
71
perms.put(new ServicePermission(
72
name + "@" + OneKDC.REALM, "accept"), "expected");
73
}
74
}
75
76
// Checks if they are all checked
77
private static void checkPerms() {
78
for (Map.Entry<Permission,String> entry: perms.entrySet()) {
79
if (entry.getValue().equals("expected")) {
80
throw new RuntimeException(
81
"Expected but not used: " + entry.getKey());
82
}
83
}
84
}
85
86
public static void main(String[] args) throws Exception {
87
System.setSecurityManager(new AcceptPermissions());
88
new OneKDC(null).writeJAASConf();
89
String moreEntries = "two {\n"
90
+ " com.sun.security.auth.module.Krb5LoginModule required"
91
+ " principal=\"" + OneKDC.SERVER + "\" useKeyTab=true"
92
+ " isInitiator=false storeKey=true;\n"
93
+ " com.sun.security.auth.module.Krb5LoginModule required"
94
+ " principal=\"" + OneKDC.BACKEND + "\" useKeyTab=true"
95
+ " isInitiator=false storeKey=true;\n"
96
+ "};\n"
97
+ "unbound {"
98
+ " com.sun.security.auth.module.Krb5LoginModule required"
99
+ " principal=* useKeyTab=true"
100
+ " isInitiator=false storeKey=true;\n"
101
+ "};\n";
102
Files.write(Paths.get(OneKDC.JAAS_CONF), moreEntries.getBytes(),
103
StandardOpenOption.APPEND);
104
105
Context c, s;
106
107
// In all cases, a ServicePermission on the acceptor name is needed
108
// for a handshake. For default principal with no predictable name,
109
// permission not needed (yet) for credentials creation.
110
111
// Named principal
112
initPerms(OneKDC.SERVER);
113
c = Context.fromJAAS("client");
114
s = Context.fromJAAS("server");
115
c.startAsClient(OneKDC.SERVER, GSSUtil.GSS_KRB5_MECH_OID);
116
s.startAsServer(OneKDC.SERVER, GSSUtil.GSS_KRB5_MECH_OID);
117
checkPerms();
118
initPerms(OneKDC.SERVER);
119
Context.handshake(c, s);
120
checkPerms();
121
122
// Named principal (even if there are 2 JAAS modules)
123
initPerms(OneKDC.SERVER);
124
c = Context.fromJAAS("client");
125
s = Context.fromJAAS(args[0]);
126
c.startAsClient(OneKDC.SERVER, GSSUtil.GSS_KRB5_MECH_OID);
127
s.startAsServer(OneKDC.SERVER, GSSUtil.GSS_KRB5_MECH_OID);
128
checkPerms();
129
initPerms(OneKDC.SERVER);
130
Context.handshake(c, s);
131
checkPerms();
132
133
// Default principal with a predictable name
134
initPerms(OneKDC.SERVER);
135
c = Context.fromJAAS("client");
136
s = Context.fromJAAS("server");
137
c.startAsClient(OneKDC.SERVER, GSSUtil.GSS_KRB5_MECH_OID);
138
s.startAsServer(GSSUtil.GSS_KRB5_MECH_OID);
139
checkPerms();
140
initPerms(OneKDC.SERVER);
141
Context.handshake(c, s);
142
checkPerms();
143
144
// Default principal with no predictable name
145
initPerms(); // permission not needed for cred !!!
146
c = Context.fromJAAS("client");
147
s = Context.fromJAAS(args[0]);
148
c.startAsClient(OneKDC.SERVER, GSSUtil.GSS_KRB5_MECH_OID);
149
s.startAsServer(GSSUtil.GSS_KRB5_MECH_OID);
150
checkPerms();
151
initPerms(OneKDC.SERVER); // still needed for handshake !!!
152
Context.handshake(c, s);
153
checkPerms();
154
}
155
}
156
157