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


PHP AuthenticationException::setToken方法代碼示例

本文整理匯總了PHP中Symfony\Component\Security\Core\Exception\AuthenticationException::setToken方法的典型用法代碼示例。如果您正苦於以下問題:PHP AuthenticationException::setToken方法的具體用法?PHP AuthenticationException::setToken怎麽用?PHP AuthenticationException::setToken使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Symfony\Component\Security\Core\Exception\AuthenticationException的用法示例。


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

示例1: 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)
 {
     if (false === $this->supports($token)) {
         return null;
     }
     /** @var SamlSpResponseToken $token */
     $user = null;
     try {
         $user = $this->loadUser($token);
     } catch (UsernameNotFoundException $ex) {
         $user = $this->createUser($token);
     }
     if (null == $user && $this->force) {
         $user = $this->createDefaultUser($token);
     }
     if (null == $user) {
         $ex = new AuthenticationException('Unable to resolve user');
         $ex->setToken($token);
         throw $ex;
     }
     if ($this->userChecker && $user instanceof UserInterface) {
         $this->userChecker->checkPostAuth($user);
     }
     $attributes = $this->getAttributes($token);
     $result = new SamlSpToken($user instanceof UserInterface ? $user->getRoles() : [], $this->providerKey, $attributes, $user);
     return $result;
 }
開發者ID:BernardoSilva,項目名稱:SpBundle,代碼行數:36,代碼來源:LightsSamlSpAuthenticationProvider.php

示例2: shouldRemoveErrorFromSessionOnManage

 /**
  * @test
  */
 public function shouldRemoveErrorFromSessionOnManage()
 {
     $error = new AuthenticationException('an error');
     $error->setToken(new OpenIdToken('aProviderKey', 'anIdentity'));
     $session = $this->createSessionStub($returnGet = $error);
     $session->expects($this->once())->method('remove')->with($this->equalTo(Security::AUTHENTICATION_ERROR));
     $request = $this->createRequestStub($returnGet = 1, $returnSession = $session);
     $relyingParty = new RecoveredFailureRelyingParty();
     //guard
     $this->assertTrue($relyingParty->supports($request));
     $relyingParty->manage($request);
 }
開發者ID:migros,項目名稱:FpOpenIdBundle,代碼行數:15,代碼來源:RecoveredFailureRelyingPartyTest.php

示例3: testFailureHandler

 public function testFailureHandler()
 {
     $username = 'admin';
     $token = $this->getMock(TokenInterface::class);
     $token->expects($this->any())->method('getUsername')->will($this->returnValue($username));
     $exception = new AuthenticationException();
     $exception->setToken($token);
     $authenticator = new ApiKeyAuthenticator();
     $response = $authenticator->onAuthenticationFailure(Request::create('/'), $exception);
     $this->assertInstanceOf(JsonResponse::class, $response);
     $this->assertSame($response->getStatusCode(), Response::HTTP_UNAUTHORIZED);
     $content = json_decode($response->getContent(), true);
     $this->assertSame('Credentials refused!', $content['reason']);
     $this->assertSame($username, $content['username']);
 }
開發者ID:thesoftwarefactoryuk,項目名稱:SenNetwork,代碼行數:15,代碼來源:ApiKeyAuthenticatorTest.php


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