Split Authenticators from the Subject Resolving (UserDetail Providing) concern #550
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Split Authentication from User Detail Providing
| Related unFTP commit |
Overview
This PR refactors the authentication system to decouple authentication (verifying credentials) from user detail retrieval (obtaining full user information). The
Authenticatortrait is now non-generic and returns aPrincipaltype instead of a genericUsertype.Key Changes
1. Non-Generic
AuthenticatorTraitBefore:
After:
The
Authenticatortrait is now non-generic and returns aPrincipal(authenticated identity) instead of a full user object.2. New
PrincipalTypeIntroduced a new
Principalstruct that represents the minimal authenticated user identity:This contains only the authenticated username, separating the authentication step from user detail retrieval.
3. New
UserDetailProviderTraitIntroduced a new trait (copied and adapted from unFTP server) to convert a
Principalinto a fullUserDetailimplementation:This allows authentication and user detail lookup to be separated, enabling more flexible architectures.
4. New
AuthenticationPipelineStructIntroduced
AuthenticationPipelinethat combines anAuthenticatorand aUserDetailProvider:The pipeline provides a unified interface for the two-step authentication process:
Principal)PrincipaltoUser: UserDetail)5. Updated
ServerBuilderwith_user_detail_provider()constructor methodnew()andwith_authenticator()methods now automatically initializesDefaultUserDetailProvider6. Added
DefaultUserDetailProviderA convenience implementation that returns
DefaultUserfor simple use cases:Migration Guide
For Authenticator Implementations
Before:
After:
For Server Setup
Before:
After:
Or use the new constructor:
For Custom User Types
If you have a custom user type, you'll need to implement
UserDetailProvider:Updated Crates
All authentication crates have been updated:
unftp-auth-jsonfile- Updated to returnPrincipalunftp-auth-pam- Updated to returnPrincipalunftp-auth-rest- Updated to returnPrincipalBenefits
Breaking Changes
Authenticator<User>→Authenticator(non-generic)Authenticator.authenticate()now returnsPrincipalinstead ofUserunftp-auth-*crates need to be updated to use the new trait signature