Skip to content
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

Closes gh-14352 #14369

Closed
wants to merge 1 commit into from
Closed

Closes gh-14352 #14369

wants to merge 1 commit into from

Conversation

Crain-32
Copy link
Contributor

The goal of #14352 is to begin introducing a more strongly typed Authentication object into the Spring Security Ecosystem. This should hopefully (My fingers are crossed) help slowly reduce some overhead for developers across the board as the general flow of User -> Authentication Object can be made more clear with people being able to see they should put a UserDetails Object in the Principal to align with Spring Security's Testing Support, along with being able to see the flow of Types through Spring Security, where now you just see Object passed everywhere.

For this PR I left it at adding in the interface and replicating the simple UsernamePasswordAuthenticationToken with the new interface, along with creating a new AbstractUserDetailsAuthentication<?, ?> which mirrors the AbstractAuthenticationToken, but requires the Principal object to be a UserDetails implementation. I believe swapping the UsernamePasswordAuthenticationToken for the UsernamePasswordTypedAuthenticationToken<?> to be a breaking change, and will leave that level of integration to the hands of the larger Spring Team.

Additionally I swapped the AbstractAuthenticationToken.eraseSecret(String)'s instance check to be a more modern capture group, as I was already reviewing that entire class.

Last thing to note is at the time of this PR #14352 is still in "waiting-for-triage", but I had a free afternoon and felt like trying this out, figured that might also help triage effort as at least for me, seeing code makes life a lot easier.

* @throws IllegalArgumentException if {@code principal.getAuthorities()} is null, or
* any Authorities in it are null.
*/
private UsernamePasswordTypedAuthenticationToken(UserDetails principal, String credentials, boolean authenticated) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another thing to note. I was very torn on if this should be a public or private constructor. In a review of how UsernamePasswordAuthenticationToken is handled, I arrived to the conclusion the maximum visibility should be protected, however with no sub-classes or other reasons to expose it, I left it as private.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Dec 22, 2023
@sjohnr
Copy link
Member

sjohnr commented Jan 5, 2024

Closing this PR for now per this comment.

@sjohnr sjohnr closed this Jan 5, 2024
@sjohnr sjohnr self-assigned this Jan 5, 2024
@sjohnr sjohnr added type: enhancement A general enhancement status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged labels Jan 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants