2017 © Pedro Peláez
 

library security-core

Symfony Security Component - Core Library

image

symfony/security-core

Symfony Security Component - Core Library

  • Thursday, July 26, 2018
  • by fabpot
  • Repository
  • 8 Watchers
  • 69 Stars
  • 10,718,292 Installations
  • PHP
  • 124 Dependents
  • 1 Suggesters
  • 13 Forks
  • 0 Open issues
  • 100 Versions
  • 2 % Grown

The 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., (*1)

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();
}

The Security component for Symfony 7.1 is backed by SymfonyCasts., (*2)

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!, (*3)

Help Symfony by [sponsoring][3] its development!, (*4)

Resources

The Versions