feat(hydra): filter hydra:operation by operation security, add collection support#6
Merged
Merged
Conversation
…tion support [*] - check each advertised operation against the current token via API Platform's ResourceAccessChecker; operations whose security expression denies access are omitted (HATEOAS: the server controls what is available). Operations without a security expression stay visible. - item operations are evaluated with the loaded entity as `object` - enrich collection GET responses (hydra:Collection) with the security-filtered collection-level operations (create POST + custom collection actions); one check per operation, no per-member checks - new config flag hydra_operations.filter_operations_by_security (default true) to disable the filtering - emit Vary: Authorization while filtering is active (responses are user-dependent) - filtering is skipped gracefully when symfony/security-bundle is not installed (optional service reference) Closes #5
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.
Closes #5
What
hydra:operationis now checked against the current token via API Platform'sResourceAccessChecker; operations whosesecurityexpression denies access are omitted. Operations without asecurityexpression stay visible (default: allowed). Item operations are evaluated with the loaded entity asobject; evaluation errors fail closed.hydra:Collection) now also get ahydra:operationarray with the security-filtered collection-level operations (createPOST+ custom collection actions). One check per operation — no per-member evaluation.hydra_operations.filter_operations_by_security(defaulttrue) restores the previous unfiltered behavior when set tofalse.Vary: Authorizationis emitted while filtering is active, since the advertised operations are user-dependent. The static/docs.jsonldis untouched.symfony/security-bundlethe checker service is absent (optional reference) and filtering is skipped.partial_uuid_item_providernode in the configuration tree.Tests
12 new PHPUnit tests covering: denied vs. granted token on item and collection responses, operations without security expression staying visible,
objectcontext propagation, disabled flag, missing checker,Varyheader, id substitution. Full suite: 24 tests, 57 assertions, green.Verified manually against a local API Platform 4.3 / Symfony 7.4 stack with two Keycloak users (with/without the admin role): item response shrinks to
GETonly, collection response losesPOST+ custom actions for the unprivileged user;/docs.jsonldstays byte-identical across tokens.🤖 Generated with Claude Code