Listing All Permissions Granted to Classes Loaded from a URL or Directory : SecurityManager « Security « Java






Listing All Permissions Granted to Classes Loaded from a URL or Directory

   

import java.io.File;
import java.net.URL;
import java.security.CodeSource;
import java.security.Permission;
import java.security.PermissionCollection;
import java.security.Policy;
import java.security.cert.Certificate;
import java.util.Enumeration;

public class Main {
  public static void main(String[] argv) throws Exception {

    SecurityManager sm = new SecurityManager();
    System.setSecurityManager(sm);
    URL codebase = new URL("http://java.sun.com/");

    codebase = new File("c:\\java\\").toURI().toURL();
    codebase = new File(System.getProperty("user.home")).toURI().toURL();

    CodeSource cs = new CodeSource(codebase, (Certificate[])null);

    PermissionCollection pcoll = Policy.getPolicy().getPermissions(cs);

    Enumeration e = pcoll.elements();
    for (; e.hasMoreElements();) {
      Permission p = (Permission) e.nextElement();
    }
  }
}

   
    
    
  








Related examples in the same category

1.Use SecurityManager to check AWT permission and file permission
2.extends SecurityManager
3.Security Manager TestSecurity Manager Test
4.Enabling the Security Manager
5.The security manager can be installed from the command line:
6.Security Support