Oihana PHP Arango

CasbinPolicySyncGrantTrait

Tells which Casbin rules a role or a service still holds, read from the authorization graph.

Casbin keeps one rule per (subject, domain, object, action, effect), whatever path of the graph grants it. A role can hold the same permission directly (role_has_permissions) and through one or more policies (role_has_policies → policy_has_permissions) ; a service the same way (service_has_permissions, service_has_policies). When one of those paths is removed, the live sync must remove the rule only when no other path still grants it — otherwise the subject loses a right the graph still gives.

The removal handlers run on afterDelete : the removed edge is no longer in the graph. A policy deletion runs on beforeDelete : its edges are still there, so the handler names the policy to ignore.

🚨 A lookup that fails returns null, and the caller removes the rule : a right the subject may have lost is restored by the next full rebuild, while a right kept by mistake would stay granted. The failure is logged as a warning.

The trait expects the consumer class to expose the following protected properties (declared on CasbinPolicySync) :

  • string $domain
  • ?Documents $permissionsModel
  • ?Edges $policyHasPermissions
  • ?Edges $roleHasPermissions
  • ?Edges $roleHasPolicies
  • ?Edges $serviceHasPermissions
  • ?Edges $serviceHasPolicies
  • ?LoggerInterface $logger
Tags
author

Marc Alcaraz

Table of Contents

Constants

GRANT_LOOKUP_LIMIT  : int = 10000
The most edges or permissions one lookup reads.

Methods

removeUnheldRules()  : int
Removes from a subject the rules of the given permissions it no longer holds.
roleHeldRules()  : array<string, true>|null
Lists the rules a role still holds through the graph.
serviceHeldRules()  : array<string, true>|null
Lists the rules a service still holds through the graph.
heldRules()  : array<string, true>|null
Reads the permissions a subject reaches directly and through its policies, and returns the keys of their rules.
targetKeys()  : array<string|int, string>
Lists the `_key` of the `_to` end of every edge leaving one of the given vertices.

Constants

Methods

removeUnheldRules()

Removes from a subject the rules of the given permissions it no longer holds.

protected removeUnheldRules(string $subject, iterable<string|int, object> $permissions, array<string, true>|null $held) : int
Parameters
$subject : string

The Casbin subject.

$permissions : iterable<string|int, object>

The permissions whose rules may go.

$held : array<string, true>|null

The rules the subject still holds (see self::roleHeldRules()), null when they cannot be read : every rule goes.

Return values
int —

The number of rules removed.

roleHeldRules()

Lists the rules a role still holds through the graph.

protected roleHeldRules(string $roleKey[, string|null $ignoredPolicyKey = null ]) : array<string, true>|null
Parameters
$roleKey : string

The role ArangoDB _key.

$ignoredPolicyKey : string|null = null

A policy whose permissions do not count (a policy being deleted).

Return values
array<string, true>|null —

The keys of the held rules (see CasbinPolicySyncRuleTrait::ruleKey()), or null when the graph cannot be read.

serviceHeldRules()

Lists the rules a service still holds through the graph.

protected serviceHeldRules(string $serviceKey[, string|null $ignoredPolicyKey = null ]) : array<string, true>|null
Parameters
$serviceKey : string

The service ArangoDB _key.

$ignoredPolicyKey : string|null = null

A policy whose permissions do not count (a policy being deleted).

Return values
array<string, true>|null —

The keys of the held rules (see CasbinPolicySyncRuleTrait::ruleKey()), or null when the graph cannot be read.

heldRules()

Reads the permissions a subject reaches directly and through its policies, and returns the keys of their rules.

private heldRules(string $subjectId, Edges|null $direct, Edges|null $viaPolicies, string|null $ignoredPolicyKey) : array<string, true>|null

Four reads at most, whatever the number of permissions : the direct edges, the policy edges, the permissions of those policies, then the permission documents themselves.

Parameters
$subjectId : string

The subject _id (roles/…, services/…).

$direct : Edges|null

The direct subject → permission edges.

$viaPolicies : Edges|null

The subject → policy edges.

$ignoredPolicyKey : string|null

A policy whose permissions do not count.

Return values
array<string, true>|null —

The held rule keys, or null when a read failed.

targetKeys()

Lists the `_key` of the `_to` end of every edge leaving one of the given vertices.

private targetKeys(Edges|null $edges, array<string|int, string> $fromIds) : array<string|int, string>
Parameters
$edges : Edges|null

The edge relation, null when not wired.

$fromIds : array<string|int, string>

The _id of the start vertices.

Tags
throws
DependencyException
NotFoundException
ContainerExceptionInterface
NotFoundExceptionInterface
ReflectionException
ArangoException
BindException
UnsupportedOperationException
ValidationException
ConstantException
Return values
array<string|int, string> —

The _to keys.

On this page

Search results