ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r531625 - in /ant/core/trunk: WHATSNEW src/main/org/apache/tools/ant/types/Permissions.java
Date Mon, 23 Apr 2007 21:49:25 GMT
Author: jkf
Date: Mon Apr 23 14:49:24 2007
New Revision: 531625

URL: http://svn.apache.org/viewvc?view=rev&rev=531625
Log:
pr 41766 permissions for AllPermission not working correctly.

Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/src/main/org/apache/tools/ant/types/Permissions.java

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?view=diff&rev=531625&r1=531624&r2=531625
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Mon Apr 23 14:49:24 2007
@@ -6,6 +6,10 @@
 
 Fixed bugs:
 -----------
+* Error in handling of some permissions, most notably the AllPermission on
+  jdk 1.5
+  Bugzilla report 41776
+
 * Replace task summary output incorrect.
   Bugzilla report 41544
 

Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/Permissions.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/Permissions.java?view=diff&rev=531625&r1=531624&r2=531625
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/Permissions.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/Permissions.java Mon Apr 23 14:49:24
2007
@@ -18,6 +18,7 @@
 
 package org.apache.tools.ant.types;
 
+import java.lang.reflect.Constructor;
 import java.security.UnresolvedPermission;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -50,6 +51,9 @@
     private SecurityManager origSm = null;
     private boolean active = false;
     private boolean delegateToOldSM;
+    
+    // Mandatory constructor for permission object.
+    private static final Class[] PARAMS = { String.class, String.class};
 
     /**
      * Create a set of Permissions.  Equivalent to calling
@@ -113,10 +117,10 @@
         for (Iterator i = grantedPermissions.listIterator(); i.hasNext();) {
             Permissions.Permission p = (Permissions.Permission) i.next();
             if (p.getClassName() == null) {
-                throw new BuildException("Granted permission " + p + " does not contain a
class.");
+                throw new BuildException("Granted permission " + p
+                        + " does not contain a class.");
             } else {
-                java.security.Permission perm =
-                    new UnresolvedPermission(p.getClassName(), p.getName(), p.getActions(),
null);
+                java.security.Permission perm = createPermission(p);
                 granted.add(perm);
             }
         }
@@ -142,6 +146,24 @@
         granted.add(new java.util.PropertyPermission("java.vm.version", "read"));
         granted.add(new java.util.PropertyPermission("java.vm.vendor", "read"));
         granted.add(new java.util.PropertyPermission("java.vm.name", "read"));
+    }
+
+    private java.security.Permission createPermission(
+            Permissions.Permission permission) {
+        try {
+            // First add explicitly already resolved permissions will not be
+            // resolved when added as unresolved permission.
+            Class clazz = Class.forName(permission.getClassName());
+            String name = permission.getName();
+            String actions = permission.getActions();
+            Constructor ctr = clazz.getConstructor(PARAMS);
+            return (java.security.Permission) ctr.newInstance(new Object[] {
+                    name, actions });
+        } catch (Exception e) {
+            // Let the UnresolvedPermission handle it.
+            return new UnresolvedPermission(permission.getClassName(),
+                    permission.getName(), permission.getActions(), null);
+        }
     }
 
     /**



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message