geniv/nette-identity-authorizator

Identity authorizator class for Nette Framework

v1.2.13 2019-04-10 20:43 UTC

README

Installation

$ composer require geniv/nette-identity-authorizator

or

"geniv/nette-identity-authorizator": "^1.2"

require:

"php": ">=7.0",
"nette/nette": ">=2.4",
"dibi/dibi": ">=3.0"

Include in application

available source drivers:

  • Identity\Authorizator\Drivers\ArrayDriver (array configure)
  • Identity\Authorizator\Drivers\NeonDriver (neon file)
  • Identity\Authorizator\Drivers\DibiDriver (dibi + cache)

policy:

  • allow - all is deny, allow part
  • deny - all is allow, deny part
  • none - all is allow, ignore part

neon configure:

# identity authorizator
identityAuthorizator:
#   debugger: true
#   autowired: true
#   policy: allow
#   driver: Identity\Authorizator\Drivers\ArrayDriver([],[],[],[])
#   driver: Identity\Authorizator\Drivers\NeonDriver(%appDir%/acl.neon)
    driver: Identity\Authorizator\Drivers\DibiDriver(%tablePrefix%)

Authorizator interface: IIdentityAuthorizator

neon configure extension:

extensions:
    identityAuthorizator: Identity\Authorizator\Bridges\Nette\Extension

presenters:

use AuthorizatorTrait;      // trait for add ACL from Tracy


$acl = $this->user->getAuthorizator();
$acl->isAllowed('role', 'resource', 'privilege');

$this->user->isAllowed('resource', 'privilege');

usage:

<span n:if="$user->isAllowed('resource', 'privilege')">...</span>

generic usage on security base presenter:

$acl = $this->user->getAuthorizator();
// manual set allowed with internal resolve policy
$acl->setAllowed(IAuthorizator::ALL, 'Homepage');
$acl->setAllowed(IAuthorizator::ALL, 'Login');

if (!$this->user->isAllowed($this->name, $this->action)) {
    // NOT ALLOWED
}