本文整理汇总了PHP中Symfony\Component\Security\Core\User\UserProviderInterface::loadUserByUsername方法的典型用法代码示例。如果您正苦于以下问题:PHP UserProviderInterface::loadUserByUsername方法的具体用法?PHP UserProviderInterface::loadUserByUsername怎么用?PHP UserProviderInterface::loadUserByUsername使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Security\Core\User\UserProviderInterface
的用法示例。
在下文中一共展示了UserProviderInterface::loadUserByUsername方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadUserByUsername
/**
* Loads the user for the given username.
*
* This method must throw UsernameNotFoundException if the user is not
* found.
*
* @param string $username The username
*
* @return UserInterface
*
* @see UsernameNotFoundException
*
* @throws UsernameNotFoundException if the user is not found
*/
public function loadUserByUsername($username)
{
if ($this->provider) {
return $this->provider->loadUserByUsername($username);
}
throw new UsernameNotFoundException();
}
示例2: getUserFromPayload
/**
* Load user from payload, using username by default.
* Override this to load by another property.
*
* @param array $payload
*
* @return \Symfony\Component\Security\Core\User\UserInterface
*/
protected function getUserFromPayload(array $payload)
{
if (!isset($payload[$this->userIdentityField])) {
throw new AuthenticationException('Invalid JWT Token');
}
return $this->userProvider->loadUserByUsername($payload[$this->userIdentityField]);
}
示例3: authenticate
/**
* Authenticate a token according to the user provider.
*
* @param \Symfony\Component\Security\Core\Authentication\Token\TokenInterface $token
*
* @return \Symfony\Component\Security\Core\User\UserProviderInterface
*
* @throws SecurityException Occures on invalid connection
*/
public function authenticate(TokenInterface $token)
{
if (!$this->supports($token)) {
return;
}
$username = $token->getUsername();
if (empty($username)) {
$username = 'NONE_PROVIDED';
}
$user = $this->_userProvider->loadUserByUsername($username);
if (false === is_array($user)) {
$user = array($user);
}
$authenticatedToken = false;
while (false === $authenticatedToken) {
if (null !== ($provider = array_pop($user))) {
$authenticatedToken = $this->authenticateUser($token, $provider);
} else {
break;
}
}
if (false === $authenticatedToken) {
throw new SecurityException('Invalid authentication informations', SecurityException::INVALID_CREDENTIALS);
}
return $authenticatedToken;
}
示例4: loadUserByUsername
/**
* Get user from cached, otherwise get it from the source User Provider.
* @param string $username
* @return type
*/
public function loadUserByUsername($username)
{
if (!isset($this->cachedUsers[$username])) {
$this->cachedUsers[$username] = $this->userProvider->loadUserByUsername($username);
}
return $this->cachedUsers[$username];
}
示例5: authenticate
/**
* @param TokenInterface $token
* @return BlockCypherUserToken
*/
public function authenticate(TokenInterface $token)
{
// if (!$userProvider instanceof ApiKeyUserProvider) {
// throw new \InvalidArgumentException(
// sprintf(
// 'The user provider must be an instance of ApiKeyUserProvider (%s was given).',
// get_class($userProvider)
// )
// );
// }
//$blockCypherToken = null;
$blockCypherToken = $token->getCredentials();
$username = $blockCypherToken;
// DEBUG
//var_dump($blockCypherToken);
//die();
/** @var User $user */
$user = $this->userProvider->loadUserByUsername($username);
// DEBUG
//var_dump($user);
//die();
if ($user) {
$blockCypherToken = $user->getBlockCypherToken();
}
if ($user && $this->validateBlockCypherToken($blockCypherToken)) {
$authenticatedToken = new BlockCypherUserToken($user, $blockCypherToken, 'blockcypher', $user->getRoles());
//$authenticatedToken->setUser($user);
return $authenticatedToken;
}
throw new AuthenticationException('BlockCypher token empty or invalid.');
}
示例6: retrieveUser
/**
* @param string $username
* @param UsernamePasswordToken $token
* @return null|UserInterface
*/
public function retrieveUser($username, UsernamePasswordToken $token)
{
try {
return $this->userProvider->loadUserByUsername($username);
} catch (NoResultException $e) {
return null;
}
}
示例7: authenticate
/**
* {@inheritDoc}
*/
public function authenticate(TokenInterface $token)
{
$username = $this->oauthProvider->getUsername($token->getCredentials());
$user = $this->userProvider->loadUserByUsername($username);
$token = new OAuthToken($token->getCredentials(), $user->getRoles());
$token->setUser($user);
$token->setAuthenticated(true);
return $token;
}
示例8: authenticate
/**
* {@inheritdoc}
*/
public function authenticate(TokenInterface $token)
{
$user = $this->userProvider->loadUserByUsername($token->getUsername());
if ($user && $this->validateDigest($token->digest, $token->nonce, $token->created, $user->getPassword())) {
$authenticatedToken = new WsseToken($user->getRoles());
$authenticatedToken->setUser($user);
return $authenticatedToken;
}
throw new AuthenticationException('The WSSE authentication failed.');
}
示例9: authenticate
public function authenticate(TokenInterface $token)
{
$user = $this->userProvider->loadUserByUsername($token->getUsername());
if ($user && ($token->isAuthenticated() || $this->crowd->isauthenticationvalid($token->getUsername(), $token->getCredentials()))) {
$authenticatedToken = new CrowdToken($user->getRoles());
$authenticatedToken->setUser($user);
return $authenticatedToken;
}
throw new AuthenticationException('The Crowd authentication failed.');
}
示例10: __invoke
public function __invoke($username, $password)
{
try {
$user = $this->userProvider->loadUserByUsername($username);
} catch (UsernameNotFoundException $e) {
// in order to prevent timing attacks, we call the same method on a dummy user
// this way it is not revealed that the user by that username does not exist in DB
$this->passwordEncoder->isPasswordValid(AccountUser::dummy(), 'dummy');
return false;
}
return $this->passwordEncoder->isPasswordValid($user, $password) ? $username : false;
}
示例11: getTokenForUsername
private function getTokenForUsername($username, $attributes = array())
{
/** @var User $user */
$user = $this->userProvider->loadUserByUsername($username);
if (!$user) {
throw new AuthenticationException("No user by the name of '{$username}'");
}
$token = new SspToken($user->getRoles());
$token->setUser($user);
$token->setAttributes($attributes);
return $token;
}
示例12: authenticate
/**
* @param TokenInterface $token
*
* @return WsseUserToken
*/
public function authenticate(TokenInterface $token)
{
/** @var WsseUserToken $token */
$user = $this->userProvider->loadUserByUsername($token->getUsername());
$secret = $user->getApiKey() . '{' . $user->getSalt() . '}';
if ($this->validateDigest($token->digest, $token->nonce, $token->created, $secret)) {
$authenticatedToken = new WsseUserToken($user->getRoles());
$authenticatedToken->setUser($user);
return $authenticatedToken;
}
throw new AuthenticationException('The WSSE authentication failed.');
}
示例13: authenticate
/**
* Attempts to authenticate a TokenInterface object.
*
* @param TokenInterface $token The TokenInterface instance to authenticate
*
* @return TokenInterface An authenticated TokenInterface instance, never null
*
* @throws AuthenticationException if the authentication fails
*/
public function authenticate(TokenInterface $token)
{
if (!$this->supports($token)) {
return;
}
if (!($user = $token->getUser())) {
throw new AuthenticationException('JWT auth failed');
}
$user = $this->userProvider->loadUserByUsername($user);
$this->userChecker->checkPostAuth($user);
$token = new JWTToken($user, $token->getCredentials(), $this->providerKey, $this->getRoles($user, $token));
return $token;
}
示例14: authenticate
/**
* Attempts to authenticate a TokenInterface object.
*
* @param TokenInterface $token The TokenInterface instance to authenticate
*
* @return TokenInterface An authenticated TokenInterface instance, never null
*
* @throws AuthenticationException if the authentication fails
*/
public function authenticate(TokenInterface $token)
{
$userName = $token->getUsername();
$user = $this->userProvider->loadUserByUsername($userName);
if (null != $user) {
$lastContext = $token->getTokenContext();
$token = new JWTToken($user->getRoles());
$token->setTokenContext($lastContext);
$token->setUser($user);
return $token;
}
throw new AuthenticationException('JWT auth failed');
}
示例15: authenticate
/**
* Authenticate API user by API key
*
* @param TokenInterface $token
* @return Token
* @throws AuthenticationException
*/
public function authenticate(TokenInterface $token)
{
$user = $this->userProvider->loadUserByUsername($token->getUsername());
if ($user && $user->getApi()) {
if ($this->validateDigest($token->getAttribute('digest'), $token->getAttribute('nonce'), $token->getAttribute('created'), $user->getApi()->getApiKey(), $user->getSalt())) {
$authToken = new Token($user->getRoles());
$authToken->setUser($user);
$authToken->setAuthenticated(true);
return $authToken;
}
}
throw new AuthenticationException('WSSE authentication failed.');
}