2017 © Pedro PelĂĄez
 

symfony-bundle security-role-checker-bundle

Provide Symfony services for checking user security roles

image

jdecool/security-role-checker-bundle

Provide Symfony services for checking user security roles

  • Saturday, October 8, 2016
  • by jdecool
  • Repository
  • 1 Watchers
  • 0 Stars
  • 9 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Symfony security role checker

Build Status Build status Scrutinizer Code Quality Latest Stable Version, (*1)

This bundle provides Symfony services for checking user security roles., (*2)

Compatibility

This bundle is tested with Symfony 2.7+, but it should be compatible with Symfony 2.3+, (*3)

Warning

The RoleChecker service doesn't emulate an user authentication. It mean that if the authentication process modify user rights, the service can detect roles updates., (*4)

Documentation

Install it

Install extension using composer:, (*5)

{
    "require": {
        "jdecool/security-role-checker-bundle": "~1.0"
    }
}

Enable the extension in your application AppKernel:, (*6)

<?php

public function registerBundles()
{
    $bundles = [
        // ...
        new JDecool\Bundle\SecurityRoleCheckerBundle\JDecoolSecurityRoleCheckerBundle(),
    ];

    // ...

    return $bundles;
}

Use it

You can check role by accessing jdecool.security.role_checker service :, (*7)

class MyController
{
    public function myAction()
    {
        $roleChecker = $this->get('jdecool.security.role_checker');

        var_dump($role->hasRole('ROLE_USER')); // checking role for current user

        $userWithRole = $this->getDoctrine()->getRepository(/* ... */)->find(1);
        var_dump($role->hasRole('ROLE_USER', $userWithRole)); // true

        $userWithoutRole = $this->getDoctrine()->getRepository(/* ... */)->find(2);
        var_dump($role->hasRole('ROLE_USER', $userWithoutRole)); // false

        // ... 
    }
}

You can also check role in a Twig template (even if it's not a best practice) :, (*8)

{{ has_role('ROLE_USER') ]} # Check role for current user
{{ has_role('ROLE_USER', other_user) ]}

License

This library is published under MIT license, (*9)

The Versions

08/10 2016

dev-master

9999999-dev http://github.com/jdecool/SecurityRoleCheckerBundle

Provide Symfony services for checking user security roles

  Sources   Download

MIT

The Requires

 

The Development Requires

security symfony role hasrole

14/07 2016

1.0.0

1.0.0.0 http://github.com/jdecool/SecurityRoleCheckerBundle

Provide Symfony services for checking user security roles

  Sources   Download

MIT

The Requires

 

The Development Requires

security symfony role hasrole