RoleWarden
Roles and permissions in the database, with an admin panel, for CodeIgniter 4. RoleWarden extends CodeIgniter Shield: Shield keeps users, passwords, sessions, sign-in, "remember me", tokens and the record of sign-in attempts; RoleWarden moves roles and permissions out of a config file and into tables you manage at runtime.
What you get
- An admin panel at
/rolewarden: users, roles with inheritance, a permission matrix per role, per-user overrides, settings, an activity log, themes, a profile and session list for every user, and a CSV import. - Permission checks for your own code:
can('invoices.approve')in views and controllers,can:invoices.approveon routes, and Shield's own$user->can(), all answered from the database. - Security emails for sign-ins from a new device or address, password changes and repeated failed sign-ins.
- A browser installer, English and Italian, three themes in light and dark, and a demo app to copy from.
Requirements
- PHP 8.3 or later, with the
intl,mbstring,jsonandmysqliextensions - CodeIgniter 4.7.4 or later within 4.x
- CodeIgniter Shield 1.4 or later within 1.x
- MySQL or MariaDB with InnoDB
RoleWarden needs Shield. An application with its own authentication and no wish to use Shield cannot use RoleWarden.
Three ideas to keep in mind
Code checks permissions, never roles
Write can('users.delete'), never "is this user an admin". Roles are only bundles of permissions that administrators rearrange in the panel; code that names a role breaks the day someone renames or splits it.
Permissions are named area.action
Lowercase, one dot: users.view, invoices.approve, documents.delete. Code refers to them by this name, never by id.
How a check is decided
- A deactivated user is denied everything.
- A permission denied to that user by an override is denied, even to a super admin.
- A permission granted to that user by an override is granted.
- A super admin is granted everything else.
- A permission held by one of the user's roles, directly or inherited from a parent role, is granted.
- Anything else is denied.
Where to start
- Starting from nothing, or no Composer: the complete application, then the browser installer. See Installation.
- Adding RoleWarden to an application you already have: the module with Composer. See Installation.
- Already using Shield's groups in
app/Config/AuthGroups.php: see Migrating from Shield. - Securing your own pages: see API reference.
No file of the module is meant to be edited. Everything you customise lives in your application, so an update is a replacement of the module's folder. Changes between versions are listed in CHANGELOG.md; licences of third-party code in THIRD-PARTY-LICENSES.md.