EthikTag/vendor/symfony/security-core
Rudy b21f2bc04b conteneurisation de l'appli 2023-01-07 22:07:15 +01:00
..
Authentication conteneurisation de l'appli 2023-01-07 22:07:15 +01:00
Authorization conteneurisation de l'appli 2023-01-07 22:07:15 +01:00
Encoder conteneurisation de l'appli 2023-01-07 22:07:15 +01:00
Event conteneurisation de l'appli 2023-01-07 22:07:15 +01:00
Exception conteneurisation de l'appli 2023-01-07 22:07:15 +01:00
Resources/translations conteneurisation de l'appli 2023-01-07 22:07:15 +01:00
Role conteneurisation de l'appli 2023-01-07 22:07:15 +01:00
Signature conteneurisation de l'appli 2023-01-07 22:07:15 +01:00
Test conteneurisation de l'appli 2023-01-07 22:07:15 +01:00
User conteneurisation de l'appli 2023-01-07 22:07:15 +01:00
Validator/Constraints conteneurisation de l'appli 2023-01-07 22:07:15 +01:00
AuthenticationEvents.php conteneurisation de l'appli 2023-01-07 22:07:15 +01:00
CHANGELOG.md conteneurisation de l'appli 2023-01-07 22:07:15 +01:00
LICENSE conteneurisation de l'appli 2023-01-07 22:07:15 +01:00
README.md conteneurisation de l'appli 2023-01-07 22:07:15 +01:00
Security.php conteneurisation de l'appli 2023-01-07 22:07:15 +01:00
composer.json conteneurisation de l'appli 2023-01-07 22:07:15 +01:00

README.md

Security Component - Core

Security provides an infrastructure for sophisticated authorization systems, which makes it possible to easily separate the actual authorization logic from so called user providers that hold the users credentials.

Getting Started

$ composer require symfony/security-core
use Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolver;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
use Symfony\Component\Security\Core\Authorization\AccessDecisionManager;
use Symfony\Component\Security\Core\Authorization\Voter\AuthenticatedVoter;
use Symfony\Component\Security\Core\Authorization\Voter\RoleVoter;
use Symfony\Component\Security\Core\Authorization\Voter\RoleHierarchyVoter;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Security\Core\Role\RoleHierarchy;

$accessDecisionManager = new AccessDecisionManager([
    new AuthenticatedVoter(new AuthenticationTrustResolver()),
    new RoleVoter(),
    new RoleHierarchyVoter(new RoleHierarchy([
        'ROLE_ADMIN' => ['ROLE_USER'],
    ]))
]);

$user = new \App\Entity\User(...);
$token = new UsernamePasswordToken($user, 'main', $user->getRoles());

if (!$accessDecisionManager->decide($token, ['ROLE_ADMIN'])) {
    throw new AccessDeniedException();
}

Sponsor

The Security component for Symfony 5.4/6.0 is backed by SymfonyCasts.

Learn Symfony faster by watching real projects being built and actively coding along with them. SymfonyCasts bridges that learning gap, bringing you video tutorials and coding challenges. Code on!

Help Symfony by sponsoring its development!

Resources