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


PHP User\UserProviderInterface类代码示例

本文整理汇总了PHP中Symfony\Component\Security\Core\User\UserProviderInterface的典型用法代码示例。如果您正苦于以下问题:PHP UserProviderInterface类的具体用法?PHP UserProviderInterface怎么用?PHP UserProviderInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了UserProviderInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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

示例2: authenticateToken

 /**
  * @inheritdoc
  */
 public function authenticateToken(TokenInterface $token, UserProviderInterface $userProvider, $providerKey)
 {
     try {
         $user = $userProvider->loadUserByUsername($token->getUsername());
     } catch (UsernameNotFoundException $e) {
         throw new CustomUserMessageAuthenticationException('Invalid username or password');
     }
     $username = $token->getUsername();
     $password = $token->getCredentials();
     $sessionCreationResult = null;
     try {
         $sessionCreationResult = $this->userSessionRepository->createSessionIdByCredentials($username, $password);
     } catch (\InvalidArgumentException $e) {
         throw new CustomUserMessageAuthenticationException('Invalid username or password');
     } catch (RepositoryInfrastructureException $e) {
         throw new CustomUserMessageAuthenticationException('Cannot connect to Revive service');
     }
     $passwordValid = $sessionCreationResult !== null && UserSessionCreationAuthenticationResult::isSuccess($sessionCreationResult->getSessionCreationAuthenticationResult());
     if ($passwordValid) {
         $sessionId = $sessionCreationResult->getSessionId();
         $roles = [];
         $roles[] = 'USER';
         if (UserSessionCreationAuthorizationSessionCreationResult::isSuccess($sessionCreationResult->getSessionCreationAuthorizationSessionCreation())) {
             $roles[] = 'ADMIN';
         }
         $token = new ReviveAuthenticationToken($user, $sessionId, $providerKey, $roles);
         return $token;
     }
     throw new CustomUserMessageAuthenticationException('Invalid username or password');
 }
开发者ID:athlan,项目名称:revive-symfony-security-bundle,代码行数:33,代码来源:LoginFormAuthenticator.php

示例3: authenticateToken

 /**
  * Function used for user authentication based on token object
  *
  * @param  \Symfony\Component\Security\Core\Authentication\Token\TokenInterface        $token
  * @param  \Symfony\Component\Security\Core\User\UserProviderInterface                 $userProvider
  * @param  string                                                                      $providerKey
  * @return \Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken
  * @throws BadCredentialsException
  */
 public function authenticateToken(TokenInterface $token, UserProviderInterface $userProvider, $providerKey)
 {
     $passwordValid = false;
     // Load user object
     try {
         $user = $userProvider->loadUserByUsername($token->getUsername());
     } catch (UsernameNotFoundException $e) {
         throw new BadCredentialsException('Invalid username or password', 0, $e);
     }
     try {
         $this->userChecker->checkPreAuth($user);
         // Call the correct authentication method
         if (null !== $this->ldapManager && $user->isLdapEnabled()) {
             $passwordValid = $this->checkAuthenticationLdap($user, $token);
         } else {
             $passwordValid = $this->checkAuthentication($user, $token);
         }
         $this->userChecker->checkPostAuth($user);
     } catch (BadCredentialsException $e) {
         if ($this->hideUserNotFoundExceptions) {
             throw new BadCredentialsException('Invalid username or password', 0, $e);
         }
         throw $e;
     }
     // Set the authenticated token
     if ($passwordValid) {
         return new UsernamePasswordToken($user, $user->getPassword(), $providerKey, $user->getRoles());
     }
     throw new BadCredentialsException('Invalid username or password');
 }
开发者ID:hkmshb,项目名称:OpitHrm,代码行数:39,代码来源:LdapAuthenticator.php

示例4:

 function it_gets_user(UserProviderInterface $userProvider, UserCommandBus $commandBus, LogInUserCommand $credentials, User $user)
 {
     $commandBus->handle($credentials)->shouldBeCalled();
     $credentials->email()->shouldBeCalled()->willReturn('bengor@user.com');
     $userProvider->loadUserByUsername('bengor@user.com')->shouldBeCalled()->willReturn($user);
     $this->getUser($credentials, $userProvider)->shouldReturn($user);
 }
开发者ID:BenGorUser,项目名称:UserBundle,代码行数:7,代码来源:FormLoginAuthenticatorSpec.php

示例5: authenticateToken

 public function authenticateToken(TokenInterface $token, UserProviderInterface $userProvider, $providerKey)
 {
     $secret = $token->getCredentials();
     $userData = $this->session->getFlashBag()->get('arcanys_sso_auth.user_data');
     if ($userData) {
         // TODO create mapping config in the future
         $username = reset($userData['uid']);
         $email = reset($userData['email']);
         $firstname = reset($userData['firstname']);
         $lastname = reset($userData['lastname']);
         $token = reset($userData['token']);
         $roles = $userData['rights'];
         if (!$roles) {
             $roles = ['ROLE_USER'];
         }
     } else {
         $this->saml2->login();
         exit;
     }
     if (!$username) {
         throw new AuthenticationException("Failed to authenticate from SSO");
     }
     $user = $userProvider->loadUserByUsername(['username' => $username, 'email' => $email, 'firstname' => $firstname, 'lastname' => $lastname, 'token' => $token, 'roles' => $roles]);
     return new PreAuthenticatedToken($user, $secret, $providerKey, $user->getRoles($roles));
 }
开发者ID:arcanys,项目名称:SSO-user-provider-bundle,代码行数:25,代码来源:SSOAuthenticator.php

示例6: authenticateToken

 /**
  * Attempt to authenticate the provided token using the provided user provider.
  * @param TokenInterface $token
  * @param UserProviderInterface $userProvider
  * @param string $providerKey
  * @return UsernamePasswordToken
  * @throws BadCredentialsException
  */
 public function authenticateToken(TokenInterface $token, UserProviderInterface $userProvider, $providerKey)
 {
     if (($user = $userProvider->loadUserByUsername($token->getUsername())) && $user->getPassword() == $token->getCredentials()) {
         return new UsernamePasswordToken($user, $user->getPassword(), $providerKey, $user->getRoles());
     }
     throw new BadCredentialsException('The presented password is invalid.');
 }
开发者ID:mlukman,项目名称:securilex,代码行数:15,代码来源:PlaintextPasswordAuthenticationFactory.php

示例7: validateCookie

 /**
  * Validates WordPress authentication cookie
  *
  * @param UserProviderInterface $userProvider
  * @param Cookie $cookie
  * @return UserInterface UserInterface if valid.
  * @throws RuntimeException
  * @throws AuthenticationException
  */
 public function validateCookie(UserProviderInterface $userProvider, $cookie)
 {
     $cookieParts = $this->decodeCookie($cookie);
     switch (count($cookieParts)) {
         case 3:
             list($username, $expiration, $hmac) = $cookieParts;
             $token = null;
             break;
         case 4:
             list($username, $expiration, $token, $hmac) = $cookieParts;
             break;
         default:
             throw new AuthenticationException('Invalid WordPress cookie.');
     }
     if ($expiration < time()) {
         throw new AuthenticationException('The WordPress cookie has expired.');
     }
     try {
         $user = $userProvider->loadUserByUsername($username);
     } catch (Exception $exception) {
         if (!$exception instanceof AuthenticationException) {
             $exception = new AuthenticationException($exception->getMessage(), $exception->getCode(), $exception);
         }
         throw $exception;
     }
     if (!$user instanceof UserInterface) {
         throw new RuntimeException(sprintf('The UserProviderInterface implementation must return an instance of UserInterface, but returned "%s".', get_class($user)));
     }
     if ($token && $hmac !== $this->generateHmacWithToken($username, $expiration, $token, $user->getPassword()) || !$token && $hmac !== $this->generateHmac($username, $expiration, $user->getPassword())) {
         throw new AuthenticationException('The WordPress cookie\'s hash is invalid. Your logged in key and salt settings could be wrong.');
     }
     return $user;
 }
开发者ID:ninodafonte,项目名称:KayueWordpressBundle,代码行数:42,代码来源:AuthenticationCookieManager.php

示例8: getUser

 /**
  * Calls the UserProvider providing a valid User
  * @param array $credentials
  * @param UserProviderInterface $userProvider
  * @return bool
  */
 public function getUser($credentials, UserProviderInterface $userProvider)
 {
     if (isset($credentials[$this->username_attribute])) {
         return $userProvider->loadUserByUsername($credentials[$this->username_attribute]);
     } else {
         return null;
     }
 }
开发者ID:PRayno,项目名称:CasAuthBundle,代码行数:14,代码来源:CasAuthenticator.php

示例9: getUser

 /**
  * {@inheritdoc}
  */
 public function getUser($credentials, UserProviderInterface $userProvider)
 {
     try {
         return $userProvider->loadUserByUsername($credentials['username']);
     } catch (UsernameNotFoundException $e) {
         throw new CustomUserMessageAuthenticationException($this->translator->trans($this->failMessage));
     }
 }
开发者ID:busaev,项目名称:s3,代码行数:11,代码来源:FormAuthenticator.php

示例10: CustomUserMessageAuthenticationException

 function it_does_not_get_user_because_user_is_inactive(JWTEncoderInterface $jwtEncoder, UserProviderInterface $userProvider, User $user)
 {
     $jwtEncoder->decode('bearer-token')->shouldBeCalled()->willReturn(['email' => 'bengor@user.com']);
     $userProvider->loadUserByUsername('bengor@user.com')->shouldBeCalled()->willReturn($user);
     $user->confirmationToken = 'confirmation-token';
     $user->invitationToken = null;
     $this->shouldThrow(new CustomUserMessageAuthenticationException('The user does not exist'))->duringGetUser('bearer-token', $userProvider);
 }
开发者ID:BenGorUser,项目名称:UserBundle,代码行数:8,代码来源:JWTAuthenticatorSpec.php

示例11: authenticateToken

 public function authenticateToken(TokenInterface $token, UserProviderInterface $userProvider, $providerKey)
 {
     $user = $userProvider->loadUserByUsername($token->getUsername());
     if (!$user) {
         throw new AuthenticationException('User not found');
     }
     return new PreAuthenticatedToken($user, $token->getUsername(), $providerKey, $user->getRoles());
 }
开发者ID:ruslan-polutsygan,项目名称:dev-bundle,代码行数:8,代码来源:UserAuthenticator.php

示例12: getUser

 public function getUser($credentials, UserProviderInterface $userProvider)
 {
     try {
         $user = $userProvider->loadUserByUsername($credentials['username']);
         return $user;
     } catch (\Exception $ex) {
         throw new CustomUserMessageAuthenticationException("User was not found.");
     }
 }
开发者ID:jayrulez,项目名称:sf3,代码行数:9,代码来源:FormAuthenticator.php

示例13: authenticateToken

 public function authenticateToken(TokenInterface $token, UserProviderInterface $userProvider, $providerKey)
 {
     try {
         $user = $userProvider->loadUserByUsername($token->getUsername());
         return $this->authenticate($user, $token, $providerKey);
     } catch (UsernameNotFoundException $e) {
         return $this->getFromProviders($token, $providerKey);
     }
 }
开发者ID:ngydat,项目名称:CoreBundle,代码行数:9,代码来源:ExternalAuthenticator.php

示例14: supportsClass

 /**
  * Whether this provider supports the given user class.
  *
  * @param string $class
  *
  * @return bool
  */
 public function supportsClass($class)
 {
     if ($this->provider) {
         return $this->provider->supportsClass($class);
     }
     return false;
 }
开发者ID:timiki,项目名称:users-bundle,代码行数:14,代码来源:UsersProvider.php

示例15: 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


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