symfony/security-core

Symfony Security Component - Core Library

Maintainers

👁 fabpot

Package info

github.com/symfony/security-core

Homepage

pkg:composer/symfony/security-core

Statistics

Installs: 211 857 472

Dependents: 846

Suggesters: 17

Stars: 1 886

v8.1.0 2026-05-29 05:06 UTC

Requires (Dev)

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT a8239abe61dafdd0c01c0b4019138b2855717f97

This package is auto-updated.

Last update: 2026-06-09 11:23:05 UTC


README

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 8.1 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