2017 © Pedro Peláez
 

library rad-security

Provide RAD security components

image

knplabs/rad-security

Provide RAD security components

  • Thursday, September 21, 2017
  • by Knplabs
  • Repository
  • 20 Watchers
  • 3 Stars
  • 18,678 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 2 Open issues
  • 8 Versions
  • 2 % Grown

The README.md

DEPRECATED

Unfortunately we decided to not maintain this project anymore (see why). If you want to mark another package as a replacement for this one please send an email to hello@knplabs.com., (*1)

Rapid Application Development : Security

Provide RAD security components, (*2)

Build Status, (*3)

Official maintainers:

Installation

composer require knplabs/rad-security ~4.0
// config/bundles.php

<?php

return [
    Knp\Rad\Security\Bundle\SecurityBundle::class => ['all' => true],
];

Use

IS_OWNER voter

You now have access to a voter that checks if the authenticated user is the owner of an object., (*4)

The user contained inside the security token must implement Knp\Rad\Security\OwnerInterface., (*5)

The object you're about to test ownership must implement Knp\Rad\Security\OwnableInterface., (*6)

Example, (*7)

<?php

namespace App\Model;

use Knp\Rad\Security\OwnerInterface;

class User implements OwnerInterface
{
}
<?php

namespace App\Model;

use Knp\Rad\Security\OwnableInterface;
use App\Model\User;

class Book implements OwnableInterface
{
    /** @var App\Model\User */
    protected $writtenBy;

    public function __construct(User $writtenBy)
    {
        $this->writtenBy = $writtenBy;
    }

    public function getOwner()
    {
        return $this->writtenBy;
    }
}
$zola = new \App\Model\User(); // He is the current authenticated user
$hugo = new \App\Model\User();

$germinal = new \App\Model\Book($zola);
$miserables = new \App\Model\Book($hugo);

$authorizationChecker = $container->get(/* ... */);
$authorizationChecker->isGranted(array('IS_OWNER'), $germinal); // true
$authorizationChecker->isGranted(array('IS_OWNER'), $miserables); // false

Security from routing

You can specify security constraints directly from your routing by providing a role or an array of roles with the roles parameter. If you specify an array, it will be passed as is to the authorization checker, and that means the authorization strategy depends on your configuration of the security component., (*8)

Example, (*9)

acme_demo:
    path: /demo
    defaults:
        _controller: FrameworkBundle:Template:template
        template: Acme:demo:index.html.twig
        _security:
            - roles: IS_AUTHENTICATED_FULLY

The main advantage comes when used with the rad-resource-resolver component & the ParamConverter from SensioLabs. You can provide a subject previously resolved and available in the request attributes. If you have many objects resolved against which you can check security constraints, you can specify many rules., (*10)

Example, (*11)

acme_group_update:
    path: /team/{tid}/group/{gid}/update
    defaults:
        _controller: AcmeBundle:Group:update
        template: Acme:Group:update.html.twig
        _resources:
            team:
                # ...
            group:
                # ...
        _security:
            -
                roles: [IS_MEMBER, ANOTHER_ROLE]
                subject: team
            -
                roles: IS_OWNER
                subject: group

The Versions

03/03 2016
30/11 2015

v2.0.0

2.0.0.0

Provide RAD security components

  Sources   Download

MIT

The Requires

 

The Development Requires

by KNP Labs

02/09 2015

v1.0.1

1.0.1.0

Provide RAD security components

  Sources   Download

MIT

The Requires

 

The Development Requires

by KNP Labs

02/09 2015

v1.0.0

1.0.0.0

Provide RAD security components

  Sources   Download

MIT

The Requires

 

The Development Requires

by KNP Labs