Skip to content
This repository was archived by the owner on May 31, 2022. It is now read-only.

Conversation

klieber
Copy link
Contributor

@klieber klieber commented Aug 16, 2016

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. I've moved the re-authentication code into
a new protected method named reauthenticateUserAuthentication so that
it can be overridden if needed.

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.

@klieber
Copy link
Contributor Author

klieber commented Aug 16, 2016

This change is loosely related to #581, however, the fix in that pull request does not fix the issue I was having. I believe that is because my issue is with the details on the user authentication whereas the @voronaam was concerned with the details on the OAuth2Authentication object.

@klieber
Copy link
Contributor Author

klieber commented Aug 16, 2016

I have signed the contributors agreement.

@voronaam
Copy link

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.
Thank you!

Copy link
Contributor

@jgrandja jgrandja left a 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) {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.
@klieber klieber force-pushed the bugfix/preserve-details-on-reauth branch from fd08072 to cfd1c3d Compare May 20, 2020 22:52
@jgrandja jgrandja closed this in b8a137b May 21, 2020
jgrandja pushed a commit that referenced this pull request May 21, 2020
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
@jgrandja
Copy link
Contributor

Thanks for the update @klieber. This is now in master and backported to 2.4.x.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

Successfully merging this pull request may close these issues.

4 participants