feat(#117): #[RequiresAuth] checks SecurityContext::isAuthenticated() directly#133
Merged
Merged
Conversation
… directly - Method-level #[RequiresAuth] now checks SecurityContext instead of isAuthorized() - Class-level #[RequiresAuth] with no method annotations checks SecurityContext - checkMethodAuthorization() falls back to class-level check before isAuthorized() - Add hasClassLevelRequiresAuth() helper method - Services without auth attributes still use isAuthorized() (unchanged) - 8 new tests covering method-level, class-level, AllowAnonymous override, fallback
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #133 +/- ##
============================================
+ Coverage 93.64% 93.68% +0.04%
- Complexity 1303 1306 +3
============================================
Files 39 39
Lines 3177 3184 +7
============================================
+ Hits 2975 2983 +8
+ Misses 202 201 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.



Summary
Make
#[RequiresAuth]checkSecurityContext::isAuthenticated()instead of callingisAuthorized()(which defaults tofalse). Implements ADR-0003.Motivation
#[RequiresAuth]was effectively broken — it calledisAuthorized()which defaults tofalse, requiring every service to override it with boilerplate. The attribute name implies "check if user is authenticated," which is whatSecurityContext::isAuthenticated()does. Fixes #117.Changes
checkMethodAuthorization(): method-level#[RequiresAuth]now checksSecurityContext::isAuthenticated()checkMethodAuthorization(): when method has no auth annotations, checks class-level#[RequiresAuth]before falling back toisAuthorized()WebServicesManager::isAuth(): class-level#[RequiresAuth]with no method annotations checksSecurityContext::isAuthenticated()WebService::hasClassLevelRequiresAuth()helperUI Changes
N/A
How to Test / Verify
8 new tests, 19 assertions. Full suite: 550 tests pass.
Breaking Changes and Migration Steps
Behavior change for services using
#[RequiresAuth]:isAuthorized()defaults tofalse)SecurityContext::isAuthenticated()(works as intended)Services without auth attributes are unchanged.
Checklist
Related issues
Closes #117
ADR: https://github.com/WebFiori/docs/blob/main/adr/0003-requires-auth-security-context.md