mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 23:13:15 +00:00
Add BaseVoter and Authorization Service Provider
PLUG-112
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2015 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace Alchemy\Phrasea\Authorization;
|
||||
|
||||
use Alchemy\Phrasea\Application as PhraseaApplication;
|
||||
use Silex\Application;
|
||||
use Silex\ServiceProviderInterface;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\PreAuthenticatedToken;
|
||||
use Symfony\Component\Security\Core\Authorization\AccessDecisionManager;
|
||||
|
||||
class AuthorizationServiceProvider implements ServiceProviderInterface
|
||||
{
|
||||
public function register(Application $app)
|
||||
{
|
||||
$app['phraseanet.security_token'] = $app->share(function (PhraseaApplication $app) {
|
||||
$user = $app['authentication']->getUser();
|
||||
|
||||
if ($user instanceof \User_Adapter) {
|
||||
return new PreAuthenticatedToken((string)$user->get_id(), null, 'fake', ['ROLE_USER']);
|
||||
}
|
||||
|
||||
return new AnonymousToken('fake', 'anon.', []);
|
||||
});
|
||||
|
||||
$app['phraseanet.access_manager'] = $app->share(function (PhraseaApplication $app) {
|
||||
return new AccessDecisionManager($app['phraseanet.voters']);
|
||||
});
|
||||
$app['phraseanet.voters'] = $app->share(function () {
|
||||
return [];
|
||||
});
|
||||
|
||||
$app['phraseanet.authorization_checker'] = $app->share(function (PhraseaApplication $app) {
|
||||
return new AuthorizationChecker(
|
||||
$app['phraseanet.access_manager'],
|
||||
$app['phraseanet.security_token']
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
public function boot(Application $app)
|
||||
{
|
||||
// Nothing to do
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user