LaLiga-BackEnd/vendor/symfony/security-core
Daniel Guzman 9f30bc98c7 welcome back to dyb-tech 2024-05-18 02:28:01 +02:00
..
Authentication welcome back to dyb-tech 2024-05-18 02:28:01 +02:00
Authorization welcome back to dyb-tech 2024-05-18 02:28:01 +02:00
Event welcome back to dyb-tech 2024-05-18 02:28:01 +02:00
Exception welcome back to dyb-tech 2024-05-18 02:28:01 +02:00
Resources/translations welcome back to dyb-tech 2024-05-18 02:28:01 +02:00
Role welcome back to dyb-tech 2024-05-18 02:28:01 +02:00
Signature welcome back to dyb-tech 2024-05-18 02:28:01 +02:00
Test welcome back to dyb-tech 2024-05-18 02:28:01 +02:00
User welcome back to dyb-tech 2024-05-18 02:28:01 +02:00
Validator/Constraints welcome back to dyb-tech 2024-05-18 02:28:01 +02:00
AuthenticationEvents.php welcome back to dyb-tech 2024-05-18 02:28:01 +02:00
CHANGELOG.md welcome back to dyb-tech 2024-05-18 02:28:01 +02:00
LICENSE welcome back to dyb-tech 2024-05-18 02:28:01 +02:00
README.md welcome back to dyb-tech 2024-05-18 02:28:01 +02:00
Security.php welcome back to dyb-tech 2024-05-18 02:28:01 +02:00
composer.json welcome back to dyb-tech 2024-05-18 02:28:01 +02: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 6.3 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