\Charcoal\UserAuthorizer

The authorizer service helps with user authorization (permission checking).

Constructor dependencies

Constructor dependencies are passed as an array of key=>value pair. The required dependencies are:

  • logger A PSR3 logger instance.
  • acl A Zend ACL (Access-Control-List) instance.
  • resource The ACL resource identifier (string).

Checking permissions

To check if a given ACL (passed in constructor) allows a list of permissions (aka privileges):

  • userAllowed(UserInterface $user, string[] $aclPermissions)
  • rolesAllowed(string[] $roles, string[] $aclPermissions)

Summary

Methods
Properties
Constants
__construct()
rolesAllowed()
userAllowed()
No public properties found
No constants found
acl()
resource()
No protected properties found
N/A
setAcl()
setResource()
$acl
$resource
N/A

Properties

$acl

$acl : \Zend\Permissions\Acl\Acl

Type

\Zend\Permissions\Acl\Acl

$resource

$resource : string

The ACL resource identifier

Type

string

Methods

__construct()

__construct(array  $data) 

Parameters

array $data

Class dependencies.

rolesAllowed()

rolesAllowed(array<mixed,string>  $aclRoles, array<mixed,string>  $aclPermissions) : boolean

Parameters

array<mixed,string> $aclRoles

The ACL roles to validate against.

array<mixed,string> $aclPermissions

The acl permissions to validate.

Returns

boolean —

Wether the permissions are allowed for a given list of roles.

userAllowed()

userAllowed(\Charcoal\User\UserInterface  $user, array<mixed,string>  $aclPermissions) : boolean

Parameters

\Charcoal\User\UserInterface $user

The user to validate against.

array<mixed,string> $aclPermissions

The acl permissions to validate.

Returns

boolean —

Whether the permissions are allowed for a given user.

acl()

acl() : \Zend\Permissions\Acl\Acl

Returns

\Zend\Permissions\Acl\Acl

resource()

resource() : string

Returns

string

setAcl()

setAcl(\Zend\Permissions\Acl\Acl  $acl) : void

Parameters

\Zend\Permissions\Acl\Acl $acl

The ACL instance.

setResource()

setResource(string  $resource) : void

Parameters

string $resource

The ACL resource identifier.

Throws

\InvalidArgumentException

If the resource identifier is not a string.