Skip to content

Commit 2a487ae

Browse files
committed
Updated hashcode and equals
Closes gh-4133
1 parent e071c28 commit 2a487ae

File tree

1 file changed

+13
-38
lines changed

1 file changed

+13
-38
lines changed

Diff for: web/src/main/java/org/springframework/security/web/authentication/WebAuthenticationDetails.java

+13-38
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.security.web.authentication;
1818

1919
import java.io.Serializable;
20+
import java.util.Objects;
2021

2122
import jakarta.servlet.http.HttpServletRequest;
2223
import jakarta.servlet.http.HttpSession;
@@ -62,37 +63,6 @@ private static String extractSessionId(HttpServletRequest request) {
6263
return (session != null) ? session.getId() : null;
6364
}
6465

65-
@Override
66-
public boolean equals(Object obj) {
67-
if (obj instanceof WebAuthenticationDetails) {
68-
WebAuthenticationDetails other = (WebAuthenticationDetails) obj;
69-
if ((this.remoteAddress == null) && (other.getRemoteAddress() != null)) {
70-
return false;
71-
}
72-
if ((this.remoteAddress != null) && (other.getRemoteAddress() == null)) {
73-
return false;
74-
}
75-
if (this.remoteAddress != null) {
76-
if (!this.remoteAddress.equals(other.getRemoteAddress())) {
77-
return false;
78-
}
79-
}
80-
if ((this.sessionId == null) && (other.getSessionId() != null)) {
81-
return false;
82-
}
83-
if ((this.sessionId != null) && (other.getSessionId() == null)) {
84-
return false;
85-
}
86-
if (this.sessionId != null) {
87-
if (!this.sessionId.equals(other.getSessionId())) {
88-
return false;
89-
}
90-
}
91-
return true;
92-
}
93-
return false;
94-
}
95-
9666
/**
9767
* Indicates the TCP/IP address the authentication request was received from.
9868
* @return the address
@@ -111,15 +81,20 @@ public String getSessionId() {
11181
}
11282

11383
@Override
114-
public int hashCode() {
115-
int code = 7654;
116-
if (this.remoteAddress != null) {
117-
code = code * (this.remoteAddress.hashCode() % 7);
84+
public boolean equals(Object o) {
85+
if (this == o) {
86+
return true;
11887
}
119-
if (this.sessionId != null) {
120-
code = code * (this.sessionId.hashCode() % 7);
88+
if (o == null || getClass() != o.getClass()) {
89+
return false;
12190
}
122-
return code;
91+
WebAuthenticationDetails that = (WebAuthenticationDetails) o;
92+
return Objects.equals(this.remoteAddress, that.remoteAddress) && Objects.equals(this.sessionId, that.sessionId);
93+
}
94+
95+
@Override
96+
public int hashCode() {
97+
return Objects.hash(this.remoteAddress, this.sessionId);
12398
}
12499

125100
@Override

0 commit comments

Comments
 (0)