php Symfony-Component-Security-Core-Authentication-Token-UsernamePasswordToken类(方法)实例源码

下面列出了php Symfony-Component-Security-Core-Authentication-Token-UsernamePasswordToken 类(方法)源码代码实例,从而了解它的用法。

作者:GeorgeBroadle    项目:caffeine-vendo   
/**
  * {@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;
 }

作者:ekreativ    项目:redmine-time-tracke   
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;
     }
 }

作者:olliet    项目:sul   
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);
 }

作者:dstansb    项目:camdra   
public function setUp()
 {
     $this->voter = new ProfileVoter();
     $this->token = new UsernamePasswordToken('testuser', 'password', 'public');
     $this->user = new User();
     $this->token->setUser($this->user);
 }

作者:LenticularClou    项目:Cloud-Ldap-Admi   
/**
  * {@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);
 }

作者:apiaryh    项目:silex-sms-login-provide   
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;
 }

作者:cilefe    项目:symfon   
/**
  * {@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.');
     }
 }

作者:Markoba    项目:stoerungsmelde   
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;
 }

作者:unrla    项目:security-bundl   
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;
 }

作者:brookinsconsultin    项目:ezecosyste   
/**
  * {@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);
     }
 }

作者:junjin    项目:wealthbo   
/**
  * 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);
 }

作者:zorn-    项目:symfon   
/**
  * {@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.');
     }
 }

作者:WellCommerc    项目:CoreBundl   
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);
 }

作者:Evrik    项目:Vida   
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);
 }

作者:Newman10    项目:WellCommerc   
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);
 }

作者:Raph    项目:AfterEp   
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();
 }

作者:lcstudio    项目:ldap-bundl   
/**
  * {@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;
     }
 }

作者:anonim113    项目:ruszdupe-we   
/**
  * @Route("/checkIn", name="loginCheck")
  * @Template()
  */
 public function checkInAction()
 {
     if (isset($_GET['connectData'])) {
         //Jeżeli są dane, to loguje
         $wykop = $this->get('WykopApi');
         $connect_data = $wykop->handleConnectData();
         $session = new Session();
         $session->set('token', $connect_data['token']);
         $session->set('sign', $connect_data['sign']);
         $profile = $wykop->doRequest('profile/index/' . $connect_data['login']);
         if (!$wykop->isValid()) {
             throw new Exception($this->api->getError());
         } else {
             $answer = $wykop->doRequest('user/login', array('login' => $profile['login'], 'accountkey' => $session->get('token')));
             if (!$wykop->isValid()) {
                 throw new Exception($this->api->getError());
             }
             $roles = ['ROLE_USER_WYKOP'];
             if ($profile['login'] === 'anonim1133') {
                 $roles[] = 'ROLE_ADMIN';
             }
             $token = new UsernamePasswordToken($profile['login'], $answer['userkey'], 'wykop', $roles);
             $token->setAttribute('wykop_login', $profile['login']);
             $token->setAttribute('wykop_sex', $profile['sex']);
             $token->setAttribute('wykop_group', $profile['author_group']);
             $token->setAttribute('wykop_avatar', $profile['avatar_med']);
             $token->setAttribute('wykop_login_date', new \DateTime('now'));
             $this->get('security.token_storage')->setToken($token);
             $session->set('_security_main', serialize($token));
         }
     }
     return $this->redirect('/');
 }

作者:zyxis    项目:cantig   
public function __construct($sourceToken, Membership $membership, Project $project)
 {
     if (!$sourceToken instanceof UsernamePasswordToken && !$sourceToken instanceof RememberMeToken) {
         throw new AccessDeniedException('Invalid authentication token');
     }
     parent::__construct($sourceToken->getUser(), $sourceToken->getCredentials(), $sourceToken->getProviderKey(), $sourceToken->getUser()->getRoles());
     $this->membership = $membership;
     $this->masterProject = $project;
 }

作者:NobletSolution    项目:SecurityBundl   
/**
  * {@inheritdoc}
  */
 protected function attemptAuthentication(Request $request)
 {
     $this->logger->info("adminListener attempting authentication!");
     if ($this->options['post_only'] && 'post' !== strtolower($request->getMethod())) {
         if (null !== $this->logger) {
             $this->logger->debug(sprintf('Authentication method not supported: %s.', $request->getMethod()));
         }
         return null;
     }
     $username = trim($request->get($this->options['username_parameter']));
     $password = $request->get($this->options['password_parameter']);
     $user = $request->get($this->options['user_parameter']);
     $token = new UsernamePasswordToken($username, $password, $this->providerKey);
     if (null !== $user) {
         $token->setAttribute('desired_user', $user);
     }
     return $this->authenticationManager->authenticate($token);
 }


问题


面经


文章

微信
公众号

扫码关注公众号