Created
May 21, 2020 06:51
-
-
Save ajgarlag/43ec84816d72bdd513dc238c0dba6de4 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 | |
/* composer.json | |
{ | |
"require": { | |
"symfony/security-core": ">=3.4" | |
} | |
} | |
*/ | |
require 'vendor/autoload.php'; | |
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; | |
use Symfony\Component\Security\Core\User\UserInterface; | |
class User implements UserInterface | |
{ | |
private const USERNAME = 'dummy'; | |
private const ROLE_DUMMY = 'ROLE_DUMMY'; | |
public function getUsername() | |
{ | |
return self::USERNAME; | |
} | |
public function getRoles() | |
{ | |
return [self::ROLE_DUMMY]; | |
} | |
public function getPassword() | |
{ | |
return null; | |
} | |
public function getSalt() | |
{ | |
return null; | |
} | |
public function eraseCredentials() | |
{ | |
return; | |
} | |
} | |
$user = new User(); | |
$token = new UsernamePasswordToken($user, null, uniqid(), ['ROLE_EXTRA']); | |
assert($token->isAuthenticated()); | |
echo 'Token is authenticated.' . PHP_EOL; | |
$token->setUser($user); | |
echo 'After setting the same user instance into the token,' . PHP_EOL; | |
echo ' the token should be still authenticated;' . PHP_EOL; | |
if ($token->isAuthenticated()) { | |
echo ' and token is still authenticated.' . PHP_EOL; | |
echo 'So you are using symfony/symfony <= 4.3' . PHP_EOL; | |
} else { | |
echo ' but token is not authenticated anymore.' . PHP_EOL; | |
echo 'So you are using symfony/symfony >= 4.4' . PHP_EOL; | |
} | |
assert($token->isAuthenticated()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment