Commit 83ff03e9 authored by Haralan Dobrev's avatar Haralan Dobrev

Revert ServiceIteraror in Security provider voters

Reopens https://github.com/silexphp/Silex/issues/1530
See problems and discussed solutions in
https://github.com/silexphp/Silex/pull/1619
parent 9a7b1fca
...@@ -5,7 +5,6 @@ Changelog ...@@ -5,7 +5,6 @@ Changelog
------------------ ------------------
* added support for defining users provider as a service ID * added support for defining users provider as a service ID
* added support for ServiceIterator in Security provider for voters
* fixed error when HttpKernelRuntime is not available * fixed error when HttpKernelRuntime is not available
* allow setting custom status code on exception response with Symfony 3.3+ * allow setting custom status code on exception response with Symfony 3.3+
* made CSRF extension work with Validator translations domain * made CSRF extension work with Validator translations domain
......
...@@ -695,32 +695,6 @@ Symfony `cookbook`_. ...@@ -695,32 +695,6 @@ Symfony `cookbook`_.
providers. :doc:`How to Create a Custom Authentication System with Guard providers. :doc:`How to Create a Custom Authentication System with Guard
</cookbook/guard_authentication>` </cookbook/guard_authentication>`
Using Voters to check User Permissions
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
See the `Security component documentation on voters <http://symfony.com/doc/current/security/voters.html>`_.
By default Silex includes the role hierarchy and authenticated voters. If you
want to add a custom voter, you need to register it as a service and extend
``security.voter_services``::
$app['custom_voter'] = function () {
return MyCustomVoter();
};
$app->extend('security.voter_services', function (array $voters) {
$voters[] = 'custom_voter';
return $voters;
});
.. note::
Using the above approach with the service names, circular references are
avoided and you can use the ``AccessDecisionManager`` in your custom voter
to `check for roles inside a voter
<http://symfony.com/doc/current/security/voters.html#checking-for-roles-inside-a-voter>`_.
Stateless Authentication Stateless Authentication
~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
namespace Silex\Provider; namespace Silex\Provider;
use Pimple\Container; use Pimple\Container;
use Pimple\ServiceIterator;
use Pimple\ServiceProviderInterface; use Pimple\ServiceProviderInterface;
use Silex\Application; use Silex\Application;
use Silex\Api\BootableProviderInterface; use Silex\Api\BootableProviderInterface;
...@@ -142,29 +141,14 @@ class SecurityServiceProvider implements ServiceProviderInterface, EventListener ...@@ -142,29 +141,14 @@ class SecurityServiceProvider implements ServiceProviderInterface, EventListener
}; };
$app['security.access_manager'] = function ($app) { $app['security.access_manager'] = function ($app) {
$votersIterator = new ServiceIterator($app, $app['security.voter_services']); return new AccessDecisionManager($app['security.voters']);
return new AccessDecisionManager($votersIterator);
};
$app['security.voter_services'] = function () {
return [RoleHierarchyVoter::class, AuthenticatedVoter::class];
};
$app[RoleHierarchyVoter::class] = function ($app) {
return new RoleHierarchyVoter(new RoleHierarchy($app['security.role_hierarchy']));
}; };
$app[AuthenticatedVoter::class] = function ($app) {
return new AuthenticatedVoter($app['security.trust_resolver']);
};
// Unused, kept for backwards-compatibility
// Extend security.voter_services instead to prevent circular references
$app['security.voters'] = function ($app) { $app['security.voters'] = function ($app) {
return array_map(function ($voterServiceId) use ($app) { return [
return $app[$voterServiceId]; new RoleHierarchyVoter(new RoleHierarchy($app['security.role_hierarchy'])),
}); new AuthenticatedVoter($app['security.trust_resolver']),
];
}; };
$app['security.firewall'] = function ($app) { $app['security.firewall'] = function ($app) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment