This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Acme\Framework\Security; | |
use Acme\Authentication\User; | |
use Symfony\Component\Security\Core\Exception\UnsupportedUserException; | |
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException; | |
use Symfony\Component\Security\Core\User\UserInterface; | |
use Symfony\Component\Security\Core\User\UserProviderInterface; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Acme\Framework\Security; | |
use Acme\Authentication\AuthenticationSessionInterface; | |
use Acme\Authentication\User; | |
use Acme\Authentication\UserManagerInterface; | |
use Symfony\Component\HttpFoundation\RedirectResponse; | |
use Symfony\Component\HttpFoundation\Request; | |
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// ... | |
/** | |
* Map legacy roles to symfony roles. Legacy roles are in following format: | |
* ['moderator' => '1'] | |
*/ | |
private function mapRoles() | |
{ | |
if (empty($this->legacyRoles)) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// ... | |
$c->loadFromExtension( | |
'security', | |
[ | |
'providers' => [ | |
'legacy' => [ | |
'id' => 'app.legacy_user_provider' | |
] | |
], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//... | |
$container->loadFromExtension(‘security’, [ | |
//... | |
‘access_control’ => [ | |
[‘path’ => ‘^/content/add’, ‘role’ => ‘ROLE_EDITOR’], | |
[‘path’ => ‘^/content/moderate’, ‘role’ => ‘ROLE_MODERATOR’], | |
[‘path’ => ‘^/user/edit’, ‘role’ => ‘ROLE_ADMIN’] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//... | |
$container->loadFromExtension(‘security’, [ | |
//... | |
‘access_control’ => [ | |
[‘path’ => ‘^/content/add’, ‘role’ => ‘add_content’], | |
[‘path’ => ‘^/content/moderate’, ‘role’ => ‘moderate_content’], | |
[‘path’ => ‘^/user/edit’, ‘role’ => ‘edit_user’] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//... | |
class PermissionUrlMap | |
{ | |
/** | |
* Order matters, in that it will match the first one it comes across. So put more specific URLs higher up. | |
* | |
* @var array Format is [‘permission’ => ‘/path/to/page’] | |
*/ | |
public static $permissionMap = [ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//... | |
class PermissionUrlRequestMatcher implements RequestMatcherInterface | |
{ | |
/** | |
* {@inheritdoc} | |
*/ | |
public function matches(Request $request) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//... | |
use ...CallableCompilerPass; | |
//... | |
protected function configurePasses(ContainerBuilder $c) | |
{ | |
$c->addCompilerPass(new CallableCompilerPass(function (ContainerBuilder $c) { | |
if (!$c->hasDefinition(‘security.access_map’)) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//... | |
class PermissionUrlVoter implements VoterInterface | |
{ | |
//... | |
/** | |
* {@inheritdoc} | |
*/ | |
public function vote(TokenInterface $token, $object, array $attributes) |