Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/security/PermissionCollection/AddToReadOnlyPermissionCollection.java
41149 views
1
/*
2
* Copyright (c) 1999, 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
* @author Gary Ellison
27
* @bug 4232694
28
* @summary PermissionCollection.setReadOnly() does not preclude using add()
29
*/
30
31
import java.security.*;
32
import java.net.SocketPermission;
33
import java.io.FilePermission;
34
import java.util.PropertyPermission;
35
36
public class AddToReadOnlyPermissionCollection {
37
public static void main(String args[]) throws Exception {
38
39
try {
40
if (args.length == 0) {
41
tryAllPC();
42
tryBasicPC();
43
tryFilePC();
44
tryPropPC();
45
trySockPC();
46
} else {
47
for (int i=0; i <args.length; i++) {
48
switch (args[i].toLowerCase().charAt(1)) {
49
case 'a':
50
tryAllPC();
51
break;
52
case 'b':
53
tryBasicPC();
54
break;
55
case 'f':
56
tryFilePC();
57
break;
58
case 'p':
59
tryPropPC();
60
break;
61
case 's':
62
trySockPC();
63
break;
64
default:
65
throw new Exception("usage: AddToReadOnlyPermissonCollection [-a -b -f -p -s]");
66
}
67
}
68
}
69
} catch (Exception e) {
70
throw e;
71
}
72
System.out.println("Passed. OKAY");
73
}
74
75
static void tryPropPC() throws Exception {
76
try {
77
PropertyPermission p0 = new PropertyPermission("user.home","read");
78
PermissionCollection pc = p0.newPermissionCollection();
79
pc.setReadOnly(); // this should lock out future adds
80
//
81
PropertyPermission p1 = new PropertyPermission("java.home","read");
82
pc.add(p1);
83
throw new
84
Exception("Failed...PropertyPermission added to readonly PropertyPermissionCollection.");
85
86
} catch (SecurityException se) {
87
System.out.println("PropertyPermissionCollection passed");
88
}
89
}
90
91
static void trySockPC() throws Exception {
92
try {
93
SocketPermission p0= new SocketPermission("example.com","connect");
94
PermissionCollection pc = p0.newPermissionCollection();
95
pc.setReadOnly(); // this should lock out future adds
96
//
97
SocketPermission p1= new SocketPermission("example.net","connect");
98
pc.add(p1);
99
throw new
100
Exception("Failed...SocketPermission added to readonly SocketPermissionCollection.");
101
102
} catch (SecurityException se) {
103
System.out.println("SocketPermissionCollection passed");
104
}
105
106
}
107
108
static void tryFilePC() throws Exception {
109
try {
110
FilePermission p0 = new FilePermission("/tmp/foobar","read");
111
PermissionCollection pc = p0.newPermissionCollection();
112
pc.setReadOnly(); // this should lock out future adds
113
//
114
FilePermission p1 = new FilePermission("/tmp/quux","read");
115
pc.add(p1);
116
throw new
117
Exception("Failed...FilePermission added to readonly FilePermissionCollection.");
118
119
} catch (SecurityException se) {
120
System.out.println("FilePermissionCollection passed");
121
}
122
}
123
124
static void tryBasicPC() throws Exception {
125
try {
126
MyBasicPermission p0 = new MyBasicPermission("BasicPermision");
127
PermissionCollection pc = p0.newPermissionCollection();
128
pc.setReadOnly(); // this should lock out future adds
129
//
130
MyBasicPermission p1 = new MyBasicPermission("EvenMoreBasic");
131
pc.add(p1);
132
throw new
133
Exception("Failed...BasicPermission added to readonly BasicPermissionCollection.");
134
135
} catch (SecurityException se) {
136
System.out.println("BasicPermissionCollection passed");
137
}
138
}
139
140
static void tryAllPC() throws Exception {
141
try {
142
AllPermission p0 = new AllPermission("AllOfIt","read");
143
PermissionCollection pc = p0.newPermissionCollection();
144
pc.setReadOnly(); // this should lock out future adds
145
//
146
AllPermission p1 = new AllPermission("SomeOfIt","read");
147
pc.add(p1);
148
throw new
149
Exception("Failed...AllPermission added to readonly AllPermissionCollection.");
150
151
} catch (SecurityException se) {
152
System.out.println("AllPermissionCollection passed");
153
}
154
}
155
156
}
157
158
class MyBasicPermission extends BasicPermission {
159
public MyBasicPermission(String name) {
160
super(name);
161
}
162
}
163
164