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


PHP TokenInterface::getAttribute方法代码示例

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


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

示例1: getValidUserApi

 /**
  * Get valid UserApi for given token
  *
  * @param TokenInterface       $token
  * @param PersistentCollection $secrets
  * @param User                 $user
  *
  * @return bool|UserApi
  */
 protected function getValidUserApi(TokenInterface $token, PersistentCollection $secrets, User $user)
 {
     $currentIteration = 0;
     $nonce = $token->getAttribute('nonce');
     $secretsCount = $secrets->count();
     /** @var UserApi $userApi */
     foreach ($secrets as $userApi) {
         $currentIteration++;
         $isSecretValid = $this->validateDigest($token->getAttribute('digest'), $nonce, $token->getAttribute('created'), $userApi->getApiKey(), $this->getSalt($user));
         if ($isSecretValid && !$userApi->getUser()->getOrganizations()->contains($userApi->getOrganization())) {
             throw new BadCredentialsException('Wrong API key.');
         }
         if ($isSecretValid && !$userApi->getOrganization()->isEnabled()) {
             throw new BadCredentialsException('Organization is not active.');
         }
         // delete nonce from cache because user have another api keys
         if (!$isSecretValid && $secretsCount !== $currentIteration) {
             $this->getNonceCache()->delete($nonce);
         }
         if ($isSecretValid) {
             return $userApi;
         }
     }
     return false;
 }
开发者ID:xamin123,项目名称:platform,代码行数:34,代码来源:WsseAuthProvider.php

示例2: authenticate

 public function authenticate(TokenInterface $token)
 {
     $user = $this->userProvider->loadUserByUsername($token->getUsername());
     if ($user && $this->validateDigest($token->getCredentials(), $token->getAttribute('nonce'), $token->getAttribute('created'), $this->getSecret($user), $this->getSalt($user))) {
         $authenticatedToken = new Token($user, $token->getCredentials(), $this->providerKey, $user->getRoles());
         return $authenticatedToken;
     }
     throw new AuthenticationException('WSSE authentication failed.');
 }
开发者ID:aml-bendall,项目名称:ExpandAkeneoApi,代码行数:9,代码来源:Provider.php

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

示例4: authenticate

 /**
  * Authenticate API user by API key
  *
  * @param  TokenInterface          $token
  * @return Token
  * @throws AuthenticationException
  */
 public function authenticate(TokenInterface $token)
 {
     $user = $this->userProvider->loadUserByUsername($token->getUsername());
     if ($user && $user->getApi()) {
         if ($this->validateDigest($token->getAttribute('digest'), $token->getAttribute('nonce'), $token->getAttribute('created'), $user->getApi()->getApiKey(), $user->getSalt())) {
             $authToken = new Token($user->getRoles());
             $authToken->setUser($user);
             $authToken->setAuthenticated(true);
             return $authToken;
         }
     }
     throw new AuthenticationException('WSSE authentication failed.');
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:20,代码来源:WsseUserProvider.php

示例5:

 function it_should_switch_the_domain_if_the_token_has_the_ldap_domain_set()
 {
     // It first grabs a copy of the domain context, then checks against it, then checks it at the end...
     $this->ldap->getDomainContext()->willReturn('foo.bar', 'foo.bar', 'example.local');
     $this->token->hasAttribute('ldap_domain')->willReturn(true);
     $this->token->getAttribute('ldap_domain')->willReturn('example.local');
     $this->ldap->switchDomain('example.local')->shouldBeCalledTimes(1);
     $this->ldap->switchDomain('foo.bar')->shouldBeCalledTimes(1);
     $this->authenticate($this->token)->shouldReturnAnInstanceOf('\\Symfony\\Component\\Security\\Core\\Authentication\\Token\\UsernamePasswordToken');
 }
开发者ID:ldaptools,项目名称:ldaptools-bundle,代码行数:10,代码来源:LdapAuthenticationProviderSpec.php

示例6: authenticate

 /**
  * Attempts to authenticate a TokenInterface object.
  *
  * @param TokenInterface $token The TokenInterface instance to authenticate
  *
  * @return TokenInterface An authenticated TokenInterface instance, never null
  *
  * @throws AuthenticationException if the authentication fails
  */
 public function authenticate(TokenInterface $token)
 {
     try {
         $key = $token->getAttribute('key');
         /** @var ApiUser $user */
         $user = $this->apiUserProvider->loadUserByKey($key);
         $authenticatedToken = new ApiUserToken($user->getRoles());
         $authenticatedToken->setUser($user);
         $authenticatedToken->setAuthenticated(true);
         return $authenticatedToken;
     } catch (BadCredentialsException $notFoundException) {
         throw new AuthenticationException('User not found');
     }
 }
开发者ID:GrizliK1988,项目名称:symfony-certification-prepare-project,代码行数:23,代码来源:ApiAuthenticationProvider.php

示例7: validateToken

 /**
  * Validate a Raven user token.
  *
  * @param TokenInterface $token Raven user token.
  *
  * @return bool true if the token is valid, false otherwise.
  *
  * @throws OpenSslException If there is an OpenSSL problem.
  */
 protected function validateToken(TokenInterface $token)
 {
     // @codeCoverageIgnoreStart
     if (false === function_exists('openssl_verify')) {
         throw new OpenSslException('OpenSSL is unavailable');
     }
     // @codeCoverageIgnoreEnd
     $data = implode('!', array($token->getAttribute('ver'), $token->getAttribute('status'), $token->getAttribute('msg'), $token->getAttribute('issue')->format('Ymd\\THis\\Z'), $token->getAttribute('id'), $token->getAttribute('url'), $token->getUsername(), $token->getAttribute('auth'), $token->getAttribute('sso'), $token->getAttribute('life'), $token->getAttribute('params')));
     $sig = base64_decode(preg_replace(array('/-/', '/\\./', '/_/'), array('+', '/', '='), rawurldecode($token->getAttribute('sig'))));
     $key = openssl_pkey_get_public($this->raven->getCertificate());
     $result = openssl_verify($data, $sig, $key);
     openssl_free_key($key);
     switch ($result) {
         case 1:
             return true;
             break;
         case 0:
             return false;
             break;
             // @codeCoverageIgnoreStart
         // @codeCoverageIgnoreStart
         default:
             throw new OpenSslException('OpenSSL has returned a error when verifying the signature');
             break;
     }
     // @codeCoverageIgnoreEnd
 }
开发者ID:littlerobot,项目名称:raven-bundle,代码行数:36,代码来源:RavenAuthenticationProvider.php

示例8: switchDomainIfNeeded

 /**
  * If the domain needs to a different context for the request, then switch it.
  *
  * @param TokenInterface $token
  */
 protected function switchDomainIfNeeded(TokenInterface $token)
 {
     if ($token->hasAttribute('ldap_domain') && $this->ldap->getDomainContext() !== $token->getAttribute('ldap_domain')) {
         $this->ldap->switchDomain($token->getAttribute('ldap_domain'));
     }
 }
开发者ID:ldaptools,项目名称:ldaptools-bundle,代码行数:11,代码来源:LdapAuthenticationProvider.php

示例9: getAttribute

 public function getAttribute($name)
 {
     return $this->innerToken->getAttribute($name);
 }
开发者ID:emodric,项目名称:LegacyBridge,代码行数:4,代码来源:LegacyToken.php


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