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