mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-26 03:13:12 +00:00
Add MockedAuthenticatedVoter because at least one voter is needed
This commit is contained in:
@@ -34,7 +34,7 @@ class AuthorizationServiceProvider implements ServiceProviderInterface
|
|||||||
return new AccessDecisionManager($app['phraseanet.voters']);
|
return new AccessDecisionManager($app['phraseanet.voters']);
|
||||||
});
|
});
|
||||||
$app['phraseanet.voters'] = $app->share(function () {
|
$app['phraseanet.voters'] = $app->share(function () {
|
||||||
return [];
|
return [new MockedAuthenticatedVoter()];
|
||||||
});
|
});
|
||||||
|
|
||||||
$app['phraseanet.authorization_checker'] = $app->share(function (PhraseaApplication $app) {
|
$app['phraseanet.authorization_checker'] = $app->share(function (PhraseaApplication $app) {
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
<?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 Symfony\Component\Security\Core\Authentication\Token\AnonymousToken;
|
||||||
|
use Symfony\Component\Security\Core\Authentication\Token\PreAuthenticatedToken;
|
||||||
|
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||||
|
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
|
||||||
|
|
||||||
|
class MockedAuthenticatedVoter implements VoterInterface
|
||||||
|
{
|
||||||
|
const IS_AUTHENTICATED_FULLY = 'IS_AUTHENTICATED_FULLY';
|
||||||
|
const IS_AUTHENTICATED_ANONYMOUSLY = 'IS_AUTHENTICATED_ANONYMOUSLY';
|
||||||
|
|
||||||
|
public function supportsAttribute($attribute)
|
||||||
|
{
|
||||||
|
return null !== $attribute && (self::IS_AUTHENTICATED_FULLY === $attribute || self::IS_AUTHENTICATED_ANONYMOUSLY === $attribute);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function supportsClass($class)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function vote(TokenInterface $token, $object, array $attributes)
|
||||||
|
{
|
||||||
|
$result = VoterInterface::ACCESS_ABSTAIN;
|
||||||
|
foreach ($attributes as $attribute) {
|
||||||
|
if (!$this->supportsAttribute($attribute)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = VoterInterface::ACCESS_DENIED;
|
||||||
|
|
||||||
|
if (self::IS_AUTHENTICATED_FULLY === $attribute
|
||||||
|
&& $token instanceof PreAuthenticatedToken
|
||||||
|
) {
|
||||||
|
return VoterInterface::ACCESS_GRANTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (self::IS_AUTHENTICATED_ANONYMOUSLY === $attribute
|
||||||
|
&& $token instanceof AnonymousToken
|
||||||
|
) {
|
||||||
|
return VoterInterface::ACCESS_GRANTED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user