GithubHelp home page GithubHelp logo

bear.aclresource's Introduction

BEAR.AclResource

Scrutinizer Code Quality Code Coverage Build Status

An ACL embedded resources module for BEAR.Sunday

This module embeds the app resource corresponding to the ACL in the specified page resource. Whereas the @Embedded annotation hard-codes and embeds app resources, this module embeds resources based on configuration. You can change the resource tree of page without changing the source code.

Install

Composer install

$ composer require bearsunday/acl-resource 1.x-dev

Module install

use Ray\Di\AbstractModule;
use Ray\TestDouble\TestDoubleModule;
use Ray\RoleModule\RoleProviderInterface;

class DevRoleProvider implements RoleProviderInterface
{
    // provide role
    public function get()
    {
        return 'guest';
    }
}

class AppModule extends AbstractModule
{
    protected function configure()
    {
        // configure ACL
        $acl = new Acl();
        $roleGuest = new Role('guest');
        $acl->addRole($roleGuest);
        $acl->addRole(new Role('owner'), $roleGuest);
        $acl->addResource(new Resource('app://self/entries'));
        $acl->addResource(new Resource('app://self/users'));
        $acl->addResource(new Resource('app://self/comments'));
        $acl->allow('guest', ['app://self/entries', 'app://self/comments']);
        $acl->allow('admin', 'app://self/friends');
        // configure embedded resource list
        $resources = [
            'page://self//blog' => [
                 'app://self/entries',
                 'app://self/comments',
                 'app://self/friends'
             ],
            'page://self//admin/setting' => [
                'app://self/user{?id}',
                'app://self/freinds?user_id={id}'
            ]
        ];
        // define provider
        $roleProviderClass = DevRoleProvider::class;
        // install module        
        $this->install(new AclResourceModule($acl, $resources, $roleProviderClass));
    }
}
  • $acl has an ACL (access control list) of Zend\Permaissions\Acl Specify. addResource all the URI path of the app resources available for $acl and specify an app resource that is accessible / impossible to the role with the allow() / disallow() method.
  • $resources is a list of which app resources can be embedded by each page resource.
  • $roleProviderClass specifies the class name to return the current user's role (eg from login status). You need to implement RoleProviderInterface.

In the example above, when accessing the /blog page with guest authority, request objects of app://self/entries and app://self/comments are set to $body['entries'], $body['comments].

bear.aclresource's People

Contributors

koriym avatar shiori-koga avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

poemn

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.