2017 © Pedro Peláez
 

library common-security-resolver

Simple voters-based access resolver

image

madlines/common-security-resolver

Simple voters-based access resolver

  • Saturday, February 27, 2016
  • by XanderEmu
  • Repository
  • 1 Watchers
  • 1 Stars
  • 60 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

Madlines Common Security Resolver

Build Status, (*1)

This is a very simple voters-bases security resolver. It gets a list of voters which work in a middleware fashion and it exposes a isGranted method which can ask voters if user can perform a specified task., (*2)

Voters don't have to implement any interface. To make that library more generic it uses duck typing instead. Voters need to be objects implementing one public method named as you like., (*3)

Tasks can be whatever you like. Those can be objects or just string. It's up to your voters to tell if they support it., (*4)

Usage:

Prepare a voter like that, (*5)

<?php

class PostEditVoter
{
    public function isGranted($user, $task)
    {
        // if (!($task instanceof PostEditTask)) {
        if ($task !== 'post_edit') {
            return null; // null means 'ignore'
            // returning integer 0 means the same
        }

        if ($user->hasRole('ROLE_ADMIN')) {
            return true; // agree
            // returning integer 1 means the same
        }

        return false; // disagree
        // returning integer -1 means the same
    }
}

Create an instance of AccessResolver and add voters to it, (*6)

$postEditVoter = new PostEditVoter();
// create more voters if you like

$resolver = new AccessResolver();

$resolver->addVoter($postEditVoter); // You can pass method name as second parameter. It defaults to `isGranted`
// add more voters if you like

Get your user from somewhere, (*7)

$user = $this->getUser();

And ask for permission like that:, (*8)

$resolver->isGranted($user, 'post_edit');
// or maybe $resolver->isGranted($user, $postEditTask);

The Versions

27/02 2016

dev-master

9999999-dev

Simple voters-based access resolver

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Aleksander Ciesiolkiewicz

27/02 2016

1.1

1.1.0.0

Simple voters-based access resolver

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Aleksander Ciesiolkiewicz

26/02 2016

1.0.2

1.0.2.0

Simple voters-based access resolver

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Aleksander Ciesiolkiewicz

26/02 2016

1.0.1

1.0.1.0

Simple voters-based access resolver

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Aleksander Ciesiolkiewicz

14/10 2015

1.0

1.0.0.0

Simple voters-based access resolver

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Aleksander Ciesiolkiewicz