If you call the superclass' checkPermission(p) , you do not need to override the class in the first place. Comment on this, then it works.
Superclas raises java.security.AccessController.checkPermission(perm) and seems to throw a java.security.AccessControlException if java.lang.SecurityManager is not called
in my case he says:
Could not load Logmanager "null" java.security.AccessControlException: access denied (java.util.PropertyPermission java.util.logging.manager read)
and etc.
public class SecurityManagerExample { public static void main(String[] args) { System.setSecurityManager(new SecurityManager() { @Override public void checkPermission(Permission p) {
I found a tutorial on how to write a security manager. I also recommend that you go through the Java document and the examples provided by oracle.
UPDATE
Take a look at the description of the method and redefine the functionality that you want to disable. As I found out, you also need to explicitly enable the functionality you want to have.
Here is an example:
public class SecurityManagerExample { public static void main(String[] args) { System.setSecurityManager(new SecurityManager() { @Override public void checkWrite(String file) {
OUTPUT
Exception in thread "main" java.lang.SecurityException: Not allowed to delete test.xml! at main.SecurityManagerExample$1.checkDelete(SecurityManagerExample.java:60) at java.io.File.delete(File.java:902) at main.SecurityManagerExample.main(SecurityManagerExample.java:74)
source share