-
Notifications
You must be signed in to change notification settings - Fork 4k
Preserve user authentication details on re-authentication #823
Preserve user authentication details on re-authentication #823
Conversation
I have signed the contributors agreement. |
Looks like your change will fix my problem as well. I hope it will get accepted. If it does, I'll retest my specific use case and will reject my PR if it is no longer needed. |
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 @klieber. If you're still looking to get this merged, please see my review comment and apply the change and we'll get this merged.
* @param authentication The authentication | ||
* @return The re-authenticated authentication. | ||
*/ | ||
protected OAuth2Authentication reauthenticateUserAuthentication(OAuth2Authentication authentication) { |
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 reauthenticateUserAuthentication()
and createUserPreAuthenticatedToken()
as it's not needed. The only change required is to setDetails()
on the PreAuthenticatedAuthenticationToken
before it's passed to AuthenticationManager
.
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 @klieber. If you're still looking to get this merged, please see my review comment and apply the change and we'll get this merged.
Sure I will take a look.
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.
@jgrandja I've made the changes requested. Let me know if there is anything else needed.
During a token refresh in the `DefaultTokenServices` the user authentication will be re-authenticated if an `AuthenticationManager` was provided. A `PreAuthenticatedAuthenticationToken` is created based on the user authentication and then passed to the `AuthenticationManager`. However, if there were any details on the user authentication those details are lost because they are not copied to the `PreAuthenticatedAuthenticationToken`. If the `AuthenticationManager` is not provided then this logic is skipped over and the details are correctly preserved. The fix is simply to set the details on the `PreAuthenticatedAuthenticationToken` before passing it to the `AuthenticationManager`. Finally, I added two new tests to `DefaultTokenServicesTests` to validate that the user authentication is built correctly on a refresh. There is one test for the scenario when there is no re-authentication which passes even before these changes and then the other tests the re-authentication scenario which requires this change to pass.
fd08072
to
cfd1c3d
Compare
During a token refresh in the `DefaultTokenServices` the user authentication will be re-authenticated if an `AuthenticationManager` was provided. A `PreAuthenticatedAuthenticationToken` is created based on the user authentication and then passed to the `AuthenticationManager`. However, if there were any details on the user authentication those details are lost because they are not copied to the `PreAuthenticatedAuthenticationToken`. If the `AuthenticationManager` is not provided then this logic is skipped over and the details are correctly preserved. The fix is simply to set the details on the `PreAuthenticatedAuthenticationToken` before passing it to the `AuthenticationManager`. Finally, I added two new tests to `DefaultTokenServicesTests` to validate that the user authentication is built correctly on a refresh. There is one test for the scenario when there is no re-authentication which passes even before these changes and then the other tests the re-authentication scenario which requires this change to pass. Fixes gh-823
Thanks for the update @klieber. This is now in master and backported to 2.4.x. |
During a token refresh in the
DefaultTokenServices
the userauthentication will be re-authenticated if an
AuthenticationManager
was provided. A
PreAuthenticatedAuthenticationToken
is createdbased on the user authentication and then passed to the
AuthenticationManager
. However, if there were any details onthe user authentication those details are lost because they are
not copied to the
PreAuthenticatedAuthenticationToken
. If theAuthenticationManager
is not provided then this logic is skippedover and the details are correctly preserved.
The fix is simply to set the details on the
PreAuthenticatedAuthenticationToken
before passing it to theAuthenticationManager
. I've moved the re-authentication code intoa new protected method named
reauthenticateUserAuthentication
so thatit can be overridden if needed.
Finally, I added two new tests to
DefaultTokenServicesTests
tovalidate that the user authentication is built correctly on a refresh.
There is one test for the scenario when there is no re-authentication
which passes even before these changes and then the other tests the
re-authentication scenario which requires this change to pass.