harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r548611 - in /harmony/enhanced/classlib/trunk/modules/security/src: main/java/common/java/security/ test/api/java/org/apache/harmony/security/tests/java/security/ test/resources/serialization/org/apache/harmony/security/tests/java/security/
Date Tue, 19 Jun 2007 06:38:52 GMT
Author: leoli
Date: Mon Jun 18 23:38:51 2007
New Revision: 548611

URL: http://svn.apache.org/viewvc?view=rev&rev=548611
Log:
Fix bugs for java.security.UnresolvedPermission is not serialization compatible with RI.

Added:
    harmony/enhanced/classlib/trunk/modules/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/UnresolvedPermissionTest.golden.ser
  (with props)
Modified:
    harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security/UnresolvedPermission.java
    harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/UnresolvedPermissionTest.java

Modified: harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security/UnresolvedPermission.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security/UnresolvedPermission.java?view=diff&rev=548611&r1=548610&r2=548611
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security/UnresolvedPermission.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security/UnresolvedPermission.java
Mon Jun 18 23:38:51 2007
@@ -57,16 +57,12 @@
      */
     private static final long serialVersionUID = -4821973115467008846L;
 
-    private static final ObjectStreamField serialPersistentFields[] = {
-        new ObjectStreamField("type", String.class), //$NON-NLS-1$
-        new ObjectStreamField("name", String.class), //$NON-NLS-1$
-        new ObjectStreamField("actions", String.class), }; //$NON-NLS-1$
 
-    // Target name
-    private transient String targetName;
-
-    //Target actions
-    private transient String targetActions;
+    private String type;    
+    
+    private String name;
+    
+    private String actions;
 
     // The signer certificates 
     private transient Certificate[] targetCerts;
@@ -89,8 +85,9 @@
                                 Certificate[] certs) {
         super(type);
         checkType(type);
-        targetName = name;
-        targetActions = actions;
+        this.type = type;
+        this.name = name;
+        this.actions = actions;
         if (certs != null && certs.length != 0) {
             //TODO filter non-signer certificates ???
             List tmp = new ArrayList();
@@ -142,10 +139,10 @@
         if (obj instanceof UnresolvedPermission) {
             UnresolvedPermission that = (UnresolvedPermission)obj;
             if (getName().equals(that.getName())
-                && (targetName == null ? that.targetName == null 
-                    : targetName.equals(that.targetName))
-                && (targetActions == null ? that.targetActions == null
-                    : targetActions.equals(that.targetActions))
+                && (name == null ? that.name == null 
+                    : name.equals(that.name))
+                && (actions == null ? that.actions == null
+                    : actions.equals(that.actions))
                 && (PolicyUtils.matchSubset(targetCerts, that.targetCerts) 
                     && PolicyUtils.matchSubset(that.targetCerts, targetCerts))) {
                 return true;
@@ -166,11 +163,11 @@
     public int hashCode() {
         if (hash == 0) {
             hash = getName().hashCode();
-            if (targetName != null) {
-                hash ^= targetName.hashCode();
+            if (name != null) {
+                hash ^= name.hashCode();
             }
-            if (targetActions != null) {
-                hash ^= targetActions.hashCode();
+            if (actions != null) {
+                hash ^= actions.hashCode();
             }
         }
         return hash;
@@ -190,14 +187,14 @@
      * @com.intel.drl.spec_ref 
      */
     public String getUnresolvedName() {
-        return targetName;
+        return name;
     }
 
     /** 
      * @com.intel.drl.spec_ref 
      */
     public String getUnresolvedActions() {
-        return targetActions;
+        return actions;
     }
 
     /** 
@@ -244,8 +241,8 @@
 	 * @return a printable representation for the receiver.
 	 */
     public String toString() {
-        return "(unresolved " + getName() + " " + targetName + " " //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$
-            + targetActions + ")"; //$NON-NLS-1$
+        return "(unresolved " + type + " " + name + " " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+            + actions + ")"; //$NON-NLS-1$
     }
 
 	/**
@@ -281,8 +278,8 @@
         if (PolicyUtils.matchSubset(targetCerts, targetType.getSigners())) {
             try {
                 return PolicyUtils.instantiatePermission(targetType,
-                                                         targetName,
-                                                         targetActions);
+                                                         name,
+                                                         actions);
             } catch (Exception ignore) {
                 //TODO log warning?
             }
@@ -311,11 +308,7 @@
      *  @see  <a href="http://java.sun.com/j2se/1.5.0/docs/api/serialized-form.html#java.security.UnresolvedPermission">Java
Spec</a>
      */
     private void writeObject(ObjectOutputStream out) throws IOException {
-        ObjectOutputStream.PutField fields = out.putFields();
-        fields.put("type", getUnresolvedType()); //$NON-NLS-1$
-        fields.put("name", getUnresolvedName()); //$NON-NLS-1$
-        fields.put("actions", getUnresolvedActions()); //$NON-NLS-1$
-        out.writeFields();
+        out.defaultWriteObject();
         if (targetCerts == null) {
             out.writeInt(0);
         } else {
@@ -342,13 +335,8 @@
      */
     private void readObject(ObjectInputStream in) throws IOException,
         ClassNotFoundException {
-        checkType(getUnresolvedType());
-        ObjectInputStream.GetField fields = in.readFields();
-        if (!getUnresolvedType().equals(fields.get("type", null))) { //$NON-NLS-1$
-            throw new InvalidObjectException(Messages.getString("security.31")); //$NON-NLS-1$
-        }
-        targetName = (String)fields.get("name", null); //$NON-NLS-1$
-        targetActions = (String)fields.get("actions", null); //$NON-NLS-1$
+        in.defaultReadObject();        
+        checkType(getUnresolvedType());      
         int certNumber = in.readInt();
         if (certNumber != 0) {
             targetCerts = new Certificate[certNumber];

Modified: harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/UnresolvedPermissionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/UnresolvedPermissionTest.java?view=diff&rev=548611&r1=548610&r2=548611
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/UnresolvedPermissionTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/UnresolvedPermissionTest.java
Mon Jun 18 23:38:51 2007
@@ -17,10 +17,16 @@
 
 package org.apache.harmony.security.tests.java.security;
 
+import java.io.Serializable;
 import java.security.AllPermission;
 import java.security.SecurityPermission;
 import java.security.UnresolvedPermission;
 
+import org.apache.harmony.testframework.serialization.SerializationTest;
+import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert;
+
+import tests.util.SerializationTester;
+
 import junit.framework.TestCase;
 
 /**
@@ -74,5 +80,42 @@
         assertFalse(up.implies(up));
         assertFalse(up.implies(new AllPermission()));
         assertFalse(up.implies(new SecurityPermission("a.b.c")));
+    }
+    
+    public void testSerialization() throws Exception {
+        UnresolvedPermission up = new UnresolvedPermission(
+                "java.security.SecurityPermission", "a.b.c", "actions", null);
+        assertEquals("java.security.SecurityPermission", up.getUnresolvedType());
+        assertEquals("a.b.c", up.getUnresolvedName());
+        assertEquals("actions", up.getUnresolvedActions());
+        assertNull(up.getUnresolvedCerts());
+
+        UnresolvedPermission deserializedUp = (UnresolvedPermission) SerializationTester
+                .getDeserilizedObject(up);
+        assertEquals("java.security.SecurityPermission", deserializedUp
+                .getUnresolvedType());
+        assertEquals("a.b.c", deserializedUp.getUnresolvedName());
+        assertEquals("actions", deserializedUp.getUnresolvedActions());
+        assertNull(deserializedUp.getUnresolvedCerts());
+    }
+    
+    public void testSerialization_Compatibility() throws Exception {
+        UnresolvedPermission up = new UnresolvedPermission(
+                "java.security.SecurityPermission", "a.b.c", "actions", null);
+        assertEquals("java.security.SecurityPermission", up.getUnresolvedType());
+        assertEquals("a.b.c", up.getUnresolvedName());
+        assertEquals("actions", up.getUnresolvedActions());
+        assertNull(up.getUnresolvedCerts());
+
+        SerializationTest.verifyGolden(this, up, new SerializableAssert() {
+            public void assertDeserialized(Serializable orig, Serializable ser) {
+                UnresolvedPermission deserializedUp = (UnresolvedPermission) ser;
+                assertEquals("java.security.SecurityPermission", deserializedUp
+                        .getUnresolvedType());
+                assertEquals("a.b.c", deserializedUp.getUnresolvedName());
+                assertEquals("actions", deserializedUp.getUnresolvedActions());
+                assertNull(deserializedUp.getUnresolvedCerts());
+            }
+        });
     }
 }

Added: harmony/enhanced/classlib/trunk/modules/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/UnresolvedPermissionTest.golden.ser
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/UnresolvedPermissionTest.golden.ser?view=auto&rev=548611
==============================================================================
Binary file - no diff available.

Propchange: harmony/enhanced/classlib/trunk/modules/security/src/test/resources/serialization/org/apache/harmony/security/tests/java/security/UnresolvedPermissionTest.golden.ser
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



Mime
View raw message