AclSecurityHandler.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /*
  3. * This file is part of the Sonata project.
  4. *
  5. * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Sonata\AdminBundle\Security\Handler;
  11. use Symfony\Component\Security\Core\SecurityContextInterface;
  12. use Sonata\AdminBundle\Admin\AdminInterface;
  13. class AclSecurityHandler implements SecurityHandlerInterface
  14. {
  15. public function __construct(SecurityContextInterface $securityContext)
  16. {
  17. $this->securityContext = $securityContext;
  18. }
  19. /**
  20. * {@inheritDoc}
  21. */
  22. public function isGranted($attributes, $object = null)
  23. {
  24. return $this->securityContext->isGranted($attributes, $object);
  25. }
  26. /**
  27. * {@inheritDoc}
  28. */
  29. public function buildSecurityInformation(AdminInterface $admin)
  30. {
  31. $baseRole = 'ROLE_'.str_replace('.', '_', strtoupper($admin->getCode())).'_%s';
  32. $results = array();
  33. foreach ($admin->getSecurityInformation() as $name => $permissions) {
  34. $results[sprintf($baseRole, $name)] = $permissions;
  35. }
  36. return $results;
  37. }
  38. }