-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Fixed ClientAuthenticationMethod inconsistent equals and hashCode #10559
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @jlaci. Please see review comment.
Also, please add a test.
} | ||
ClientAuthenticationMethod that = (ClientAuthenticationMethod) obj; | ||
return this.getValue().equalsIgnoreCase(that.getValue()); | ||
return this.getValue().toLowerCase(Locale.ROOT).equals(that.getValue().toLowerCase(Locale.ROOT)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove toLowerCase()
and use equals()
for exact matching.
In that case, I would also have to change the hashCode from But be aware, that this would also change the current behaviour of the I think that the original intention here, was to ignore the case for comparison, and the hashCode was simply buggy. Nevertheless if you say that case should matter, then I'll update both methods. |
Thanks for pointing that out @jlaci, as you're right this could potentially break existing applications. Nevertheless, case does matter as the standard client authn methods should be compared using exact matching. I'm thinking we might push this to |
Okay, I've updated the PR as requested. 6.0 is not a problem for me, I already have a workaround in place where I've encountered this bug, I just wanted to spare others from bashing their heads :) Please feel free to comment if you need anything else changed. |
Thanks @jlaci ! Can you please add a test in |
Thanks for the updates @jlaci and apologies for the delay. This is now in |
In
org.springframework.security.oauth2.core.ClientAuthenticationMethod
the equals method was comparing the value usingequalsIgnoreCase
, however thehashCode
was returning the original string'shashCode
. This meant that if the value was only differing in the case,equals
would return true, but thehashCode
wouldn't match, causing all sorts of problems, such as in a Collection callingcontains
returning false. E.g.:I fixed the issue by calling an explicit toLowerCase() in both cases.