List of usage examples for java.lang SecurityManager checkPackageDefinition
public void checkPackageDefinition(String pkg)
From source file:Main.java
public static void main(String[] args) { System.setProperty("java.security.policy", "file:/C:/java.policy"); SecurityManager sm = new Main(); System.setSecurityManager(sm); sm.checkPackageDefinition("java2s.com"); System.out.println("Allowed!"); }
From source file:com.sshtools.j2ssh.util.DynamicClassLoader.java
private boolean securityAllowsClass(String className) { try {//from w ww . j av a 2 s . co m SecurityManager security = System.getSecurityManager(); if (security == null) { // if there's no security manager then all classes // are allowed to be loaded return true; } int lastDot = className.lastIndexOf('.'); // Check if we are allowed to load the class' package security.checkPackageDefinition((lastDot > -1) ? className.substring(0, lastDot) : ""); // Throws if not allowed return true; } catch (SecurityException e) { return false; } }