harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smish...@apache.org
Subject svn commit: r502562 - in /harmony/enhanced/classlib/trunk/modules/auth/src: main/java/common/javax/security/auth/kerberos/ main/java/common/org/apache/harmony/auth/internal/kerberos/v5/ test/java/common/org/apache/harmony/auth/tests/javax/security/auth...
Date Fri, 02 Feb 2007 10:12:05 GMT
Author: smishura
Date: Fri Feb  2 02:12:04 2007
New Revision: 502562

URL: http://svn.apache.org/viewvc?view=rev&rev=502562
Log:
Fix for HARMONY-1182:
[classlib][auth] KerberosPrincipal("file:C://") lead to UnsupportedOperationException on Harmony

Modified:
    harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/kerberos/KerberosPrincipal.java
    harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/kerberos/v5/PrincipalName.java
    harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/KerberosPrincipalTest.java

Modified: harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/kerberos/KerberosPrincipal.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/kerberos/KerberosPrincipal.java?view=diff&rev=502562&r1=502561&r2=502562
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/kerberos/KerberosPrincipal.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/kerberos/KerberosPrincipal.java
Fri Feb  2 02:12:04 2007
@@ -22,7 +22,6 @@
 import java.io.ObjectOutputStream;
 import java.io.Serializable;
 import java.security.Principal;
-import java.util.StringTokenizer;
 
 import org.apache.harmony.auth.internal.kerberos.v5.KerberosException;
 import org.apache.harmony.auth.internal.kerberos.v5.KrbClient;
@@ -47,15 +46,15 @@
     public static final int KRB_NT_UID = 5;
 
     // the full name of principal
-    private transient String name;
+    private transient PrincipalName name;
 
     // the realm
     private transient String realm;
 
-    // type of the principal
-    private transient int type;
+    // "principal" @ "realm"
+    private transient String strName;
 
-    private void init(String name) {
+    private void init(int type, String name) {
 
         // FIXME: correctly implement parsing name according to RFC 1964
         // http://www.ietf.org/rfc/rfc1964.txt
@@ -75,7 +74,7 @@
                         .getString("auth.24")); //$NON-NLS-1$
             }
 
-            this.name = name;
+            name = name.substring(0, pos);
         } else {
             // look for default realm name
             try {
@@ -83,30 +82,30 @@
             } catch (KerberosException e) {
                 throw new IllegalArgumentException(e);
             }
-
-            if (realm != null) {
-                this.name = name + '@' + realm;
-            } else {
-                this.name = name;
-            }
         }
+        this.name = new PrincipalName(type, name);
     }
 
     public KerberosPrincipal(String name) {
-        init(name);
-        type = KRB_NT_PRINCIPAL;
+        init(KRB_NT_PRINCIPAL, name);
     }
 
     public KerberosPrincipal(String name, int type) {
-        init(name);
+        init(type, name);
         if (type < 0 || type > KRB_NT_UID) {
             throw new IllegalArgumentException(Messages.getString("auth.25")); //$NON-NLS-1$
         }
-        this.type = type;
     }
 
     public String getName() {
-        return name;
+        if (strName == null) {
+            if (realm == null) {
+                strName = name.getCanonicalName();
+            } else {
+                strName = name.getCanonicalName() + '@' + realm;
+            }
+        }
+        return strName;
     }
 
     public String getRealm() {
@@ -114,7 +113,7 @@
     }
 
     public int getNameType() {
-        return type;
+        return name.getType();
     }
 
     @Override
@@ -133,38 +132,27 @@
 
         KerberosPrincipal that = (KerberosPrincipal) obj;
 
-        return (that.name.equals(this.name) && that.type == this.type);
+        if (realm == null) {
+            return that.realm == null;
+        } else if (!realm.equals(that.realm)) {
+            return false;
+        }
+        return name.equals(that.name);
     }
 
     @Override
     public String toString() {
-        return name;
+        return getName();
     }
 
-    private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException
{
+    private void readObject(ObjectInputStream s) throws IOException,
+            ClassNotFoundException {
 
         s.defaultReadObject();
 
-        PrincipalName principalName = PrincipalName.instanceOf((byte[]) s
+        name = PrincipalName.instanceOf((byte[]) s.readObject());
+        realm = (String) ASN1StringType.GENERALSTRING.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
     }
@@ -173,23 +161,7 @@
 
         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, "/"); //$NON-NLS-1$
-            nameString = new String[strTknzr.countTokens()];
-            for (int i = 0; i < nameString.length; i++) {
-                nameString[i] = strTknzr.nextToken();
-            }
-        }
-
-        s.writeObject(new PrincipalName(type, nameString).getEncoded());
+        s.writeObject(name.getEncoded());
         s.writeObject(ASN1StringType.GENERALSTRING.encode(realm));
     }
 }

Modified: harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/kerberos/v5/PrincipalName.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/kerberos/v5/PrincipalName.java?view=diff&rev=502562&r1=502561&r2=502562
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/kerberos/v5/PrincipalName.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/kerberos/v5/PrincipalName.java
Fri Feb  2 02:12:04 2007
@@ -21,6 +21,7 @@
 import java.math.BigInteger;
 import java.util.Arrays;
 import java.util.List;
+import java.util.StringTokenizer;
 
 import org.apache.harmony.security.asn1.ASN1Explicit;
 import org.apache.harmony.security.asn1.ASN1Integer;
@@ -64,12 +65,40 @@
         this.name = name;
     }
 
+    public PrincipalName(int type, String str) {
+        this.type = type;
+        
+        // FIXME: ignores escaped '/','@' chars
+        if (str.indexOf('/') == -1) {
+            //there is only one component in principal name
+            name = new String[] { str };
+        } else {
+            StringTokenizer strTknzr = new StringTokenizer(str, "/"); //$NON-NLS-1$
+            name = new String[strTknzr.countTokens()];
+            for (int i = 0; i < name.length; i++) {
+                name[i] = strTknzr.nextToken();
+            }
+        }
+    }
+
     public int getType() {
         return type;
     }
 
     public String[] getName() {
         return name;
+    }
+
+    public String getCanonicalName() {
+        StringBuilder buf = new StringBuilder();
+        for (int i = 0; i < (name.length - 1); i++) {
+            buf.append(name[i]);
+            buf.append('/');
+        }
+        // append last name element
+        buf.append(name[name.length - 1]);
+
+        return buf.toString();
     }
 
     public byte[] getEncoded() {

Modified: harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/KerberosPrincipalTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/KerberosPrincipalTest.java?view=diff&rev=502562&r1=502561&r2=502562
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/KerberosPrincipalTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/KerberosPrincipalTest.java
Fri Feb  2 02:12:04 2007
@@ -77,6 +77,10 @@
         assertEquals("apache.org", principal.getRealm());
         assertEquals(KerberosPrincipal.KRB_NT_PRINCIPAL, principal
                 .getNameType());
+        
+        // Regression for HARMONY-1182
+        principal = new KerberosPrincipal("file:C://@apache.org");
+        assertEquals("file:C:@apache.org", principal.getName());
     }
 
     /**
@@ -264,8 +268,17 @@
      * @tests javax.security.auth.kerberos.KerberosPrincipal#equals(Object)
      */
     public void test_equals() {
+
+        KerberosPrincipal p = new KerberosPrincipal("A@B");
+
+        assertTrue(p.equals(new KerberosPrincipal("A@B")));
+        assertFalse(p.equals(new KerberosPrincipal("A@B.org")));
+        assertFalse(p.equals(new KerberosPrincipal("aaa@B")));
+        assertFalse(p.equals(new KerberosPrincipal("A@B",
+                KerberosPrincipal.KRB_NT_UID)));
+
         // Regression for HARMONY-744
-        assertFalse(new KerberosPrincipal("A@B").equals(null));
-        assertFalse(new KerberosPrincipal("A@B").equals(new Object()));
+        assertFalse(p.equals(null));
+        assertFalse(p.equals(new Object()));
     }
 }



Mime
View raw message