harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r597319 - in /harmony/enhanced/classlib/branches/java6/modules/security/src: main/java/common/java/security/ test/api/java/org/apache/harmony/security/tests/java/security/
Date Thu, 22 Nov 2007 07:42:09 GMT
Author: pyang
Date: Wed Nov 21 23:42:08 2007
New Revision: 597319

URL: http://svn.apache.org/viewvc?rev=597319&view=rev
Log:
java6 has special handling in 'exitVM.*' permission, fix Harmony's Permission to comply with
RI 6, add some regression test, and some trivial compiler warning fix

Modified:
    harmony/enhanced/classlib/branches/java6/modules/security/src/main/java/common/java/security/BasicPermission.java
    harmony/enhanced/classlib/branches/java6/modules/security/src/main/java/common/java/security/BasicPermissionCollection.java
    harmony/enhanced/classlib/branches/java6/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/BasicPermission2Test.java
    harmony/enhanced/classlib/branches/java6/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/Permissions2Test.java
    harmony/enhanced/classlib/branches/java6/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/PermissionsTest.java

Modified: harmony/enhanced/classlib/branches/java6/modules/security/src/main/java/common/java/security/BasicPermission.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/security/src/main/java/common/java/security/BasicPermission.java?rev=597319&r1=597318&r2=597319&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/security/src/main/java/common/java/security/BasicPermission.java
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/security/src/main/java/common/java/security/BasicPermission.java
Wed Nov 21 23:42:08 2007
@@ -129,7 +129,16 @@
 	 */
     public boolean implies(Permission permission) {
         if (permission != null && permission.getClass() == this.getClass()) {
-            return nameImplies(getName(), permission.getName());
+            String name = getName();
+            String thatName = permission.getName();
+            if (this instanceof RuntimePermission) {
+                if (thatName.equals("exitVM")) {
+                    thatName = "exitVM.*";
+                } else if (name.equals("exitVM")) {
+                    name = "exitVM.*";
+                }
+            }
+            return nameImplies(name, thatName);
         }
         return false;
     }

Modified: harmony/enhanced/classlib/branches/java6/modules/security/src/main/java/common/java/security/BasicPermissionCollection.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/security/src/main/java/common/java/security/BasicPermissionCollection.java?rev=597319&r1=597318&r2=597319&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/security/src/main/java/common/java/security/BasicPermissionCollection.java
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/security/src/main/java/common/java/security/BasicPermissionCollection.java
Wed Nov 21 23:42:08 2007
@@ -182,6 +182,7 @@
      * Reads the object from stream and checks its consistency: all contained
      * permissions must be of the same subclass of BasicPermission.
      */
+    @SuppressWarnings("unchecked")
     private void readObject(java.io.ObjectInputStream in) throws IOException,
         ClassNotFoundException {
         ObjectInputStream.GetField fields = in.readFields();

Modified: harmony/enhanced/classlib/branches/java6/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/BasicPermission2Test.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/BasicPermission2Test.java?rev=597319&r1=597318&r2=597319&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/BasicPermission2Test.java
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/BasicPermission2Test.java
Wed Nov 21 23:42:08 2007
@@ -18,6 +18,7 @@
 package org.apache.harmony.security.tests.java.security;
 
 import java.security.BasicPermission;
+import java.security.Permission;
 import java.security.PermissionCollection;
 
 public class BasicPermission2Test extends junit.framework.TestCase {
@@ -119,4 +120,18 @@
 		assertTrue("Should imply", bpc.implies(bp4));
 		assertTrue("Should not imply", !bpc.implies(bp3));
 	}
+    
+    //Special treat with RuntimePermission exitVM in Java 6, which equals RuntimePermission
exitVM.*
+    public void test_RuntimePermissionExitVM(){
+        Permission permission_exitVM = new RuntimePermission("exitVM");
+        Permission permission_exitVM_ALL = new RuntimePermission("exitVM.*");
+        Permission permission_exitVM_0 = new RuntimePermission("exitVM.0");
+        Permission permission_exitVM_a = new RuntimePermission("exitVM.a");
+        assertTrue(permission_exitVM.implies(permission_exitVM_ALL));
+        assertTrue(permission_exitVM.implies(permission_exitVM_0));
+        assertTrue(permission_exitVM.implies(permission_exitVM_a));
+        assertTrue(permission_exitVM_ALL.implies(permission_exitVM));
+        assertTrue(permission_exitVM_ALL.implies(permission_exitVM_0));
+        assertTrue(permission_exitVM_ALL.implies(permission_exitVM_a));
+    }
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/Permissions2Test.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/Permissions2Test.java?rev=597319&r1=597318&r2=597319&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/Permissions2Test.java
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/Permissions2Test.java
Wed Nov 21 23:42:08 2007
@@ -144,4 +144,16 @@
 				.implies(new FilePermission(s + "tmp" + s + "test" + s
 						+ "test2.file", "write")));
 	}
+    
+    public void test_RuntimePermission_exitVM(){
+        Permissions permissions = new Permissions();
+        permissions.add(new RuntimePermission("exitVM"));
+        assertTrue(permissions.implies(new RuntimePermission("exitVM.*")));
+        assertTrue(permissions.implies(new RuntimePermission("exitVM.0")));
+        
+        permissions = new Permissions();
+        permissions.add(new RuntimePermission("exitVM.*"));
+        assertTrue(permissions.implies(new RuntimePermission("exitVM")));
+        assertTrue(permissions.implies(new RuntimePermission("exitVM.0")));
+    }
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/PermissionsTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/PermissionsTest.java?rev=597319&r1=597318&r2=597319&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/PermissionsTest.java
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/PermissionsTest.java
Wed Nov 21 23:42:08 2007
@@ -146,5 +146,19 @@
     	} catch (NullPointerException e){}
 
     }
+    
+    public void test_toString() {
+        Permissions ps = new Permissions();
+        String address = getAddress(ps.toString());
+        String expectedResult = "java.security.Permissions@" + address
+                + " (\n)\n";
+        assertEquals(expectedResult, ps.toString());
+    }
+
+    private String getAddress(String s) {
+        int startIndex = s.indexOf('@') + 1;
+        int endIndex = s.indexOf(' ');
+        return s.substring(startIndex, endIndex);
+    }
 
  }



Mime
View raw message