當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Token\UsernamePasswordToken類代碼示例

本文整理匯總了PHP中Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken的典型用法代碼示例。如果您正苦於以下問題:PHP UsernamePasswordToken類的具體用法?PHP UsernamePasswordToken怎麽用?PHP UsernamePasswordToken使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了UsernamePasswordToken類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: authenticate

 /**
  * {@inheritdoc}
  */
 public function authenticate(TokenInterface $token)
 {
     if (!$this->supports($token)) {
         return;
     }
     $username = $token->getUsername();
     if (empty($username)) {
         $username = 'NONE_PROVIDED';
     }
     try {
         $user = $this->retrieveUser($username, $token);
     } catch (UsernameNotFoundException $notFound) {
         if ($this->hideUserNotFoundExceptions) {
             throw new BadCredentialsException('Bad credentials', 0, $notFound);
         }
         $notFound->setUsername($username);
         throw $notFound;
     }
     if (!$user instanceof UserInterface) {
         throw new AuthenticationServiceException('retrieveUser() must return a UserInterface.');
     }
     try {
         $this->userChecker->checkPreAuth($user);
         $this->checkAuthentication($user, $token);
         $this->userChecker->checkPostAuth($user);
     } catch (BadCredentialsException $e) {
         if ($this->hideUserNotFoundExceptions) {
             throw new BadCredentialsException('Bad credentials', 0, $e);
         }
         throw $e;
     }
     $authenticatedToken = new UsernamePasswordToken($user, $token->getCredentials(), $this->providerKey, $this->getRoles($user, $token));
     $authenticatedToken->setAttributes($token->getAttributes());
     return $authenticatedToken;
 }
開發者ID:GeorgeBroadley,項目名稱:caffeine-vendor,代碼行數:38,代碼來源:UserAuthenticationProvider.php

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

示例3: testUserBlame

 public function testUserBlame()
 {
     $context = $this->getContainer()->get('security.context');
     $token = new UsernamePasswordToken('test', 'test', 'test_provider', []);
     $user = new User();
     $user->setUsername('dantleech');
     $user->setPassword('foo');
     $user->setLocale('fr');
     $user->setSalt('saltz');
     $this->db('ORM')->getOm()->persist($user);
     $this->db('ORM')->getOm()->flush();
     $token->setUser($user);
     $context->setToken($token);
     $contact = new Contact();
     $contact->setFirstName('Max');
     $contact->setLastName('Mustermann');
     $contact->setPosition('CEO');
     $contact->setSalutation('Sehr geehrter Herr Dr Mustermann');
     $this->db('ORM')->getOm()->persist($contact);
     $this->db('ORM')->getOm()->flush();
     $changer = $contact->getChanger();
     $creator = $contact->getCreator();
     $this->assertSame($changer, $user);
     $this->assertSame($creator, $user);
 }
開發者ID:ollietb,項目名稱:sulu,代碼行數:25,代碼來源:UserBlameSubscriberIntegrationTest.php

示例4: setUp

 public function setUp()
 {
     $this->voter = new ProfileVoter();
     $this->token = new UsernamePasswordToken('testuser', 'password', 'public');
     $this->user = new User();
     $this->token->setUser($this->user);
 }
開發者ID:dstansby,項目名稱:camdram,代碼行數:7,代碼來源:ProfileVoterTest.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: features_for_user

 public function features_for_user($user)
 {
     $token = new UsernamePasswordToken($user->getUsername(), null, 'main', $user->getRoles());
     $token->setUser($user);
     $ret = array();
     foreach ($this->supported_features as $attribute) {
         $ret[$attribute] = $this->voteOnAttribute($attribute, null, $token);
     }
     return $ret;
 }
開發者ID:Markobaa,項目名稱:stoerungsmelder,代碼行數:10,代碼來源:FeatureVoter.php

示例9: buildASession

 private final function buildASession($session, $repository)
 {
     $user = $this->provider->loadUserByToken($session, $repository);
     if ($user) {
         $authenticatedToken = new UsernamePasswordToken($user, $session, 'front', ['ROLE_USER']);
         $authenticatedToken->setUser($user);
         $this->session->set($session, $authenticatedToken);
         return true;
     }
     return false;
 }
開發者ID:unrlab,項目名稱:security-bundle,代碼行數:11,代碼來源:SecurityListener.php

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

示例11: setClientForRiaClientView

 /**
  * Set client id for ria client view and add ROLE_CLIENT_VIEW to ria
  *
  * @param User $ria
  * @param int $clientId
  * @throws \InvalidArgumentException
  */
 public function setClientForRiaClientView(User $ria, $clientId)
 {
     $this->checkIsRiaUser($ria);
     $previousRoles = $this->securityContext->getToken()->getRoles();
     $previousRoles[] = 'ROLE_CLIENT_VIEW';
     //$ria->addRole('ROLE_CLIENT_VIEW');
     //$token = new UsernamePasswordToken($ria, null, 'main', $ria->getRoles());
     $token = new UsernamePasswordToken($ria, null, 'main', $previousRoles);
     $token->setAttribute('ria.client_view.client_id', $clientId);
     $this->securityContext->setToken($token);
 }
開發者ID:junjinZ,項目名稱:wealthbot,代碼行數:18,代碼來源:Acl.php

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

示例13: logIn

 protected function logIn()
 {
     $client = $this->container->get('client.repository')->findOneBy([]);
     $session = $this->client->getContainer()->get('session');
     $firewall = 'client';
     $token = new UsernamePasswordToken('demo@wellcommerce.org', 'demo', $firewall, ['ROLE_CLIENT']);
     $token->setUser($client);
     $session->set('_security_' . $firewall, serialize($token));
     $session->save();
     $cookie = new Cookie($session->getName(), $session->getId());
     $this->client->getCookieJar()->set($cookie);
     $this->container->get('security.token_storage')->setToken($token);
 }
開發者ID:WellCommerce,項目名稱:CoreBundle,代碼行數:13,代碼來源:AbstractFrontControllerTestCase.php

示例14: logIn

 protected function logIn(Client $client)
 {
     $em = $client->getContainer()->get('doctrine')->getManager();
     $user = $em->getRepository('VidalMainBundle:User')->findOneByUsername('7binary@bk.ru');
     $session = $client->getContainer()->get('session');
     $firewall = 'everything';
     $token = new UsernamePasswordToken($user, null, $firewall, $user->getRoles());
     $token->setUser($user);
     $session->set('_security_' . $firewall, serialize($token));
     $session->save();
     $cookie = new Cookie($session->getName(), $session->getId());
     $client->getCookieJar()->set($cookie);
 }
開發者ID:Evrika,項目名稱:Vidal,代碼行數:13,代碼來源:TestCase.php

示例15: logIn

 protected function logIn()
 {
     $user = $this->container->get('user.repository')->findOneBy([]);
     $session = $this->client->getContainer()->get('session');
     $firewall = 'admin';
     $token = new UsernamePasswordToken('admin', 'admin', $firewall, ['ROLE_ADMIN']);
     $token->setUser($user);
     $session->set('_security_' . $firewall, serialize($token));
     $session->save();
     $cookie = new Cookie($session->getName(), $session->getId());
     $this->client->getCookieJar()->set($cookie);
     $this->container->get('security.token_storage')->setToken($token);
 }
開發者ID:Newman101,項目名稱:WellCommerce,代碼行數:13,代碼來源:AbstractAdminControllerTestCase.php


注:本文中的Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。