Authorisation System
- Introduction
- Access Instance
- Default Authorization System
- Security Best Practices
- Declared Privileges
Introduction
The authorisation system in Sukarix is managed through the f3-access library. The documentation for f3-access is
available in the f3-access repository.
Access Instance
The access instance is available in classes using the HasAccess behaviour trait. This trait integrates the access
control mechanisms provided by f3-access into your Sukarix application.
Default Authorization System
The beforeroute method of the Action class implements the default authorization system. This method checks the
user’s permissions before allowing access to specific routes or actions.
Security Best Practices
By default, everything is set to deny in the template application for security reasons. This default setting ensures
that only explicitly allowed actions are accessible, enhancing the overall security of your application.
Caution
Recommended Authorization Policy
For security, it is recommended to maintain the default
denysetting and explicitly allow access to necessary routes and actions.
Declared Privileges
Sukarix\Utils\PrivilegeUtils reads the privileges an application declares from the action
classes that carry them, which is what a role matrix is built from:
$privileges = PrivilegeUtils::listSystemPrivileges(
__DIR__ . '/Actions',
'Actions',
'Actions\RequirePrivilegeTrait'
);
// ['rooms' => ['add', 'delete', 'index'], 'users' => ['add', 'index'], …]
A privilege is the first two namespace segments below the root: Actions\Rooms\Index
declares rooms.index. Classes nested deeper share the privilege of the group above them,
so Actions\Rooms\Presentations\{Index,Add,Delete} is the single privilege
rooms.presentations rather than three. Classes sitting directly under the root are the
shared base classes and declare nothing.
Note
Why the directory rather than the class map
The composer class map is the obvious source, but an action added after the autoloader was dumped is missing from it, and its privilege then silently disappears from the role matrix — leaving a route nobody can be granted. The files on disk are the truth.