webroot/vendor/symfony/security-core
2024-12-01 20:57:32 +01:00
..
Authentication 2024.12.01 20:57:28 2024-12-01 20:57:32 +01:00
Authorization 2024.12.01 20:57:28 2024-12-01 20:57:32 +01:00
Event 2024.12.01 20:57:28 2024-12-01 20:57:32 +01:00
Exception 2024.12.01 20:57:28 2024-12-01 20:57:32 +01:00
Resources/translations 2024.12.01 20:57:28 2024-12-01 20:57:32 +01:00
Role 2024.12.01 20:57:28 2024-12-01 20:57:32 +01:00
Signature 2024.12.01 20:57:28 2024-12-01 20:57:32 +01:00
Test 2024.12.01 20:57:28 2024-12-01 20:57:32 +01:00
User 2024.12.01 20:57:28 2024-12-01 20:57:32 +01:00
Validator/Constraints 2024.12.01 20:57:28 2024-12-01 20:57:32 +01:00
AuthenticationEvents.php 2024.12.01 20:57:28 2024-12-01 20:57:32 +01:00
CHANGELOG.md 2024.12.01 20:57:28 2024-12-01 20:57:32 +01:00
composer.json 2024.12.01 20:57:28 2024-12-01 20:57:32 +01:00
LICENSE 2024.12.01 20:57:28 2024-12-01 20:57:32 +01:00
README.md 2024.12.01 20:57:28 2024-12-01 20:57:32 +01:00
Security.php 2024.12.01 20:57:28 2024-12-01 20:57:32 +01:00

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.4 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