harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smish...@apache.org
Subject svn commit: r437945 - in /incubator/harmony/enhanced/classlib/trunk/modules/auth/src: main/java/common/javax/security/auth/kerberos/ test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/ test/resources/serialization...
Date Tue, 29 Aug 2006 04:09:05 GMT
Author: smishura
Date: Mon Aug 28 21:09:05 2006
New Revision: 437945

URL: http://svn.apache.org/viewvc?rev=437945&view=rev
Log:
Implement KerberosPrincipal serialization + compatibility test

Added:
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KerberosPrincipalTest.java
  (with props)
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KerberosPrincipalTest.golden.0.ser
  (with props)
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KerberosPrincipalTest.golden.1.ser
  (with props)
Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/kerberos/KerberosPrincipal.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/kerberos/KerberosPrincipal.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/kerberos/KerberosPrincipal.java?rev=437945&r1=437944&r2=437945&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/kerberos/KerberosPrincipal.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/kerberos/KerberosPrincipal.java
Mon Aug 28 21:09:05 2006
@@ -14,9 +14,9 @@
  *  limitations under the License.
  */
 /**
-* @author Maxim V. Makarov, Stepan M. Mishura
-* @version $Revision$
-*/
+ * @author Maxim V. Makarov, Stepan M. Mishura
+ * @version $Revision$
+ */
 
 package javax.security.auth.kerberos;
 
@@ -25,6 +25,10 @@
 import java.io.ObjectOutputStream;
 import java.io.Serializable;
 import java.security.Principal;
+import java.util.StringTokenizer;
+
+import org.apache.harmony.auth.internal.kerberos.v5.PrincipalName;
+import org.apache.harmony.security.asn1.ASN1StringType;
 
 /**
  * @com.intel.drl.spec_ref
@@ -68,29 +72,32 @@
 
     // the full name of principal
     private transient String name;
+
     // the realm
     private transient String realm;
-    // type of the principal 
+
+    // type of the principal
     private transient int type;
 
     // TODO: It is gag.
-    // When KerberosPrincipla will be realize then this method 
+    // When KerberosPrincipla will be realize then this method
     // should be delete or modify
     private void init(String name) {
-        
+
         // FIXME: correctly implement parsing name according to RFC 1964
         // http://www.ietf.org/rfc/rfc1964.txt
-        if (name == null || name.trim().length()==0) {
+        if (name == null || name.trim().length() == 0) {
             throw new IllegalArgumentException("Invalid principal name");
         }
         int pos = name.indexOf('@');
         if (pos != -1) {
             realm = name.substring(pos + 1, name.length());
         } else {
+            // look for local realm name
             throw new UnsupportedOperationException();
         }
         this.name = name;
-        
+
         // verify realm name according to RFC 1964(2.1.1 (2))
         // check invalid chars '/', ':' and null
         if (realm.indexOf('/') != -1 || realm.indexOf(':') != -1
@@ -101,10 +108,10 @@
     }
 
     /**
-     * @com.intel.drl.spec_ref 
+     * @com.intel.drl.spec_ref
      */
     public KerberosPrincipal(String name) {
-        //TODO: If principal name does't specify then a default realm 
+        // TODO: If principal name does't specify then a default realm
         // should be read from krb.conf file else IllegalArgumentException
         // should be throw
         init(name);
@@ -112,14 +119,14 @@
     }
 
     /**
-     * @com.intel.drl.spec_ref 
+     * @com.intel.drl.spec_ref
      */
     public KerberosPrincipal(String name, int type) {
-        //TODO: If principal name does't specify then a default realm 
+        // TODO: If principal name does't specify then a default realm
         // should be read from krb.conf file else IllegalArgumentException
         // should be throw
         init(name);
-        //TODO: it is gag
+        // TODO: it is gag
         if (type < 0 || type > KRB_NT_UID) {
             throw new IllegalArgumentException("Invalid name type");
         }
@@ -167,8 +174,8 @@
             return false;
         }
 
-        KerberosPrincipal that = (KerberosPrincipal)obj;
-        
+        KerberosPrincipal that = (KerberosPrincipal) obj;
+
         return (that.name.equals(this.name) && that.type == this.type);
     }
 
@@ -179,15 +186,61 @@
         return super.toString();
     }
 
-    // TODO: read a object from a stream
     private void readObject(ObjectInputStream s) throws IOException,
-        ClassNotFoundException {
+            ClassNotFoundException {
+
         s.defaultReadObject();
+
+        PrincipalName principalName = (PrincipalName) PrincipalName.ASN1
+                .decode((byte[]) s.readObject());
+        realm = (String) ASN1StringType.GENERALSTRING.decode((byte[]) s
+                .readObject());
+
+        String[] nameString = principalName.getName();
+        StringBuilder buf = new StringBuilder();
+        for (int i = 0; i < (nameString.length - 1); i++) {
+            buf.append(nameString[i]);
+            buf.append('/');
+        }
+        // append last name element
+        buf.append(nameString[nameString.length - 1]);
+
+        // append realm
+        buf.append('@');
+        buf.append(realm);
+
+        name = buf.toString();
+
+        type = principalName.getType();
+
+        //FIXME: verify serialized values
     }
 
-    // TODO: write a object to a stream
     private void writeObject(ObjectOutputStream s) throws IOException {
+
         s.defaultWriteObject();
-    }
 
+        String[] nameString;
+
+        // FIXME: ignores escaped '/','@' chars
+        int pos = name.indexOf('@');
+        String str = name.substring(0, pos);
+        if (name.indexOf('/') == -1) {
+            //there is only one component in principal name
+            nameString = new String[] { str };
+        } else {
+            StringTokenizer strTknzr = new StringTokenizer(str, "/");
+            nameString = new String[strTknzr.countTokens()];
+            for (int i = 0; i < nameString.length; i++) {
+                nameString[i] = strTknzr.nextToken();
+            }
+        }
+
+        byte[] enc = PrincipalName.ASN1.encode(new PrincipalName(type,
+                nameString));
+        s.writeObject(enc);
+
+        enc = ASN1StringType.GENERALSTRING.encode(realm);
+        s.writeObject(enc);
+    }
 }

Added: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KerberosPrincipalTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KerberosPrincipalTest.java?rev=437945&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KerberosPrincipalTest.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KerberosPrincipalTest.java
Mon Aug 28 21:09:05 2006
@@ -0,0 +1,45 @@
+/*
+ *  Copyright 2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.harmony.auth.tests.javax.security.auth.kerberos.serialization;
+
+import javax.security.auth.kerberos.KerberosPrincipal;
+
+import junit.framework.TestCase;
+
+import org.apache.harmony.testframework.serialization.SerializationTest;
+
+public class KerberosPrincipalTest extends TestCase {
+
+    private static final KerberosPrincipal[] data = new KerberosPrincipal[] {
+            new KerberosPrincipal("aaa@somehost.net"),
+            new KerberosPrincipal("aaa/bbb/ccc/ddd/eee@anotherHost.org",
+                    KerberosPrincipal.KRB_NT_SRV_INST) };
+
+    /**
+     * @tests serialization/deserialization compatibility.
+     */
+    public void testSerializationSelf() throws Exception {
+        SerializationTest.verifySelf(data);
+    }
+
+    /**
+     * @tests serialization/deserialization compatibility with RI.
+     */
+    public void testSerializationCompatibility() throws Exception {
+        SerializationTest.verifyGolden(this, data);
+    }
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KerberosPrincipalTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KerberosPrincipalTest.golden.0.ser
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KerberosPrincipalTest.golden.0.ser?rev=437945&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KerberosPrincipalTest.golden.0.ser
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KerberosPrincipalTest.golden.1.ser
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KerberosPrincipalTest.golden.1.ser?rev=437945&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KerberosPrincipalTest.golden.1.ser
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



Mime
View raw message