You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by le...@apache.org on 2007/10/31 08:17:58 UTC

svn commit: r590576 - in /harmony/enhanced/classlib/branches/java6/modules/auth/src: main/java/common/javax/security/auth/kerberos/ test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/

Author: leoli
Date: Wed Oct 31 00:17:57 2007
New Revision: 590576

URL: http://svn.apache.org/viewvc?rev=590576&view=rev
Log:
Fix a bug in javax.security.auth.kerberos.KerImpl.equals().

Modified:
    harmony/enhanced/classlib/branches/java6/modules/auth/src/main/java/common/javax/security/auth/kerberos/KerberosTicket.java
    harmony/enhanced/classlib/branches/java6/modules/auth/src/main/java/common/javax/security/auth/kerberos/KeyImpl.java
    harmony/enhanced/classlib/branches/java6/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/KerberosTicketTest.java

Modified: harmony/enhanced/classlib/branches/java6/modules/auth/src/main/java/common/javax/security/auth/kerberos/KerberosTicket.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/auth/src/main/java/common/javax/security/auth/kerberos/KerberosTicket.java?rev=590576&r1=590575&r2=590576&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/auth/src/main/java/common/javax/security/auth/kerberos/KerberosTicket.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/auth/src/main/java/common/javax/security/auth/kerberos/KerberosTicket.java Wed Oct 31 00:17:57 2007
@@ -343,10 +343,10 @@
         sb.append("Postdated Ticket = ").append(flags[POSTDATED] + LF); //$NON-NLS-1$
         sb.append("Renewable Ticket = ").append(flags[RENEWABLE] + LF); //$NON-NLS-1$
         sb.append("Initial Ticket = ").append(flags[INITIAL] + LF); //$NON-NLS-1$
-        sb.append("Auth Time = ").append(this.authTime.toString() + LF); //$NON-NLS-1$
-        sb.append("Start Time = ").append(this.startTime.toString() + LF); //$NON-NLS-1$
-        sb.append("End Time = ").append(this.endTime.toString() + LF); //$NON-NLS-1$
-        sb.append("Renew Till = ").append(this.renewTill.toString() + LF); //$NON-NLS-1$
+        sb.append("Auth Time = ").append(this.authTime + LF); //$NON-NLS-1$
+        sb.append("Start Time = ").append(this.startTime + LF); //$NON-NLS-1$
+        sb.append("End Time = ").append(this.endTime + LF); //$NON-NLS-1$
+        sb.append("Renew Till = ").append(this.renewTill + LF); //$NON-NLS-1$
         sb.append("Client Addresses "); //$NON-NLS-1$
         if (clientAddresses != null) {
             for (int i = 0; i < clientAddresses.length; i++) {
@@ -374,6 +374,10 @@
 
     @Override
     public boolean equals(Object other) {
+        if( this == other && !this.isDestroyed()){
+            return true;
+        }
+        
         if ((other instanceof KerberosTicket) && (!this.isDestroyed())) {
             KerberosTicket that = (KerberosTicket) other;
             if ((!that.isDestroyed()) && sessionKey.equals(that.sessionKey)

Modified: harmony/enhanced/classlib/branches/java6/modules/auth/src/main/java/common/javax/security/auth/kerberos/KeyImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/auth/src/main/java/common/javax/security/auth/kerberos/KeyImpl.java?rev=590576&r1=590575&r2=590576&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/auth/src/main/java/common/javax/security/auth/kerberos/KeyImpl.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/auth/src/main/java/common/javax/security/auth/kerberos/KeyImpl.java Wed Oct 31 00:17:57 2007
@@ -319,16 +319,26 @@
     
     @Override
     public boolean equals(Object other) {
-        if (other instanceof KeyImpl && !this.isDestroyed()
-                && !((KeyImpl) other).isDestroyed()) {
-            if ((keyType == ((KeyImpl) other).keyType)
-                    && (keyBytes.length == ((KeyImpl) other).keyBytes.length)) {
+        if (this.isDestroyed()) {
+            return false;
+        }
+        if (this == other) {
+            return true;
+        }
+
+        if (other instanceof KeyImpl) {
+            KeyImpl that = (KeyImpl) other;
+            if (that.isDestroyed()) {
+                return false;
+            }
+            if ((keyType == that.keyType)
+                    && (keyBytes.length == that.keyBytes.length)) {
                 for (int i = 0; i < keyBytes.length; i++) {
-                    if (keyBytes[i] != ((KeyImpl) other).keyBytes[i]) {
+                    if (keyBytes[i] != that.keyBytes[i]) {
                         return false;
                     }
-                    return true;
                 }
+                return true;
             }
         }
         return false;

Modified: harmony/enhanced/classlib/branches/java6/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/KerberosTicketTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/KerberosTicketTest.java?rev=590576&r1=590575&r2=590576&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/KerberosTicketTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/KerberosTicketTest.java Wed Oct 31 00:17:57 2007
@@ -546,6 +546,24 @@
         }
         assertFalse("Destroyed krbTicket sholudn't be equivalent ", krbTicket1
                 .equals(krbTicket2));
+        
+        //Regression test for KerberosTicket.equals().
+        final KerberosPrincipal clientPrincipal = new KerberosPrincipal(
+                "leo@EXAMPLE.COM");
+        final KerberosPrincipal serverPrincipal = new KerberosPrincipal(
+                "krbtgt/EXAMPLE.COM@EXAMPLE.COM");
+        KerberosTicket tgt = new KerberosTicket(new byte[0], clientPrincipal,
+                serverPrincipal, new byte[0], 1, new boolean[0],
+                new Date(1000), null, new Date(new Date().getTime() + 1000),
+                null, null);
+        assertEquals(tgt, tgt);
+        KerberosTicket tgt1 = new KerberosTicket(new byte[0], clientPrincipal,
+                serverPrincipal, new byte[0], 1, new boolean[0],
+                new Date(1000), null, new Date(new Date().getTime() + 1000),
+                null, null);
+        assertEquals(tgt, tgt1);
+        assertEquals(tgt1, tgt);
+        
     }
 
     /**