Skip to content
Snippets Groups Projects
foo.php 1.96 KiB
Newer Older
Maxime Veber's avatar
Maxime Veber committed
<?php

require __DIR__ . '/vendor/autoload.php';


$request = \Symfony\Component\HttpFoundation\Request::createFromGlobals();
$dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher();



/////////////////////////
/// AUTHENTICATION

// Preparation


// Auth

// Should happen in CustomAuthenticationListener
/*
$providers = [new \BiiG\SecurityTest\CustomAuthenticationProvider()];
$authenticationManager = new \Symfony\Component\Security\Core\Authentication\AuthenticationProviderManager($providers);
$authenticatedToken = $authenticationManager->authenticate($unauthenticatedToken);
//*/



///////////////////////
/// FIREWALL

$map = new \Symfony\Component\Security\Http\FirewallMap();

$requestMatcher = new \Symfony\Component\HttpFoundation\RequestMatcher('^/');

$tokenStorage = new \Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage();

// instances of Symfony\Component\Security\Http\Firewall\ListenerInterface
$listeners = [new \BiiG\SecurityTest\CustomAuthenticationListener(
    $tokenStorage,
    new \BiiG\SecurityTest\CustomAuthenticationProvider(),
    'swagg'
)];


$anonymousClass = \Symfony\Component\Security\Core\Authentication\Token\AnonymousToken::class;
$rememberMeClass = \Symfony\Component\Security\Core\Authentication\Token\RememberMeToken::class;

$trustResolver = new \Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolver($anonymousClass, $rememberMeClass);

// The exception listener object is too complex for this example
/*
$exceptionListener = new \Symfony\Component\Security\Http\Firewall\ExceptionListener($tokenStorage, $trustResolver);
//*/

$map->add($requestMatcher, $listeners);


$firewall = new \Symfony\Component\Security\Http\Firewall($map, $dispatcher);


$dispatcher->addListener(
    \Symfony\Component\HttpKernel\KernelEvents::REQUEST,
    array($firewall, 'onKernelRequest')
);

$kernel = new \BiiG\SecurityTest\Kernel($dispatcher, function() {
    echo "<h1>Hello</h1>";
});

$kernel->handle($request);