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


PHP UsernamePasswordToken::getCredentials方法代码示例

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


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

示例1: retrieveUser

 /**
  * {@inheritdoc}
  */
 protected function retrieveUser($username, UsernamePasswordToken $token)
 {
     $user = $token->getUser();
     if ($user instanceof UserInterface) {
         return $user;
     }
     try {
         if ($this->getAuthService()->hasPartnerAuth()) {
             try {
                 $user = $this->userProvider->loadUserByUsername($username);
                 $bind = $this->getUserService()->getUserBindByTypeAndUserId($this->getAuthService()->getPartnerName(), $user['id']);
                 if ($bind) {
                     $partnerUser = $this->getAuthService()->checkPartnerLoginById($bind['fromId'], $token->getCredentials());
                     if ($partnerUser) {
                         $user = $this->syncEmailAndPassword($user, $partnerUser, $token);
                     }
                 }
             } catch (UsernameNotFoundException $notFound) {
                 if (filter_var($username, FILTER_VALIDATE_EMAIL)) {
                     $partnerUser = $this->getAuthService()->checkPartnerLoginByEmail($username, $token->getCredentials());
                 } else {
                     $partnerUser = $this->getAuthService()->checkPartnerLoginByNickname($username, $token->getCredentials());
                 }
                 if (empty($partnerUser)) {
                     throw $notFound;
                 }
                 $bind = $this->getUserService()->getUserBindByTypeAndFromId($this->getAuthService()->getPartnerName(), $partnerUser['id']);
                 if ($bind) {
                     $user = $this->getUserService()->getUser($bind['toId']);
                     $user = $this->syncEmailAndPassword($user, $partnerUser, $token);
                 } else {
                     $setting = $this->getSettingService()->get('user_partner', array());
                     $email_filter = explode("\n", $setting['email_filter']);
                     if (in_array($partnerUser['email'], $email_filter)) {
                         $partnerUser['email'] = $partnerUser['id'] . '_dz_' . $this->getRandomString(5) . '@edusoho.net';
                     }
                     $registration = array();
                     $registration['nickname'] = $partnerUser['nickname'];
                     $registration['email'] = $partnerUser['email'];
                     $registration['password'] = $token->getCredentials();
                     $registration['createdIp'] = $partnerUser['createdIp'];
                     $registration['token'] = array('userId' => $partnerUser['id']);
                     $this->getUserService()->register($registration, $this->getAuthService()->getPartnerName());
                     $user = $this->userProvider->loadUserByUsername($username);
                 }
             }
         } else {
             $user = $this->userProvider->loadUserByUsername($username);
         }
         if (!$user instanceof UserInterface) {
             throw new AuthenticationServiceException('The user provider must return a UserInterface object.');
         }
         return $user;
     } catch (UsernameNotFoundException $notFound) {
         $notFound->setUsername($username);
         throw $notFound;
     } catch (\Exception $repositoryProblem) {
         $ex = new AuthenticationServiceException($repositoryProblem->getMessage(), 0, $repositoryProblem);
         $ex->setToken($token);
         throw $ex;
     }
 }
开发者ID:styling,项目名称:LeesPharm,代码行数:65,代码来源:AuthenticationProvider.php

示例2: checkAuthentication

 /**
  * {@inheritdoc}
  */
 protected function checkAuthentication(UserInterface $user, UsernamePasswordToken $token)
 {
     $currentUser = $token->getUser();
     if ($currentUser instanceof UserInterface) {
         if ($currentUser->getPassword() !== $user->getPassword()) {
             throw new BadCredentialsException('The credentials were changed from another session.');
         }
     } else {
         if (!($presentedPassword = $token->getCredentials())) {
             throw new BadCredentialsException('The presented password cannot be empty.');
         }
         if ($user instanceof User) {
             $encoder = $this->encoderFactory->getEncoder($user);
             if (!$encoder->isPasswordValid($user->getPassword(), $presentedPassword, $user->getSalt())) {
                 throw new BadCredentialsException('The presented password is invalid.');
             }
         } else {
             $ldap = new Ldap($this->params['host'], $this->params['port'], $this->params['version']);
             $bind = $ldap->bind($user->getUsername(), $presentedPassword);
             $this->logger->debug(sprintf('LDAP bind with username "%s" and password "%s" yielded: %s', $user->getUsername(), $presentedPassword, print_r($bind, true)));
             if (!$bind) {
                 throw new BadCredentialsException('The presented password is invalid.');
             }
             // There's likely more data in the LDAP result now after a successful bind
             $this->userProvider->refreshUser($user);
         }
     }
 }
开发者ID:mapbender,项目名称:fom,代码行数:31,代码来源:LdapAuthenticationProvider.php

示例3: authUserFromRedmine

 public function authUserFromRedmine(UsernamePasswordToken $token)
 {
     $pass = $token->getCredentials();
     $username = $token->getUser();
     try {
         $response = $this->client->redmineLogin($username, $pass);
         $q = json_decode($response);
         $em = $this->em;
         $user = $em->getRepository("RedmineAppBundle:RedmineUser")->findOneBy(['redmineToken' => $q->user->api_key, 'redmineUserID' => $q->user->id]);
         if ($user) {
             return $user->getUsername();
         } else {
             $user = new RedmineUser();
             $user->setUsername($q->user->login)->setEmail($q->user->mail)->setPassword($this->encoder->encodePassword($user, md5(uniqid())))->setName($q->user->firstname)->setSurname($q->user->lastname)->setRedmineUserID($q->user->id)->setRedmineToken($q->user->api_key);
             $settings = new Settings();
             $settings->setSms(false)->setPush(false)->setCheckFirst(Carbon::createFromTime(17, 45))->setCheckSecond(Carbon::createFromTime(20, 0))->setCheckThird(Carbon::createFromTime(9, 30))->setUser($user);
             $this->em->persist($user);
             $this->em->persist($settings);
             $this->em->flush();
             return $user->getUsername();
         }
     } catch (\Exception $e) {
         return null;
     }
 }
开发者ID:ekreative,项目名称:redmine-time-tracker,代码行数:25,代码来源:RedmineUserProvider.php

示例4: checkAuthentication

 /**
  * {@inheritdoc}
  */
 protected function checkAuthentication(UserInterface $user, UsernamePasswordToken $token)
 {
     $currentUser = $token->getUser();
     if ($currentUser instanceof UserInterface) {
         if ($currentUser->getPassword() !== $user->getPassword()) {
             throw new BadCredentialsException('The credentials were changed from another session.');
         }
     } else {
         if (!($presentedPassword = $token->getCredentials())) {
             throw new BadCredentialsException('The presented password cannot be empty.');
         }
         $client = $this->clientFactory->build('en');
         $request = CustomerLoginRequest::ofEmailAndPassword($token->getUser(), $presentedPassword);
         $response = $request->executeWithClient($client);
         if ($response->isError()) {
             throw new BadCredentialsException('The presented password is invalid.');
         }
         $result = $request->mapResponse($response);
         $customer = $result->getCustomer();
         if ($currentUser !== $customer->getEmail()) {
             throw new BadCredentialsException('The presented password is invalid.');
         }
         $this->session->set('customer.id', $customer->getId());
     }
 }
开发者ID:sphereio,项目名称:commercetools-sunrise-php,代码行数:28,代码来源:CTPAuthenticationProvider.php

示例5: checkAuthentication

 /**
  * {@inheritdoc}
  */
 protected function checkAuthentication(UserInterface $user, UsernamePasswordToken $token)
 {
     $password = $token->getCredentials();
     if ($password === null || $password === '') {
         throw new BadCredentialsException('The presented password is invalid.');
     }
     return parent::checkAuthentication($user, $token);
 }
开发者ID:LenticularCloud,项目名称:Cloud-Ldap-Admin,代码行数:11,代码来源:LdapBindAuthenticationProvider.php

示例6: authenticate

 public function authenticate(TokenInterface $token)
 {
     if ($this->code != $token->getCredentials()) {
         throw new AuthenticationException("Authentication code does not match");
     }
     $user = $token->getUser();
     // TODO: Provide a mechanism to get the real user object, and set user roles in token
     $token = new UsernamePasswordToken($user, $token->getCredentials(), $this->name, ['ROLE_USER']);
     return $token;
 }
开发者ID:apiaryhq,项目名称:silex-sms-login-provider,代码行数:10,代码来源:SmsAuthenticator.php

示例7: checkAuthentication

 /**
  * {@inheritdoc}
  */
 protected function checkAuthentication(UserInterface $user, UsernamePasswordToken $token)
 {
     $password = $token->getCredentials();
     try {
         $username = $user->getUsername();
         $this->ldap->bind($username, $password);
     } catch (ConnectionException $e) {
         throw new BadCredentialsException('The presented password is invalid.');
     }
 }
开发者ID:cilefen,项目名称:symfony,代码行数:13,代码来源:LdapBindAuthenticationProvider.php

示例8: retrieveUser

 /**
  * {@inheritdoc}
  */
 protected function retrieveUser($username, UsernamePasswordToken $token)
 {
     $repository = $this->getRepository();
     try {
         $apiUser = $repository->getUserService()->loadUserByCredentials($username, $token->getCredentials());
         $repository->setCurrentUser($apiUser);
         return new User($apiUser);
     } catch (NotFoundException $e) {
         throw new AuthenticationException('Authentication to eZ Publish failed', $e->getCode(), $e);
     }
 }
开发者ID:brookinsconsulting,项目名称:ezecosystem,代码行数:14,代码来源:BasicAuthProvider.php

示例9: checkAuthentication

 /**
  * {@inheritdoc}
  */
 protected function checkAuthentication(UserInterface $user, UsernamePasswordToken $token)
 {
     $username = $token->getUsername();
     $password = $token->getCredentials();
     try {
         $username = $this->ldap->escape($username, '', LDAP_ESCAPE_DN);
         $dn = str_replace('{username}', $username, $this->dnString);
         $this->ldap->bind($dn, $password);
     } catch (ConnectionException $e) {
         throw new BadCredentialsException('The presented password is invalid.');
     }
 }
开发者ID:zorn-v,项目名称:symfony,代码行数:15,代码来源:LdapBindAuthenticationProvider.php

示例10: checkAuthentication

 public function checkAuthentication(UserInterface $user, UsernamePasswordToken $token)
 {
     $connector = new Connector($user->getUsername(), $token->getCredentials());
     if (!$connector->isSignedIn()) {
         throw new BadCredentialsException();
     }
     $student = $connector->getStudent();
     $user->fromStudent($student);
     $user->setLastConnectionAt(new \DateTime());
     if ($user->getId() == null || $user->getAccount() == null) {
         $user->setAccount(new Account());
     }
     $this->em->persist($user);
     $this->em->flush();
 }
开发者ID:Raphy,项目名称:AfterEpi,代码行数:15,代码来源:AuthenticationProvider.php

示例11: checkAuthentication

 /**
  * {@inheritdoc}
  */
 protected function checkAuthentication(UserInterface $user, UsernamePasswordToken $token)
 {
     $currentUser = $token->getUser();
     if ($currentUser instanceof UserInterface) {
         if ($currentUser->getPassword() !== $user->getPassword()) {
             throw new BadCredentialsException('The credentials were changed from another session.');
         }
     } else {
         if ('' === ($presentedPassword = $token->getCredentials())) {
             throw new BadCredentialsException('The presented password cannot be empty.');
         }
         if (!$this->encoderFactory->getEncoder($user)->isPasswordValid($user->getPassword(), $presentedPassword, $user->getSalt())) {
             throw new BadCredentialsException('The presented password is invalid.');
         }
     }
 }
开发者ID:scrobot,项目名称:Lumen,代码行数:19,代码来源:DaoAuthenticationProvider.php

示例12: retrieveUser

 /**
  * {@inheritdoc}
  */
 protected function retrieveUser($username, UsernamePasswordToken $token)
 {
     $user = $token->getUser();
     if ($user instanceof UserInterface) {
         return $user;
     }
     try {
         $user = $this->userProvider->loadUserByUsernameAndPassword($username, $token->getCredentials());
         if (!$user instanceof UserInterface) {
             throw new AuthenticationServiceException('The user provider must return a UserInterface object.');
         }
         return $user;
     } catch (UsernameNotFoundException $notFound) {
         throw $notFound;
     }
 }
开发者ID:lcstudios,项目名称:ldap-bundle,代码行数:19,代码来源:LdapAuthenticationProvider.php

示例13: checkAuthentication

 /**
  * {@inheritdoc}
  */
 protected function checkAuthentication(AccountInterface $account, UsernamePasswordToken $token)
 {
     $user = $token->getUser();
     if ($user instanceof AccountInterface) {
         if ($account->getPassword() !== $user->getPassword()) {
             throw new BadCredentialsException('The credentials were changed from another session.');
         }
     } else {
         if (!($presentedPassword = (string) $token->getCredentials())) {
             throw new BadCredentialsException('Bad credentials');
         }
         if (!$this->encoderFactory->getEncoder($account)->isPasswordValid($account->getPassword(), $presentedPassword, $account->getSalt())) {
             throw new BadCredentialsException('Bad credentials');
         }
     }
 }
开发者ID:faridos,项目名称:ServerGroveLiveChat,代码行数:19,代码来源:DaoAuthenticationProvider.php

示例14: handle

 /**
  * {@inheritdoc}
  */
 public function handle(Request $request, ClientInterface $client)
 {
     $username = $request->request->get('username');
     $password = $request->request->get('password');
     $scope = $request->request->get('scope');
     if (empty($username)) {
         throw new OAuthInvalidRequestException('Missing username parameter.');
     }
     if (empty($password)) {
         throw new OAuthInvalidRequestException('Missing password parameter.');
     }
     $user = $this->userProvider->loadUserByUsername($username);
     $token = new UsernamePasswordToken($username, $password, $this->providerKey);
     if (!$this->encoderFactory->getEncoder($user)->isPasswordValid($user->getPassword(), $token->getCredentials(), $user->getSalt())) {
         throw new OAuthInvalidRequestException('Bad credentials.');
     }
     $accessToken = $this->accessTokenProvider->create($user, $client, $scope);
     $data = ['access_token' => $accessToken->getId(), 'token_type' => 'bearer', 'expires_in' => $accessToken->getExpires()];
     return new Response(json_encode($data), 200, ['Content-Type' => 'application/json;charset=UTF-8', 'Cache-Control' => 'no-store', 'Pragma' => 'no-cache']);
 }
开发者ID:euskadi31,项目名称:OAuth2ServerServiceProvider,代码行数:23,代码来源:PasswordGrantType.php

示例15: checkAuthentication

 /**
  * {@inheritdoc}
  */
 protected function checkAuthentication(UserInterface $user, UsernamePasswordToken $token)
 {
     $currentUser = $token->getUser();
     $presentedPassword = $token->getCredentials();
     if ($currentUser instanceof UserInterface) {
         if ('' === $presentedPassword) {
             throw new BadCredentialsException('The password in the token is empty. You may forgive turn off `erase_credentials` in your `security.yml`');
         }
         if (!$this->ldapManager->bind($currentUser, $presentedPassword)) {
             throw new BadCredentialsException('The credentials were changed from another session.');
         }
     } else {
         if ('' === $presentedPassword) {
             throw new BadCredentialsException('The presented password cannot be empty.');
         }
         if (!$this->ldapManager->bind($user, $presentedPassword)) {
             throw new BadCredentialsException('The presented password is invalid.');
         }
     }
 }
开发者ID:Mapaxe,项目名称:FR3DLdapBundle,代码行数:23,代码来源:LdapAuthenticationProvider.php


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