Repository navigation
refactor(hydra): extract the operation grant decision into OperationGrantChecker - #25
Merged
Merged
Conversation
…rantChecker [*] Move isFilteringActive() and isOperationGranted() from AddHydraOperationsSubscriber into a shared, privately registered service. The subscriber delegates to it; its first four constructor arguments keep type, position, default and name, the checker is an optional fifth one. No behaviour change. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Adds a direct unit test of the grant decision: inactive (switch off or no access checker) and operations without security expression or resource class are granted without calling the access checker; otherwise the checker is called once with class, expression and ['object' => $subject], with the key present for a null subject; any \Throwable denies. The extension test pins the wiring: the optional reference to api_platform.security.resource_access_checker on the checker definition and the subscriber's reference to the shared checker. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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
Refactoring only, no behaviour change. Release as patch
0.8.2.The grant decision of the runtime
hydra:operationsubscriber ("is filtering active" and "may the current token execute this operation") moves from private methods ofAddHydraOperationsSubscriberinto the shared, privately registered serviceDmstr\ApiPlatformUtils\Service\OperationGrantChecker(isActive(),isGranted(Operation $operation, ?object $subject = null)). The subscriber delegates to it. This prepares the discovery filter of #21, which needs the same decision for the OpenAPI document and the Hydra documentation; #21 stays open.What changes
OperationGrantChecker: the logic is moved literally, including the order of the checks (inactive, nosecurity, no resource class, access checker) and the fail-closed rule (any\Throwablewhile evaluating the expression denies).AddHydraOperationsSubscriberkeeps its four constructor arguments (type, position, default, name) and gains an optional fifth?OperationGrantChecker $grantChecker. Without it the subscriber builds a checker from arguments three and four; with it the given checker wins.config/services.yaml: the optional reference@?api_platform.security.resource_access_checkerand the parameterdmstr_api_platform_utils.hydra_operations.filter_operations_by_securitymove from the subscriber definition to the checker definition; the subscriber gets a reference to the checker.Unchanged: service IDs, configuration keys, parameters, the
Vary: Authorizationheader and the emittedhydra:operationentries. The checker stays coupled tohydra_operations.filter_operations_by_security.Tests
tests/EventSubscriber/AddHydraOperationsSubscriberTest.phpis unchanged and green, which is the proof that behaviour is preserved.tests/Service/OperationGrantCheckerTest.phpcovers the checker directly: both inactive cases, operations withoutsecurityor resource class (no call to the access checker), the call arguments including theobjectkey for a null subject, and denial on\Exceptionand\Error.ApiPlatformUtilsExtensionTestpins the wiring, in particular the optional reference on the checker definition: a typo there would silently disable filtering.🤖 Generated with Claude Code