Groups & Permissions
Group loading, permission evaluation and deny precedence.
Group Loading
The group controller reads the authenticated user’s assigned MongoDB group IDs and resolves active group documents through the context-specific collection. Invalid, missing, inactive or duplicate group assignments are ignored. The standard login flow redirects before the next request, where groups are initialized from the restored user.
Without a mapped group collection, group-based permissions are unavailable even when user authentication is enabled.
Permission Resolution
Permission keys are normalized to lowercase and trimmed. Effective authorization follows deny overrides grant: an explicit denial in any loaded group wins; otherwise at least one grant is required. No grant means denied by default.
has() and denies() report raw grants and denials. Use can() or
isAllowed() for effective authorization decisions.
Example
use Core\Registry;
use Core\User\Group;
$groups = Registry::get(Group::class);
if ($groups->can('cms.content.edit')) {
// Authorized action.
}
Public API Reference
Core\User\Group
Class & Registry
Class:
Core\User\Group
Extends:
Core\User\Group\Base
use Core\User\Group;
use Core\Registry;
$group = Registry::get(Group::class);
| Method | Description |
|---|---|
public function init(): void |
Initialize user group controller |
public function isAvailable(): bool |
Check if user group handling is available |
public function hasGroups(): bool |
Check if user groups are loaded |
public function getGroups(): array |
Get loaded user groups |
public function can(string $permission): bool |
Check if permission is effectively allowed |
public function cannot(string $permission): bool |
Check if permission is effectively denied |
public function isAllowed(string $permission): bool |
Check if permission is effectively allowed |
public function getAllowed(string $permission): bool |
Get effective allowed permission state |
public function isDenied(string $permission): bool |
Check if permission is effectively denied |
public function getDenied(string $permission): bool |
Get effective denied permission state |
public function has(string $permission): bool |
Check if permission is granted by an assigned group |
public function denies(string $permission): bool |
Check if permission is explicitly denied by an assigned group |
Group Document
Class & Registry
use Core\User\Group;
use Core\Registry;
$group = Registry::get(Group::class);
$groupDocument = $group->getDocument();
| Method | Description |
|---|---|
public function getName(): string |
Get group name |
public function setName(string $name): static |
Set group name |
public function isActive(): bool |
Get if group is active |
public function getActive(): bool |
Get active state |
public function setActive(bool $active): static |
Set active state |
public function getPermissions(): array |
Get granted permissions |
public function setPermissions(array $permissions): static |
Set granted permissions |
public function getDeniedPermissions(): array |
Get denied permissions |
public function setDeniedPermissions(array $deniedPermissions): static
|
Set denied permissions |
Implementation Details
The following technical reference expands the existing guide with authentication lifecycle, state management, and provider behavior.
Groups and Permissions
Overview
Core\User\Group\Base provides shared APPNETOS group loading and permission
evaluation.
The controller loads all active groups assigned to the current runtime user and exposes both raw and effective permission checks.
Application-Agnostic Permission Keys
APPNETOS does not impose a fixed permission vocabulary.
Applications may define arbitrary keys such as:
cms.content.edit
cms.uri.manage
shop.product.delete
appnetos-dns-control.nameservers.edit
Group Collection Mapping
The concrete group collection is supplied by the mapped application or context child:
protected function getCollection(): GroupCollection|null
{
return null;
}
Returning null disables group and permission handling.
Loading Groups
During initialization, the controller:
- Resolves the current runtime user.
- Reads the user's group IDs.
- Loads active group documents.
- Ignores invalid or missing group IDs.
- Stores loaded groups by ObjectId string.
Permission Semantics
APPNETOS uses deny-overrides-grant semantics.
Explicit DENY
→ always wins
No DENY + at least one GRANT
→ allowed
No DENY + no GRANT
→ denied
Raw Permission Checks
has()
Checks whether at least one loaded group grants the permission.
$group->has('cms.content.edit');
has() does not evaluate explicit denies.
denies()
Checks whether at least one loaded group explicitly denies the permission.
$group->denies('cms.content.edit');
denies() does not calculate the effective permission result.
Effective Permission Checks
can()
Returns the effective allowed state.
$group->can('cms.content.edit');
cannot()
Returns the inverse effective result.
$group->cannot('cms.content.edit');
Aliases:
$group->isAllowed($permission);
$group->getAllowed($permission);
$group->isDenied($permission);
$group->getDenied($permission);
Example
Group A
→ cms.content.edit GRANTED
Group B
→ cms.content.edit DENIED
Results:
has() = true
denies() = true
can() = false
cannot() = true
The explicit deny overrides the grant.
Important Difference
denies()
→ explicitly denied by a group
cannot()
→ effectively not allowed
A permission can therefore return:
denies() = false
cannot() = true
when no group explicitly denies it but no group grants it either.