Prechádzať zdrojové kódy

SEC-222: Improve hashCode() to use XOR.

Ben Alex 19 rokov pred
rodič
commit
8cff715599

+ 6 - 6
core/src/main/java/org/acegisecurity/providers/AbstractAuthenticationToken.java

@@ -145,28 +145,28 @@ public abstract class AbstractAuthenticationToken implements Authentication {
     }
 
     public int hashCode() {
-        int code = 2305;
+        int code = 31;
 
         if (this.getAuthorities() != null) {
             for (int i = 0; i < this.getAuthorities().length; i++) {
-                code = code * (this.getAuthorities()[i].hashCode() % 7);
+                code ^= this.getAuthorities()[i].hashCode();         
             }
         }
 
         if (this.getPrincipal() != null) {
-            code = code * (this.getPrincipal().hashCode() % 7);
+            code ^= this.getPrincipal().hashCode();         
         }
 
         if (this.getCredentials() != null) {
-            code = code * (this.getCredentials().hashCode() % 7);
+            code ^= this.getCredentials().hashCode();         
         }
 
         if (this.getDetails() != null) {
-            code = code * (this.getDetails().hashCode() % 7);
+            code ^= this.getDetails().hashCode();         
         }
 
         if (this.isAuthenticated()) {
-            code = code * -3;
+            code ^= -37;
         }
 
         return code;