Database-backed implementation of PermissionService with fail-closed error handling.
This implementation provides production-ready permission storage that:
Persists RelationTuples to a SQL database via PermissionRepository
Delegates permission logic to PermissionLogic (pure domain logic)
Implements fail-closed pattern: database errors result in access denial (return false)
Logs infrastructure failures before denying access for debugging
SECURITY CRITICAL: Database errors must NEVER bypass authorization checks. The fail-closed pattern ensures that any infrastructure failure (database down, connection timeout, query error) results in access denial rather than granting unintended permissions.
Check if a user is allowed to perform an action on a target resource.
Check if a user is allowed to perform an action on a target resource.
This method:
Fetches all relation tuples for the user in the target's namespace 2. Delegates to PermissionLogic.isAllowed (pure function) 3. Returns false (fail-closed) if any database error occurs 4. Logs warnings when database errors prevent permission checks
Value parameters
action
The permission operation to check
obj
The target resource
subj
The user information (optional)
Attributes
Returns
UIO[Boolean] - true if allowed, false if denied or error (fail-closed)
Removes the relation tuple from the database via repository.removeRelation. The repository implementation should be idempotent (revoking non-existent relations succeeds).
Value parameters
relation
The permission relation to revoke
target
The permission target
userId
The user to revoke the permission from
Attributes
Returns
UIO[Boolean] - true if successful, false if failed