Last active
September 27, 2015 09:30
-
-
Save wouterj/536eb7467aade085d24b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$authenticator = new AuthenticationProviderManager([ | |
new DaoAuthenticationProvider( | |
new InMemoryUserProvider([ | |
'wouter' => ['password' => 'test', 'roles' => ['ROLE_USER']] | |
]), | |
new UserChecker(), | |
'cli', | |
new EncoderFactory([ | |
User::class => new PlaintextPasswordEncoder(), | |
]) | |
) | |
]); | |
$tokenStorage = new TokenStorage(); | |
$token = new UsernamePasswordToken( | |
$event->getInput()->getArgument('user'), | |
$event->getInput()->getOption('pass'), | |
'cli' | |
); | |
$tokenStorage->setToken($authenticator->authenticate($token)); | |
$accessDecisionManager = new AccessDecisionManager([new RoleVoter()]); | |
$authorizationChecker = new AuthorizationChecker( | |
$tokenStorage, | |
$authenticator, | |
$accessDecisionManager | |
); | |
if (!$this->authorizationChecker->isGranted('ROLE_USER')) { | |
throw new AccessDeniedException(); | |
} | |
// ... show something secret, the user is now logged in |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment