Skip to content

Repository files navigation

Charcoal User

The User package provides abstract tools for defining user models, authenticating and authorizating users from an integration with Laminas Permissions ACL.

Installation

composer require charcoal/user

Overview

The User object

At the core of this module is the definition of a "User" object. The contract can be found as \Charcoal\User\UserInterface. This interfaces extends \Charcoal\Object\ContentInterface (from charcoal/object), which extends \Charcoal\Model\ModelInterface (from charcoal/core).

The preferred way of using this module is by defining your own User class in your project and extending the provided \Charcoal\User\AbstractUser class.

For quick prototypes or small projects, a full concrete class is provided as \Charcoal\User\GenericUser.

User properties

PropertyTypeDefaultDescription
usernamestringtrue
passwordstringnull
emailstringnull
rolesstring[][]ACL roles, which define user permissions.
last_login_datedate-timenull
last_login_ipstring''
last_password_datedate-timenull
last_password_ipstring''
login_tokenstringnull

Note that the key of the User is the username. Therefore, id() returns the username. It must be unique.

Properties inherited from Content-Interface:

PropertyTypeDefaultDescription
activebooleantrue
positionnumbernull
createddate-timenull
created_bystring''
last_modifieddate-timenull
last_modified_bystring''

Authentication

TODO

Authorization

User authorization is managed with a role-based Access Control List (ACL). Internally, it uses laminas/laminas-permissions-acl for the ACL logic. It is recommended to read the Laminas ACL documentation to learn more about how it all works.

There are 2 main concepts that must be managed, either from JSON config files or in the database (which works well with charcoal/admin), roles and permissions.

ACL Configuration

To set up ACL, it is highly recommended to use the \Charcoal\User\Acl\Manager.

ACL Example

{
"acl": {
"permissions": {
"superuser": {
"superuser": true
},
"author": {
"allowed": {},
"denied": {}
}
}
}
}
useCharcoal\User\Acl\ManagerasAclManager;
useLaminas\Permissions\Acl\Acl;
useLaminas\Permissions\Acl\Resource\GenericResourceasAclResource;
$acl = newAcl();
// Add resource for ACL$acl->addResource(newAclResource($resourceName));
$aclManager = newAclManager([
'logger' => $logger,
]);
$aclManager->loadPermissions($acl, $config['acl.permissions'], $resourceName);
$authorizer = newAuthorizer([
'logger' => $logger,
'acl' => $acl,
'resource' => $resourceName,
]);
$isAllowed = $authorizer->userAllowed($user, [ 'permssion' ]);

Resources

About

[READ-ONLY] User definition, authentication and authorization

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

2 watching

Forks

Releases

Used by

Contributors

Languages