diff --git a/core/src/main/java/org/springframework/security/core/userdetails/User.java b/core/src/main/java/org/springframework/security/core/userdetails/User.java index 141f65dde8..5d164bea76 100644 --- a/core/src/main/java/org/springframework/security/core/userdetails/User.java +++ b/core/src/main/java/org/springframework/security/core/userdetails/User.java @@ -179,8 +179,8 @@ public class User implements UserDetails, CredentialsContainer { */ @Override public boolean equals(Object obj) { - if (obj instanceof User) { - return this.username.equals(((User) obj).username); + if (obj instanceof User user) { + return this.username.equals(user.getUsername()); } return false; }