NAME

Authorization::AccessControl::ACL - Access Control List of granted privileges

SYNOPSIS

use Authorization::AccessControl::ACL;

my $acl = Authorization::AccessControl::ACL->new();
$acl->role("admin")
  ->grant(User => "delete")
  ->grant(User => "create");

$acl->grant(Book => "search")
  ->grant(Book => 'delete', {owned => true});

my req = $acl->request;
...

DESCRIPTION

The ACL class provides functionality for maintaining a set of granted privileges. Each item in the list is an instance of Authorization::AccessControl::Grant. Every call to "grant" creates a new grant instance and adds it to the ACL's list. By default, these grants are role-less: they apply to all users. Calling "role" with a role name argument allows you to chain subsquent calls to "grant" off of it: such grants are configured for that role only.

The full grant list can be obtained via the "get_grants" method, although this is merely informational - the grants themselves are immutable and have little relevent functionality outside of the ACL.

The "request" method generates an Authorization::AccessControl::Request, which is used to check if a specific action is permitted by the ACL.

Most ACL instance properties are immutable: with the exception of the list contents, none of their properties may be altered after object creation.

METHODS

new

Authorizatrion::AccessControl::ACL->new()

Constructor.

Creates a new ACL instance. Each ACL instance created via this constructor is entirely unrelated. For a global persistent ACL, see "acl" in Authorization::AccessControl

clone

$acl->clone()

Creates a new ACL instance pre-populated with the cloned object's grants and hooks. Once cloned, the two instances are entirely unrelated and changes to one will not be reflected in the other.

N.B. contextual role is not taken into account when cloning:

my $acl2 = $acl1->role('admin')->grant(User => "delete")->clone;
$acl2->grant(User => "update"); 

The second grant is role-less, applying to all users, even though the admin role context was active when the clone was performed. This may cause you to inadvertently grant more privileges than you expect if not attended to.

role

$acl->role($role = undef)

Returns a new dependent instance of Authorization::AccessControl::ACL facilitating chaining in order to create role-specific grants. Dependent instances share a grant list with their "parent".

The $role argument is optional, if omitted or undef, the returned instance becomes role-less. If present, should be a string.

Chainable.

grant

$acl->grant($resource => $action)

Creates a privilege Authorization::AccessControl::Grant and adds it to the access control list.

Chainable.

get_grants

$acl->get_grants()

Returns an array of all grants contained in the access control list.

request

$acl->request()

Returns an Authorization::AccessControl::Request instance linked to this ACL. Subsequent changes to the ACL will be taken into account if made prior to the request being evaluated. "clone" first to avoid the implications of this behavior, if required.

hook

$acl->hook(on_permit|on_deny => sub {})

Register a callback to be executed when a permission request is granted or denied, such as for comprehensive authorization logging. Multiple hooks may be registered for each status, and will be called in order when the event occurs.

on_permit handlers receive a Authorization::AccessControl::Grant that accepted the request as their argument.

on_deny handlers receive a Authorization::AccessControl::Request that failed to be accepted by any grant as their argument.

AUTHOR

Mark Tyrrell <mark@tyrrminal.dev>

LICENSE

Copyright (c) 2024 Mark Tyrrell

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.