当前位置: 首页>>代码示例>>PHP>>正文


PHP UserProviderInterface::loadUserByUsername方法代码示例

本文整理汇总了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();
 }
开发者ID:timiki,项目名称:users-bundle,代码行数:21,代码来源:UsersProvider.php

示例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]);
 }
开发者ID:aegis-security,项目名称:JWTAuthenticationBundle,代码行数:15,代码来源:JWTProvider.php

示例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;
 }
开发者ID:mickaelsteinberg,项目名称:BackBee,代码行数:35,代码来源:UserAuthenticationProvider.php

示例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];
 }
开发者ID:mlukman,项目名称:securilex,代码行数:12,代码来源:UserProviderSegmentalizer.php

示例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.');
 }
开发者ID:qiyu2580,项目名称:php-wallet-sample,代码行数:35,代码来源:BlockCypherAuthenticationProvider.php

示例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;
     }
 }
开发者ID:NobletSolutions,项目名称:SecurityBundle,代码行数:13,代码来源:AdminAuthenticationProvider.php

示例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;
 }
开发者ID:rybakit,项目名称:KnpOAuthBundle,代码行数:12,代码来源:OAuthProvider.php

示例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.');
 }
开发者ID:snieditions,项目名称:rest-api,代码行数:13,代码来源:WsseProvider.php

示例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.');
 }
开发者ID:GCth,项目名称:crowd-auth-bundle,代码行数:10,代码来源:CrowdProvider.php

示例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;
 }
开发者ID:gobudgit,项目名称:gobudgit,代码行数:12,代码来源:CredentialVerifier.php

示例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;
 }
开发者ID:baszoetekouw,项目名称:janus,代码行数:12,代码来源:SspProvider.php

示例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.');
 }
开发者ID:cowtent,项目名称:cowtent-application,代码行数:17,代码来源:WsseProvider.php

示例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;
 }
开发者ID:shirone,项目名称:security-jwt-service-provider,代码行数:22,代码来源:JWTProvider.php

示例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');
 }
开发者ID:bluecloudy,项目名称:security-jwt-service-provider,代码行数:22,代码来源:JWTProvider.php

示例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.');
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:20,代码来源:WsseUserProvider.php


注:本文中的Symfony\Component\Security\Core\User\UserProviderInterface::loadUserByUsername方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。