Skip to content

Commit 2d74f74

Browse files
committed
Fix SecurityManager.
1 parent 3029131 commit 2d74f74

File tree

2 files changed

+1
-127
lines changed

2 files changed

+1
-127
lines changed

src/main/java/io/github/albertus82/jface/sysinfo/SystemInformationDialog.java

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.github.albertus82.jface.sysinfo;
22

3-
import java.lang.management.ManagementPermission;
43
import java.lang.reflect.InvocationTargetException;
54
import java.util.Collections;
65
import java.util.Map;
@@ -96,32 +95,7 @@ public class SystemInformationDialog extends Dialog {
9695
* {@code false}.
9796
*/
9897
public static boolean isAvailable() {
99-
final SecurityManager sm = System.getSecurityManager();
100-
if (sm == null) {
101-
return true;
102-
}
103-
try {
104-
sm.checkPropertiesAccess(); // system properties
105-
return true;
106-
}
107-
catch (final SecurityException e) {
108-
log.log(Level.FINE, "The calling thread does not have permission to access the system properties:", e);
109-
}
110-
try {
111-
sm.checkPermission(new RuntimePermission("getenv.*")); // environment variables
112-
return true;
113-
}
114-
catch (final SecurityException e) {
115-
log.log(Level.FINE, "Access to the environment variables is not permitted based on the current security policy:", e);
116-
}
117-
try {
118-
sm.checkPermission(new ManagementPermission("monitor")); // jvm args
119-
return true;
120-
}
121-
catch (final SecurityException e) {
122-
log.log(Level.FINE, "Access to the JVM arguments is not permitted based on the current security policy:", e);
123-
}
124-
return false;
98+
return true;
12599
}
126100

127101
/**
Lines changed: 0 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
package io.github.albertus82.jface.sysinfo;
22

3-
import java.lang.management.ManagementPermission;
4-
import java.security.Permission;
5-
import java.util.logging.Level;
63
import java.util.logging.Logger;
74

8-
import org.junit.AfterClass;
95
import org.junit.Assert;
10-
import org.junit.BeforeClass;
116
import org.junit.Test;
127

138
import io.github.albertus82.util.logging.LoggerFactory;
@@ -16,104 +11,9 @@ public class SystemInformationDialogTest {
1611

1712
private static final Logger log = LoggerFactory.getLogger(SystemInformationDialogTest.class);
1813

19-
private static boolean skip = false;
20-
21-
@BeforeClass
22-
public static void beforeAll() {
23-
if (System.getSecurityManager() != null) {
24-
log.log(Level.WARNING, "SecurityManager detected, ignoring test {0}.", SystemInformationDialogTest.class);
25-
skip = true;
26-
}
27-
else {
28-
try {
29-
System.setSecurityManager(new SecurityManager());
30-
}
31-
catch (final UnsupportedOperationException e) {
32-
log.log(Level.WARNING, "SecurityManager deprecated, ignoring test {0}.", SystemInformationDialogTest.class);
33-
skip = true;
34-
}
35-
}
36-
}
37-
38-
@AfterClass
39-
public static void afterAll() {
40-
if (!skip) {
41-
System.setSecurityManager(null);
42-
}
43-
}
44-
4514
@Test
4615
public void testIsAvailable() {
47-
if (skip) {
48-
return;
49-
}
50-
51-
Assert.assertTrue(SystemInformationDialog.isAvailable());
52-
53-
System.setSecurityManager(new SecurityManager() {
54-
@Override
55-
public void checkPropertiesAccess() {
56-
throw new SecurityException("1");
57-
}
58-
59-
@Override
60-
public void checkPermission(final Permission perm) { /* NOOP */ }
61-
});
62-
Assert.assertTrue(SystemInformationDialog.isAvailable());
63-
64-
System.setSecurityManager(new SecurityManager() {
65-
@Override
66-
public void checkPropertiesAccess() { /* NOOP */ }
67-
68-
@Override
69-
public void checkPermission(final Permission perm) {
70-
if (new RuntimePermission("getenv.*").equals(perm)) {
71-
throw new SecurityException("2");
72-
}
73-
}
74-
});
75-
Assert.assertTrue(SystemInformationDialog.isAvailable());
76-
77-
System.setSecurityManager(new SecurityManager() {
78-
@Override
79-
public void checkPropertiesAccess() { /* NOOP */ }
80-
81-
@Override
82-
public void checkPermission(final Permission perm) {
83-
if (new ManagementPermission("monitor").equals(perm)) {
84-
throw new SecurityException("3");
85-
}
86-
}
87-
});
8816
Assert.assertTrue(SystemInformationDialog.isAvailable());
89-
90-
System.setSecurityManager(new SecurityManager() {
91-
@Override
92-
public void checkPropertiesAccess() { /* NOOP */ }
93-
94-
@Override
95-
public void checkPermission(final Permission perm) {
96-
if (new RuntimePermission("getenv.*").equals(perm) || new ManagementPermission("monitor").equals(perm)) {
97-
throw new SecurityException("4");
98-
}
99-
}
100-
});
101-
Assert.assertTrue(SystemInformationDialog.isAvailable());
102-
103-
System.setSecurityManager(new SecurityManager() {
104-
@Override
105-
public void checkPropertiesAccess() {
106-
throw new SecurityException("5");
107-
}
108-
109-
@Override
110-
public void checkPermission(final Permission perm) {
111-
if (new RuntimePermission("getenv.*").equals(perm) || new ManagementPermission("monitor").equals(perm)) {
112-
throw new SecurityException("6");
113-
}
114-
}
115-
});
116-
Assert.assertFalse(SystemInformationDialog.isAvailable());
11717
}
11818

11919
}

0 commit comments

Comments
 (0)