Exemplo n.º 1
0
  protected PermissionCollection getPermissions(CodeSource codeSource) {
    PermissionCollection perms;
    try {
      try {
        perms = super.getPermissions(codeSource);
      } catch (SecurityException e) {
        // We lied about our CodeSource and that makes URLClassLoader unhappy.
        perms = new Permissions();
      }

      ProtectionDomain myDomain =
          AccessController.doPrivileged(
              new PrivilegedAction<ProtectionDomain>() {
                public ProtectionDomain run() {
                  return getClass().getProtectionDomain();
                }
              });
      PermissionCollection myPerms = myDomain.getPermissions();
      if (myPerms != null) {
        for (Enumeration<Permission> elements = myPerms.elements(); elements.hasMoreElements(); ) {
          perms.add(elements.nextElement());
        }
      }
    } catch (Throwable e) {
      // We lied about our CodeSource and that makes URLClassLoader unhappy.
      perms = new Permissions();
    }
    perms.setReadOnly();
    return perms;
  }
 protected Class<?> defineClassFromData(
     final File container, final byte[] classData, final String classname) throws IOException {
   this.definePackage(container, classname);
   final ProtectionDomain currentPd = Project.class.getProtectionDomain();
   final String classResource = this.getClassFilename(classname);
   final CodeSource src =
       new CodeSource(
           AntClassLoader.FILE_UTILS.getFileURL(container),
           this.getCertificates(container, classResource));
   final ProtectionDomain classesPd =
       new ProtectionDomain(src, currentPd.getPermissions(), this, currentPd.getPrincipals());
   return this.defineClass(classname, classData, 0, classData.length, classesPd);
 }