本文整理汇总了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;
}
示例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);
}
示例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']);
}