当前位置: 首页>>代码示例>>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;未经允许,请勿转载。