2017 © Pedro Peláez
 

library overseer

Attribute-based authorization manager.

image

spareparts/overseer

Attribute-based authorization manager.

  • Wednesday, January 18, 2017
  • by SpareParts
  • Repository
  • 2 Watchers
  • 2 Stars
  • 4,590 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 5 Versions
  • 11 % Grown

The README.md

Overseer

Action-based authorization manager, (*1)

Quick disclaimer: This is pretty much a work in progress. At this point this is more of a "proof-of-concept" than working code. Though the logic is sound and I fully intend to finish this into an awesome 1.0 release., (*2)

Build Status Scrutinizer Code Quality Build Status Code Coverage, (*3)

What is this and why should I care?

Overseer is an "action-based" auth manager, meaning it is based on authorizing possible "actions" (such as read, edit, delete, etc.) with given "subject" (such as Article, Product, Category etc.)., (*4)

Overseer focuses on decoupling auth logic from the rest of the application. When solving problems as "user that is the owner of this product can edit it" other auth managers tend to wire the logic directly into the said product class or pile all possible actions (read, write, delete, ...) into one big method. Either way it breaks S of the SOLID principles (single responsibility principle) and that's where Overseer jumps in., (*5)

Basic building stones of Overseer are "voting assemblies", consisting of "voters". Each combination of action and subject can have (doesn't have to, though) its own voting assembly, thus separating concerns and responsibilities involved., (*6)

Installation

Composer

This is how we do it, boys., (*7)

composer require spareparts/overseer

Basic usage

Let's imagine we have an article site, and we want to make sure the admin can read the article always, while its author only unless it's not banned., (*8)

This is how we create the voting assembly for this specific subject and action. It contains four voters,, (*9)

$assembly = new VotingAssembly(
    $subjectName = 'article',
    $actionName = 'read',
    $strategy = StrategyEnum::FIRST_VOTE_DECIDES(),
    $voters = [
        new RoleVoter(VotingDecisionEnum::ALLOWED(), 'admin'),
        new ClosureVoter(function (DummyArticle $article, IdentityContext $context) {
            // allow the owner to edit
            if ($subject->ownerId === $context->getId()) {
                return new SingleVoterResult(VotingDecisionEnum::ALLOWED());
            }
            return null;
        }),
        new ClosureVoter(function (DummyArticle $article) {
            // deny access if the article is banned
            if ($subject->isBanned()) {
                return new SingleVoterResult(VotingDecisionEnum::ALLOWED());
            }
            return null;
        }),
        new RoleVoter(VotingDecisionEnum::ALLOWED(), 'user'),
    ]
);

$authorizationManager = new GenericVotingManager([
    // our article edit assembly
    $assembly,
    // other assemblies...
    // ...
]);

Now let's use it, (*10)

$context = new IdentityContext($userId, $userRoles);
$authorized = $authorizationManager->vote('edit', $article, $context);
if ($authorized->getDecision() === VotingDecisionEnum::ALLOWED()) {
    // we can edit!
}

The Versions

18/01 2017

dev-master

9999999-dev

Attribute-based authorization manager.

  Sources   Download

MIT

The Requires

 

The Development Requires

acl attribute authorization authorization manager

09/01 2017

v0.1.0

0.1.0.0

Attribute-based authorization manager.

  Sources   Download

MIT

The Requires

 

The Development Requires

acl attribute authorization authorization manager

07/01 2017

dev-new_doc

dev-new_doc

Attribute-based authorization manager.

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

The Development Requires

acl attribute authorization authorization manager

24/12 2016

dev-assembly_tests

dev-assembly_tests

Attribute-based authorization manager.

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

The Development Requires

acl attribute authorization authorization manager

19/12 2016

dev-new_revision

dev-new_revision

Attribute-based authorization manager.

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

The Development Requires

acl attribute authorization authorization manager