harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r565626 - 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/
Date Tue, 14 Aug 2007 05:25:26 GMT
Author: leoli
Date: Mon Aug 13 22:25:26 2007
New Revision: 565626

URL: http://svn.apache.org/viewvc?view=rev&rev=565626
Log:
Add Java 6 new feature in auth module (javax.security.auth.kerberos.KerberosKey and javax.security.auth.kerberos.KerberosTicket.equals
and hashCode()).

Modified:
    harmony/enhanced/classlib/branches/java6/modules/auth/src/main/java/common/javax/security/auth/kerberos/KerberosKey.java
    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/KerberosKeyTest.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/KerberosKey.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/auth/src/main/java/common/javax/security/auth/kerberos/KerberosKey.java?view=diff&rev=565626&r1=565625&r2=565626
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/auth/src/main/java/common/javax/security/auth/kerberos/KerberosKey.java
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/auth/src/main/java/common/javax/security/auth/kerberos/KerberosKey.java
Mon Aug 13 22:25:26 2007
@@ -117,4 +117,32 @@
             throw new IllegalStateException(Messages.getString("auth.48")); //$NON-NLS-1$
         }
     }
+    
+    @Override
+    public boolean equals(Object other) {
+        if ((other instanceof KerberosKey) && (!this.isDestroyed())) {
+            KerberosKey that = (KerberosKey) other;
+            if ((!that.isDestroyed()) && (versionNum == that.versionNum)) {
+                if (key.equals(((KerberosKey) other).key)) {
+                    if (principal != null) {
+                        return principal.equals(that.principal);
+                    } else {
+                        return that.principal == null;
+                    }
+                }
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public int hashCode() {
+        int hashcode = 0;
+        if (principal != null) {
+            hashcode += principal.hashCode();
+        }
+        hashcode += versionNum;
+        hashcode += key.hashCode();
+        return hashcode;
+    }
 }

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?view=diff&rev=565626&r1=565625&r2=565626
==============================================================================
--- 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
Mon Aug 13 22:25:26 2007
@@ -371,4 +371,73 @@
             throw new IllegalStateException(Messages.getString("auth.43")); //$NON-NLS-1$
         }
     }
+
+    @Override
+    public boolean equals(Object other) {
+        if ((other instanceof KerberosTicket) && (!this.isDestroyed())) {
+            KerberosTicket that = (KerberosTicket) other;
+            if ((!that.isDestroyed()) && sessionKey.equals(that.sessionKey)
+                    && (authTime.equals(that.authTime))
+                    && (endTime.equals(that.endTime))
+                    && (startTime.equals(that.startTime))
+                    && (client.equals(that.client))
+                    && (server.equals(that.server))
+                    && (asn1Encoding.length == that.asn1Encoding.length)
+                    && (flags.length == that.flags.length)) {
+                for (int i = 0; i < asn1Encoding.length; i++) {
+                    if (asn1Encoding[i] != that.asn1Encoding[i]) {
+                        return false;
+                    }
+                }
+                for (int i = 0; i < flags.length; i++) {
+                    if (flags[i] != that.flags[i]) {
+                        return false;
+                    }
+                }
+                if (((renewTill != null) && (renewTill.equals(that.renewTill)))
+                        || ((renewTill == null) && that.renewTill == null)) {
+                    if ((clientAddresses != null)
+                            && (that.clientAddresses != null)) {
+                        for (int i = 0; i < clientAddresses.length; i++) {
+                            if ((clientAddresses[i] == null && that.clientAddresses[i]
!= null)
+                                    || (clientAddresses[i] != null && !clientAddresses[i]
+                                            .equals(that.clientAddresses[i]))) {
+                                return false;
+                            }
+                        }
+                        return true;
+                    } else if ((clientAddresses == null)
+                            && (that.clientAddresses == null)) {
+                        return true;
+                    }
+                }
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public int hashCode() {
+        int hashcode = 0;
+        for (int i = 0; i < asn1Encoding.length; i++) {
+            hashcode += asn1Encoding[i];
+        }
+        hashcode += sessionKey.hashCode();
+        for (int i = 0; i < flags.length; i++) {
+            hashcode += (flags[i] ? 1 : 0);
+        }
+        hashcode += authTime.hashCode();
+        hashcode += startTime.hashCode();
+        hashcode += endTime.hashCode();
+        hashcode += (renewTill != null ? renewTill.hashCode() : 0);
+        hashcode += client.hashCode();
+        hashcode += server.hashCode();
+        if (clientAddresses != null) {
+            for (int i = 0; i < clientAddresses.length; i++) {
+                hashcode += (clientAddresses[i] != null ? clientAddresses[i]
+                        .hashCode() : 0);
+            }
+        }
+        return hashcode;
+    }
 }

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?view=diff&rev=565626&r1=565625&r2=565626
==============================================================================
--- 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
Mon Aug 13 22:25:26 2007
@@ -316,4 +316,31 @@
                 keyBytes));
         s.writeObject(enc);
     }
+    
+    @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)) {
+                for (int i = 0; i < keyBytes.length; i++) {
+                    if (keyBytes[i] != ((KeyImpl) other).keyBytes[i]) {
+                        return false;
+                    }
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public int hashCode() {
+        int hashcode = 0;
+        for (int i = 0; i < keyBytes.length; i++) {
+            hashcode += keyBytes[i];
+        }
+        hashcode *= keyType;
+        return hashcode;
+    }
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/KerberosKeyTest.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/KerberosKeyTest.java?view=diff&rev=565626&r1=565625&r2=565626
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/KerberosKeyTest.java
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/KerberosKeyTest.java
Mon Aug 13 22:25:26 2007
@@ -22,6 +22,7 @@
 import java.io.ObjectOutputStream;
 import java.util.Arrays;
 
+import javax.security.auth.DestroyFailedException;
 import javax.security.auth.kerberos.KerberosKey;
 import javax.security.auth.kerberos.KerberosPrincipal;
 
@@ -224,5 +225,38 @@
             fail("No expected IllegalStateException");
         } catch (IllegalStateException e) {
         }
+    }
+    
+    /**
+     * @tests javax.security.auth.kerberos.KerberosKey#equals(java.lang.Object)
+     */
+    public void test_equals() {
+        KerberosKey kerberosKey1 = new KerberosKey(principal, keyBytes, 1, 123);
+        KerberosKey kerberosKey2 = new KerberosKey(principal, keyBytes, 1, 123);
+        KerberosKey kerberosKey3 = new KerberosKey(principal, new byte[] { 1,
+                3, 4, 5 }, 1, 123);
+        assertEquals("kerberosKey1 and kerberosKey2 should be equivalent ",
+                kerberosKey1, kerberosKey2);
+        assertFalse("kerberosKey1 and kerberosKey3 sholudn't be equivalent ",
+                kerberosKey1.equals(kerberosKey3));
+        try {
+            kerberosKey2.destroy();
+        } catch (DestroyFailedException e) {
+            fail("kerberosKey2 destroy failed");
+        }
+        assertFalse("Destroyed kerberosKey sholudn't be equivalent ",
+                kerberosKey1.equals(kerberosKey2));
+    }
+
+    /**
+     * @tests javax.security.auth.kerberos.KerberosKey#hashCode()
+     */
+    public void test_hashCode() {
+        KerberosKey kerberosKey1 = new KerberosKey(principal, keyBytes, 1, 123);
+        KerberosKey kerberosKey2 = new KerberosKey(principal, keyBytes, 1, 123);
+        assertEquals("kerberosKey1 and kerberosKey2 should be equivalent ",
+                kerberosKey1, kerberosKey2);
+        assertEquals("hashCode should be equivalent", kerberosKey1.hashCode(),
+                kerberosKey2.hashCode());
     }
 }

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?view=diff&rev=565626&r1=565625&r2=565626
==============================================================================
--- 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
Mon Aug 13 22:25:26 2007
@@ -23,6 +23,7 @@
 import java.util.Date;
 
 import javax.crypto.SecretKey;
+import javax.security.auth.DestroyFailedException;
 import javax.security.auth.RefreshFailedException;
 import javax.security.auth.kerberos.KerberosKey;
 import javax.security.auth.kerberos.KerberosPrincipal;
@@ -519,6 +520,48 @@
         }
 
         // TODO test: ticket refreshing 
+    }
+    
+    /**
+     * @tests javax.security.auth.kerberos.KerberosTicket#equals(java.lang.Object)
+     */
+    public void test_equals() throws Exception {
+        KerberosTicket krbTicket1 = new KerberosTicket(ticket, pClient,
+                pServer, sessionKey, KEY_TYPE, flags, authTime, startTime,
+                endTime, renewTill, addesses);
+        KerberosTicket krbTicket2 = new KerberosTicket(ticket, pClient,
+                pServer, sessionKey, KEY_TYPE, flags, authTime, startTime,
+                endTime, renewTill, addesses);
+        KerberosTicket krbTicket3 = new KerberosTicket(ticket, pClient,
+                pServer, sessionKey, KEY_TYPE, new boolean[] { true, false },
+                authTime, startTime, endTime, renewTill, addesses);
+        assertEquals("krbTicket1 and krbTicket2 should be equivalent ",
+                krbTicket1, krbTicket2);
+        assertFalse("krbTicket1 and krbTicket3 sholudn't be equivalent ",
+                krbTicket1.equals(krbTicket3));
+        try {
+            krbTicket2.destroy();
+        } catch (DestroyFailedException e) {
+            fail("krbTicket2 destroy failed");
+        }
+        assertFalse("Destroyed krbTicket sholudn't be equivalent ", krbTicket1
+                .equals(krbTicket2));
+    }
+
+    /**
+     * @tests javax.security.auth.kerberos.KerberosTicket#hashCode()
+     */
+    public void test_hashCode() {
+        KerberosTicket krbTicket1 = new KerberosTicket(ticket, pClient,
+                pServer, sessionKey, KEY_TYPE, flags, authTime, startTime,
+                endTime, renewTill, addesses);
+        KerberosTicket krbTicket2 = new KerberosTicket(ticket, pClient,
+                pServer, sessionKey, KEY_TYPE, flags, authTime, startTime,
+                endTime, renewTill, addesses);
+        assertEquals("krbTicket1 and krbTicket2 should be equivalent",
+                krbTicket1, krbTicket2);
+        assertEquals("hashCode should be equivalent", krbTicket1.hashCode(),
+                krbTicket2.hashCode());
     }
 
     // Hands-created ticket encoding:



Mime
View raw message