소스 검색

Fix equals and hashCode alignment

Fixes gh-4588
Rob Winch 8 년 전
부모
커밋
f3828924ff

+ 12 - 0
acl/src/main/java/org/springframework/security/acls/domain/AccessControlEntryImpl.java

@@ -128,6 +128,18 @@ public class AccessControlEntryImpl implements AccessControlEntry,
 		return true;
 	}
 
+	@Override
+	public int hashCode() {
+		int result = this.acl.hashCode();
+		result = 31 * result + this.permission.hashCode();
+		result = 31 * result + (this.id != null ? this.id.hashCode() : 0);
+		result = 31 * result + this.sid.hashCode();
+		result = 31 * result + (this.auditFailure ? 1 : 0);
+		result = 31 * result + (this.auditSuccess ? 1 : 0);
+		result = 31 * result + (this.granting ? 1 : 0);
+		return result;
+	}
+
 	public Acl getAcl() {
 		return acl;
 	}

+ 16 - 0
acl/src/main/java/org/springframework/security/acls/domain/AclImpl.java

@@ -325,6 +325,22 @@ public class AclImpl implements Acl, MutableAcl, AuditableAcl, OwnershipAcl {
 		return false;
 	}
 
+	@Override
+	public int hashCode() {
+		int result = this.parentAcl != null ? this.parentAcl.hashCode() : 0;
+		result = 31 * result + this.aclAuthorizationStrategy.hashCode();
+		result = 31 * result + (this.permissionGrantingStrategy != null ?
+			this.permissionGrantingStrategy.hashCode() :
+			0);
+		result = 31 * result + (this.aces != null ? this.aces.hashCode() : 0);
+		result = 31 * result + this.objectIdentity.hashCode();
+		result = 31 * result + this.id.hashCode();
+		result = 31 * result + (this.owner != null ? this.owner.hashCode() : 0);
+		result = 31 * result + (this.loadedSids != null ? this.loadedSids.hashCode() : 0);
+		result = 31 * result + (this.entriesInheriting ? 1 : 0);
+		return result;
+	}
+
 	public String toString() {
 		StringBuilder sb = new StringBuilder();
 		sb.append("AclImpl[");

+ 11 - 0
cas/src/main/java/org/springframework/security/cas/authentication/CasAuthenticationToken.java

@@ -144,6 +144,17 @@ public class CasAuthenticationToken extends AbstractAuthenticationToken implemen
 		return false;
 	}
 
+	@Override
+	public int hashCode() {
+		int result = super.hashCode();
+		result = 31 * result + this.credentials.hashCode();
+		result = 31 * result + this.principal.hashCode();
+		result = 31 * result + this.userDetails.hashCode();
+		result = 31 * result + this.keyHash;
+		result = 31 * result + (this.assertion != null ? this.assertion.hashCode() : 0);
+		return result;
+	}
+
 	public Object getCredentials() {
 		return this.credentials;
 	}

+ 7 - 0
core/src/main/java/org/springframework/security/authentication/AnonymousAuthenticationToken.java

@@ -100,6 +100,13 @@ public class AnonymousAuthenticationToken extends AbstractAuthenticationToken im
 		return false;
 	}
 
+	@Override
+	public int hashCode() {
+		int result = super.hashCode();
+		result = 31 * result + this.keyHash;
+		return result;
+	}
+
 	/**
 	 * Always returns an empty <code>String</code>
 	 *

+ 6 - 0
core/src/main/java/org/springframework/security/authentication/RememberMeAuthenticationToken.java

@@ -120,4 +120,10 @@ public class RememberMeAuthenticationToken extends AbstractAuthenticationToken {
 		return false;
 	}
 
+	@Override
+	public int hashCode() {
+		int result = super.hashCode();
+		result = 31 * result + this.keyHash;
+		return result;
+	}
 }

+ 17 - 0
web/src/main/java/org/springframework/security/web/header/Header.java

@@ -60,6 +60,23 @@ public final class Header {
 		return this.headerValues;
 	}
 
+	@Override
+	public boolean equals(Object o) {
+		if (this == o) {
+			return true;
+		}
+		if (o == null || getClass() != o.getClass()) {
+			return false;
+		}
+
+		Header header = (Header) o;
+
+		if (!this.headerName.equals(header.headerName)) {
+			return false;
+		}
+		return this.headerValues.equals(header.headerValues);
+	}
+
 	public int hashCode() {
 		return headerName.hashCode() + headerValues.hashCode();
 	}