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


PHP TokenInterface::getUsername方法代码示例

本文整理汇总了PHP中Symfony\Component\Security\Core\Authentication\Token\TokenInterface::getUsername方法的典型用法代码示例。如果您正苦于以下问题:PHP TokenInterface::getUsername方法的具体用法?PHP TokenInterface::getUsername怎么用?PHP TokenInterface::getUsername使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\Security\Core\Authentication\Token\TokenInterface的用法示例。


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

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

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

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

示例4: authenticate

 /**
  * @param TokenInterface $token
  * @return WsseToken|TokenInterface
  */
 public function authenticate(TokenInterface $token)
 {
     $user = $this->userProvider->loadUserByUsername($token->getUsername());
     if ($user && $this->validateDigest($token->getAttribute('digest'), $token->getAttribute('nonce'), $token->getAttribute('created'), $this->getSecret($user), $this->getSalt($user), $user)) {
         $authenticatedToken = new WsseToken($user->getRoles());
         $authenticatedToken->setUser($user);
         $authenticatedToken->setAuthenticated(true);
         return $authenticatedToken;
     }
     $this->logger->error(sprintf('Attempt of unauthorized access for user: %s', $token->getUsername()));
     throw new AuthenticationException(' Incorrect email or password.');
 }
开发者ID:gitter-badger,项目名称:diamantedesk-application,代码行数:16,代码来源:WsseProvider.php

示例5: authenticateToken

 /**
  * @param TokenInterface $token
  * @param UserProviderInterface $userProvider
  * @param $providerKey
  * @throw AuthenticationException
  * @thorw BadCredentialsException
  * @return UsernamePasswordToken
  */
 public function authenticateToken(TokenInterface $token, UserProviderInterface $userProvider, $providerKey)
 {
     try {
         $user = $userProvider->loadUserByUsername($token->getUsername());
     } catch (UsernameNotFoundException $e) {
         throw new AuthenticationException(sprintf('Can\'t find user by "%s" username', $token->getUsername()));
     }
     if (true === $this->pamAuth($token->getUsername(), $token->getCredentials())) {
         return new UsernamePasswordToken($user, $user->getPassword(), $providerKey, in_array($user->getUsername(), $this->rootUsers) ? ['ROLE_USER', 'ROLE_ADMIN'] : ['ROLE_USER']);
     }
     throw new BadCredentialsException('Bad credentials', 403);
 }
开发者ID:spolischook,项目名称:ylang-ylang,代码行数:20,代码来源:PamAuthenticator.php

示例6: authenticate

 public function authenticate(TokenInterface $token)
 {
     $user = $this->userProvider->loadUserByUsername($token->getUsername());
     if ($user) {
         if ($this->validateDigest((string) $token->digest, $token->getUsername(), $token->nonce, $token->created, $user->getAuthSecret())) {
             $authenticatedToken = new WsseUserToken(array('IS_AUTHENTICATED'));
             $authenticatedToken->setUser($user);
             $authenticatedToken->setAuthenticated(TRUE);
             return $authenticatedToken;
         }
     }
     throw new AuthenticationException('The WSSE authentication failed.');
 }
开发者ID:richsage,项目名称:MjhWsseBundle,代码行数:13,代码来源:WsseProvider.php

示例7: onAuthenticationSuccess

 /**
  * {@inheritdoc}
  */
 public function onAuthenticationSuccess(Request $request, TokenInterface $token)
 {
     if ($request->isXmlHttpRequest()) {
         return new JsonResponse(['success' => true, 'username' => $token->getUsername()]);
     }
     return parent::onAuthenticationSuccess($request, $token);
 }
开发者ID:okwinza,项目名称:Sylius,代码行数:10,代码来源:AuthenticationSuccessHandler.php

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

示例9: onAuthenticationSuccess

 /**
  * 
  * @param Request $request
  * @param Response $response
  * @param TokenInterface $token
  * @return void
  */
 public function onAuthenticationSuccess(Request $request, TokenInterface $token)
 {
     //trigger_error(var_export($token->getUsername() , 1));
     $this->em->getRepository('SportnetzwerkSpnBundle:Player')->updateOnlineFlag($token->getUsername(), 1);
     //kdos: must have when using an ajax login
     return new JsonResponse(array('data' => 'Credentials ok'), 200);
 }
开发者ID:kotscho,项目名称:sportnetzwerk,代码行数:14,代码来源:LoginHandler.php

示例10: authenticate

 public function authenticate(TokenInterface $token)
 {
     if (strlen($token->getOAuthToken()) === 0) {
         $url = $this->remoteApiUrl . "/oauth/v2/token?" . "client_id=" . $this->remoteApiId . "&client_secret=" . $this->remoteApiSecret . "&grant_type=password" . "&username=" . $token->getUser() . "&password=" . $token->getPassword();
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         $apiResponse = json_decode(curl_exec($ch));
         curl_close($ch);
         if (isset($apiResponse->access_token)) {
             $user = $this->userManager->createUser();
             $user->setUsername($token->getUsername());
             $authenticatedToken = new OAuthUserToken($user->getRoles());
             $authenticatedToken->setUser($user);
             $authenticatedToken->setOAuthToken($apiResponse->access_token);
             $authenticatedToken->setRefreshToken($apiResponse->refresh_token);
             $authenticatedToken->setTokenType($apiResponse->token_type);
             // We take 3 minutes less (180 seconds) just to be sure.
             $authenticatedToken->setExpireTime(time() + $apiResponse->expires_in - 180);
             return $authenticatedToken;
         } elseif (isset($apiResponse->error_description)) {
             throw new AuthenticationException($apiResponse->error_description);
         } else {
             throw new AuthenticationException('The OAuth authentication failed.');
         }
     } else {
         return $token;
     }
 }
开发者ID:bankette,项目名称:OAuth_Password_Client,代码行数:29,代码来源:OAuthProvider.php

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

示例12: onAuthenticationSuccess

 /**
  * {@inheritDoc}
  */
 public function onAuthenticationSuccess(Request $request, TokenInterface $token)
 {
     if ($request->isXmlHttpRequest()) {
         $json = array('ok' => true, 'username' => $token->getUsername());
         return new \Symfony\Component\HttpFoundation\JsonResponse($json);
     }
     return parent::onAuthenticationSuccess($request, $token);
 }
开发者ID:symforce,项目名称:symforce-user,代码行数:11,代码来源:AjaxAuthenticationSuccessHandler.php

示例13: authenticate

 public function authenticate(TokenInterface $token)
 {
     if ($token->getUsername() == 'new_user_registration') {
         return $token;
     } else {
         $this->user = $this->userProvider->loadUserByUsername(array($token->getUsername()));
         if ($this->user) {
             $plainUserPassword = base64_decode($token->encryptedPass);
             if ($this->_hash_equals(crypt($plainUserPassword, $this->user->getSalt()), $this->user->getPassword())) {
                 $authenticatedToken = new CustomAuthToken($this->user->getRoles());
                 $authenticatedToken->setUser($this->user);
                 return $authenticatedToken;
             }
         }
     }
     throw new AuthenticationException('Authentication failed.');
 }
开发者ID:syedomair,项目名称:SymfonyAPIProject,代码行数:17,代码来源:CustomAuthProvider.php

示例14: authenticateToken

 /**
  * @param TokenInterface $token
  * @param UserProviderInterface $userProvider
  * @param $providerKey
  * @return UsernamePasswordToken
  */
 public function authenticateToken(TokenInterface $token, UserProviderInterface $userProvider, $providerKey)
 {
     $user = $userProvider->loadUserByUsername($token->getUsername());
     $params = ["client_id" => $this->config['client_id'], "client_secret" => $this->config['client_secret'], "email" => $token->getUsername(), "password" => $token->getCredentials()];
     try {
         $storage = $this->emailTokenProvider->authentificate($this->config['endpoint'], $params, $this->config['grant']);
     } catch (BadAuthentificationException $e) {
         // CAUTION: this message will be returned to the client
         // (so don't put any un-trusted messages / error strings here)
         throw new CustomUserMessageAuthenticationException('Invalid credentials');
     }
     $emailToken = new EmailToken($user, $user->getPassword(), $providerKey, $user->getRoles());
     $emailToken->setAccessToken($storage['accessToken']);
     $emailToken->setRefreshToken($storage['refreshToken']);
     $emailToken->setExpiresIn($storage['expiresIn']);
     return $emailToken;
 }
开发者ID:NathanVss,项目名称:oauth-extension-bundle,代码行数:23,代码来源:EmailAuthenticator.php

示例15: 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  type                                                                        $providerKey
  * @return \Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken
  * @throws BadCredentialsException
  */
 public function authenticateToken(TokenInterface $token, UserProviderInterface $userProvider, $providerKey)
 {
     $passwordValid = false;
     // Loda user object
     try {
         $user = $userProvider->loadUserByUsername($token->getUsername());
     } catch (UsernameNotFoundException $e) {
         throw new BadCredentialsException('Invalid username or password', 0, $e);
     }
     // Check if ldap extension is enabled and user's ldap flag is set.
     if (null !== $this->ldapManager && $user->isLdapEnabled()) {
         try {
             $this->ldapManager->bind($token->getUsername(), $token->getCredentials());
             $passwordValid = (bool) $this->ldapManager->getBoundUser();
             if (null !== $this->logger && !$token->isAuthenticated()) {
                 $this->logger->info("[LdapAuthenticator] Ldap authentication successful.", array('user' => $this->ldapManager->getBoundUser()));
             }
         } catch (\Zend\Ldap\Exception\LdapException $e) {
             throw new BadCredentialsException('Invalid username or password', 0, $e);
         }
     } else {
         $currentUser = $token->getUser();
         if ($currentUser instanceof UserInterface) {
             if ($currentUser->getPassword() !== $user->getPassword()) {
                 throw new BadCredentialsException('The credentials were changed from another session.');
             } else {
                 $passwordValid = true;
             }
         } else {
             if ("" === ($presentedPassword = $token->getCredentials())) {
                 throw new BadCredentialsException('Invalid username or password.');
             }
             if (!($passwordValid = $this->encoderFactory->getEncoder($user)->isPasswordValid($user->getPassword(), $presentedPassword, $user->getSalt()))) {
                 throw new BadCredentialsException('Invalid username or password.');
             }
         }
         if (null !== $this->logger && !$token->isAuthenticated()) {
             $this->logger->info("[LdapAuthenticator] Local authentication successful.", array('user' => $user->getUsername()));
         }
     }
     // Set the authenticated token
     if ($passwordValid) {
         return new UsernamePasswordToken($user, $user->getPassword(), $providerKey, $user->getRoles());
     }
     throw new BadCredentialsException('Invalid username or password');
 }
开发者ID:joeflack4,项目名称:OpitHrm,代码行数:55,代码来源:LdapAuthenticator.php


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