1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
<?php
namespace CASManager\SecurityBundle\Security\User;
use Symfony\Component\Security\Core\User\UserProviderInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
use BeSimple\SsoAuthBundle\Security\Core\User\UserFactoryInterface;
class UserProvider implements UserProviderInterface,UserFactoryInterface
{
/**
* @var array
*/
private $roles;
/**
* Constructor.
*
* @param array $roles An array of roles
*/
public function __construct(array $roles = array())
{
$this->roles = $roles;
}
/**
* {@inheritdoc}
*/
public function loadUserByUsername($username)
{echo "ok";
//return $this->spawnUser($username);
return new User($username, null, $this->roles, true, true, true, true);
}
/**
* {@inheritDoc}
*/
public function refreshUser(UserInterface $user)
{
if (!$user instanceof User) {
throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', get_class($user)));
}
return $this->spawnUser($user->getUsername());
}
/**
* {@inheritDoc}
*/
public function supportsClass($class)
{
return $class === 'Symfony\Component\Security\Core\User\User';
}
/**
* Spawns a new user with given username.
*
* @param string $username
*
* @return \Symfony\Component\Security\Core\User\User
*/
private function spawnUser($username)
{
return new User($username, null, $this->roles, true, true, true, true);
}
public function createUser($username, array $roles, array $attributes)
{
return new User($username, null, $roles, true, true, true, true);
}
} |
Partager