foam3

See: auth/README.md Permissions.md

FOAM Authorization System

Core Model Relationships

The FOAM authorization system is built around four primary models: User, Group, Permission, and Capability. These models are connected through junction tables that enable many-to-many relationships while storing additional metadata.

Junction Tables

Permission Granting

Capabilities can grant permissions through their permissionsGranted property. The authorization system uses these relationships to determine user permissions through both group membership and granted capabilities.

Pseudo-Permission Inheritance

The @GroupName pseudo-permission creates a permission inheritance relationship between groups. When a group is assigned a permission with the @ prefix, it gains all permissions from the referenced target group.

Implementation Details

  1. Pseudo-Permission Detection: Permissions starting with @ are treated as special group references
  2. Target Group Resolution: The system extracts the group name after @ and looks up that group’s permissions
  3. Permission Inheritance: All permissions from the target group are implicitly granted to the source group

Key Characteristics

ServiceProvider (SPID) System

See SPID.md for comprehensive documentation on the SPID system.

ServiceProvider is a subclass of Capability that extends the core capability functionality. This provides multi-tenancy by isolating data and permissions per service provider.

Inherent Permissions

Each ServiceProvider automatically grants two specific permissions based on its ID:

User Home SPID

Each User has a spid property that references their home ServiceProvider. When a user’s SPID is set or changed, the system automatically creates or updates UserCapabilityJunctions to grant the ServiceProvider capability.

Authorization Flow

The authorization system checks SPID permissions through:

  1. Direct permission checks for serviceprovider.read.<spid> and serviceproviderdao.read.<spid>
  2. Capability-based permission checking via UserCapabilityJunctions
  3. SPID context checking when no user is present in the context

Key Features

Groups vs Capabilities: Key Differences

Cardinality Differences

The fundamental difference between Groups and Capabilities lies in their relationship with Users:

Prerequisite System

Capabilities have a unique prerequisite system that Groups lack:

SPID-Level Control Example

The prerequisite system enables powerful SPID-level feature control:

Practical Use Cases

This design pattern allows for:

Additionally, sub-classes of Capability can be greated which offer specialized functionality. The ServiceProvide class is a sub-class Capability. The inherentPermissions Property is meant to be used by Capability sub-classes.

Role Convention

Roles are Groups that follow a specific naming convention and usage pattern in the FOAM authorization system. This is purely a convention, not enforced by the software architecture.

Role Definition

Roles are Groups whose IDs contain “Role”, conventionally as a prefix (e.g. OpsRole).

Role Characteristics

By convention, Roles:

Role Inheritance Mechanism

Groups can inherit all permissions from a Role by assigning the pseudo-permission @RoleName. This creates a clean separation between:

Implementation Details

The permission table view (PermissionTableView) uses its ROLE_PREFIX constant ('Role'). In roles-only mode it drops groups whose ID contains “Role” from the columns and filters the rows to the @Role... pseudo-permissions, so the matrix shows which groups inherit which roles.

Benefits

This convention reduces maintenance overhead by:

Additional Notes

TODO