NAME

Authorization::AccessControl::Grant - Encapsulation of the parameters of a privilege grant

SYNOPSIS

use Authorization::AccessControl::Grant;

my $grant = Authorization::AccessControl::Grant->new(
  resource => 'Book',
  action   => 'read',
);

$grant->accepts(resource => 'Book', action => 'read'); 

DESCRIPTION

This is a simple class to encapsulate the properties of a privilege grant: resource, action, roles, and restrictions, with the latter two optional. Methods are available for checking all properties at once ("accepts") and determining if another grant is exactly equal (used for duplicate detection) (is_equal).

Grant instances are immutable: none of their properties may be altered after object creation.

METHODS

new

Authorization::AccessControl::Grant->new( %params )

Creates a new privilege grant instance. Normally, you should use "grant" in Authorization::AccessControl::ACL rather than this constructor directly, to create and "register" instances. resource, action, role, and restrictions keys are respected in %params

role

Accessor for the role property

resource

Accessor for the resource property

action

Accessor for the action property

restrictions

Accessor for the restrictions property

is_equal

$grant1->is_equal($grant2)

Returns true if all properties of both grants are exactly the same, false otherwise

accepts

$grant->accepts( %params )

Returns true if the parameters meet all of the requirements of the grant, false otherwise. Specifically, this means that resource and action must match exactly, the grant's role (if set) must be contained within the roles ArrayRef, and every item in the grant's restrictions must be matched by a corresponding entry with the same value in the attributes HashRef

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.