Giter Club home page Giter Club logo

nette-authorizator's Introduction

ACL

Installation

$ composer require geniv/nette-authorizator

or

"geniv/nette-authorizator": ">=1.0.0"

require:

"php": ">=5.6.0",
"nette/nette": ">=2.4.0",
"dibi/dibi": ">=3.0.0"

Include in application

available source drivers:

  • Neon (neon filesystem) - support form
  • Dibi (dibi + cache) - support form
  • Array (neon configure)

policy:

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

neon configure:

# acl
authorizator:
#   autowired: false    # default null, true|false|self|null
    policy: allow       # allow (all is deny, allow part) | deny (all is allow, deny part) | none (all is allow, ignore part)
    source: "Neon"
    path: %appDir%/components/test/nette-authorizator/sql/acl.neon
#    source: "Dibi"
#    tablePrefix: %tablePrefix%
#    source: "Array"
#    role:
#        - guest
#        - moderator
#        - admin
#    resource:
#        - article
#        - comment
#        - poll
#    privilege:
#        - show
#        - insert
#        - update
#        - delete
#    acl:
#        moderator:
#            article: [show, insert, update]
#        admin: all

neon configure extension:

extensions:
    authorizator: Authorizator\Bridges\Nette\Extension

presenters:

$acl = $this->user->getAuthorizator();
$acl->isAllowed('guest', 'sekce-forum', 'zobrazit');

$this->user->isAllowed('sekce-forum', 'zobrazit');

usage:

<span n:if="$user->isAllowed('sekce-forum', 'zobrazit')">...</span>

All method onSuccess callback are default defined like $this->redirect('this');

presenters form:

use Authorizator\Forms\AclForm;
use Authorizator\Forms\PrivilegeForm;
use Authorizator\Forms\ResourceForm;
use Authorizator\Forms\RoleForm;
...
abstract class BasePresenter extends Presenter
{
    use AutowiredComponent;
...

protected function createComponentRoleForm(RoleForm $roleForm): RoleForm
{
    //$roleForm->setTemplatePath(path);
    //$roleForm->onSuccess[] = function (array $values) { };
    //$roleForm->onError[] = function (array $values, Exception $e = null) { };
    return $roleForm;
}


protected function createComponentResourceForm(ResourceForm $resourceForm): ResourceForm
{
    //$resourceForm->setTemplatePath(path);
    //$resourceForm->onSuccess[] = function (array $values) { };
    //$resourceForm->onError[] = function (array $values, Exception $e = null) { };
    return $resourceForm;
}


protected function createComponentPrivilegeForm(PrivilegeForm $privilegeForm): PrivilegeForm
{
    //$privilegeForm->setTemplatePath(path);
    //$privilegeForm->onSuccess[] = function (array $values) { };
    //$privilegeForm->onError[] = function (array $values, Exception $e = null) { };
    return $privilegeForm;
}

protected function createComponentAclForm(AclForm $aclForm): AclForm
{
    //$aclForm->setTemplatePath(path);
    //$aclForm->onSuccess[] = function (array $values) { };
    //$aclForm->onError[] = function (array $values) { };
    return $aclForm;
}

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
}

form not required for correct function ACL.

Available form: role, resource, privilege and acl.

usage form:

{control roleForm}
{control resourceForm}
{control privilegeForm}
{control aclForm}

nette-authorizator's People

Contributors

geniv avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.