spring-projects / spring-projects/spring-security
Consider reviewing the usage of `Authentication`
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 9.6k
- Forks
- 6.3k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 52
Description
Spring Security should consider reviewing the usage of the Authentication Interface in regards to improving the usability of Spring Security outlined in #13266
Spring's Authentication interface deals with a multitude of issues, many of which I believe stem from its exposure to the downstream Developer, multiplied by its relatively long lifespan (Almost as old as yours truly!) The main one I'd like to highlight for review is the following, a solution to which was discussed in #14352
- Weak Typing within the interface, specifically
getPrincipal()and its intended behavior within the Spring Security Architecture, being assumed to be an instance ofUserDetails.
During a longer review of the downstream pain with getPrincipal(), I'd like to highlight another minor issue that could also be addressed.
- Excessive doubling of information between the
UserDetailsandAuthentication, clouding responsibility.
For the main point I believe the fact the Javadoc states the following should be a good enough reason to review the type signature.
Many of the authentication providers will create a UserDetails object as the principal.
In order to not conflict with the overview statement of Spring Security , "Spring Security is a powerful and highly customizable authentication", a solution might also involve minor modifications to the UserDetails object to make it more flexible.
Regarding the minor point I believe a comparison of Methods within the UserDetails and Authentication Signatures can provide the context for it.
UserDetails::getPasswordtoAuthentication::getCredentialsUserDetails::getAuthoritiestoAuthentication::getAuthoritiesPrincipal::getNametoUserDetails::getUsername
This overlap results in what I can only call a "weird tuple". We need anAuthenticationto build aUserDetails, and 1/2 theAuthenticationis essentially useless until theUserDetails/Principalfield is populated, at which point the Credentials are cleared, and the behavior ofAuthenticationconverts more to that ofUserDetails. These two behaviors of Authenticating the User, and representing the User, within the same interface, make it hard to work with for anyone starting to get into Spring Security.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the Authentication, UserDetails, and Principal interfaces described in the issue, along with discussions in #13266 and #14352. Define and document an agreed approach for separating authentication from user representation and resolving the weak getPrincipal() typing; completion requires a decided, implementable design.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- authentication, backend-api-design, security
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100