Skip to content

Commit

Permalink
getExtraInfo was removed.
Browse files Browse the repository at this point in the history
  • Loading branch information
makasim committed Mar 1, 2013
1 parent 1ba8408 commit 80c0c40
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 26 deletions.
9 changes: 6 additions & 3 deletions RelyingParty/RecoveredFailureRelyingParty.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\SecurityContextInterface;

use Fp\OpenIdBundle\RelyingParty\IdentityProviderResponse;
use Fp\OpenIdBundle\Security\Core\Authentication\Token\OpenIdToken;

class RecoveredFailureRelyingParty implements RelyingPartyInterface
{
Expand All @@ -21,7 +21,7 @@ public function supports(Request $request)
if (false == $error = $request->getSession()->get(SecurityContextInterface::AUTHENTICATION_ERROR)) {
return false;
}
if (false == $error->getExtraInformation() instanceof IdentityProviderResponse) {
if (false == $error->getToken() instanceof OpenIdToken) {
return false;
}

Expand All @@ -41,6 +41,9 @@ public function manage(Request $request)

$request->getSession()->remove(SecurityContextInterface::AUTHENTICATION_ERROR);

return $error->getExtraInformation();
return new IdentityProviderResponse(
$error->getToken()->getIdentity(),
$error->getToken()->getAttributes()
);
}
}
14 changes: 7 additions & 7 deletions Resources/doc/interactive_user_creation.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Acme\DemoBundle\Entity\User;
use Fp\OpenIdBundle\RelyingParty\Exception\OpenIdAuthenticationCanceledException;
use Fp\OpenIdBundle\RelyingParty\IdentityProviderResponse;
use Fp\OpenIdBundle\RelyingParty\RecoveredFailureRelyingParty;
use Fp\OpenIdBundle\Security\Core\Authentication\Token\OpenIdToken
class SecurityController extends Controller
{
Expand All @@ -107,18 +107,18 @@ class SecurityController extends Controller
}
/**
* @var $identityProvidedResponse IdentityProviderResponse
* @var $token OpenIdToken
*/
$identityProvidedResponse = $failure->getExtraInformation();
if (false == $identityProvidedResponse instanceof IdentityProviderResponse) {
throw new \LogicException('The failure does not contain IdentityProvidedResponse in extraInfo, Is the failure come from openid?');
$token = $failure->getToken();
if (false == $token instanceof OpenIdToken) {
throw new \LogicException('The failure does not contain OpenIdToken, Is the failure come from openid?');
}
$attributes = array_merge(array(
'contact/email' => '',
'namePerson/first' => '',
'namePerson/last' => '',
), $identityProvidedResponse->getAttributes())
), $token->getAttributes())
;
//the next code is pseudo. You have to adopt it to your needs.
Expand All @@ -134,7 +134,7 @@ class SecurityController extends Controller
$this->getUserManager()->updateUser($user);
$identity = $this->getIdentityManager()->create();
$identity->setIdentity($identityProvidedResponse->getIdentity());
$identity->setIdentity($token->getIdentity());
$identity->setAttributes($attributes);
$identity->setUser($user);
$this->getIdentityManager()->update($identity);
Expand Down
2 changes: 1 addition & 1 deletion Security/Http/Firewall/OpenIdAuthenticationListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected function attemptAuthentication(Request $request)
try {
return $this->authenticationManager->authenticate($token);
} catch (AuthenticationException $e) {
$e->setExtraInformation($result);
$e->setToken($token);

throw $e;
}
Expand Down
26 changes: 17 additions & 9 deletions Tests/RelyingParty/RecoveredFailureRelyingPartyTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace Fp\OpenIdBundle\Tests\RelyingParty;

use Fp\OpenIdBundle\Security\Core\Authentication\Token\OpenIdToken;
use Symfony\Component\Security\Core\SecurityContextInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;

Expand Down Expand Up @@ -87,12 +88,12 @@ public function shouldNotSupportIfAuthenticationErrorWithoutIdentityProviderResp
/**
* @test
*/
public function shouldSupportIfAuthenticationErrorWithIdentityProviderResponseSet()
public function shouldSupportIfAuthenticationErrorWithOpenIdTokenProviderResponseSet()
{
$identityProviderResponse = new IdentityProviderResponse('an_identity');
$token = new OpenIdToken('aProviderKey', 'identity');

$error = new AuthenticationException('an error');
$error->setExtraInformation($identityProviderResponse);
$error->setToken($token);

$session = $this->createSessionStub($returnGet = $error);
$request = $this->createRequestStub($returnGet = 1, $returnSession = $session);
Expand All @@ -105,7 +106,7 @@ public function shouldSupportIfAuthenticationErrorWithIdentityProviderResponseSe
/**
* @test
*
* @expectedException InvalidArgumentException
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage The relying party does not support the request
*/
public function throwIfTryManageNotSupportedRequest()
Expand All @@ -123,10 +124,14 @@ public function throwIfTryManageNotSupportedRequest()
*/
public function shouldReturnIdentityProviderResponseOnManage()
{
$expectedIdentityProviderResponse = new IdentityProviderResponse('an_identity');
$expectedIdentity = 'theIdentity';
$expectedAttributes = array('foo' => 'fooVal', 'bar' => 'barVal');

$token = new OpenIdToken('aProviderKey', $expectedIdentity);
$token->setAttributes($expectedAttributes);

$error = new AuthenticationException('an error');
$error->setExtraInformation($expectedIdentityProviderResponse);
$error->setToken($token);

$session = $this->createSessionStub($returnGet = $error);
$request = $this->createRequestStub($returnGet = 1, $returnSession = $session);
Expand All @@ -136,16 +141,19 @@ public function shouldReturnIdentityProviderResponseOnManage()
//guard
$this->assertTrue($relyingParty->supports($request));

$this->assertSame($expectedIdentityProviderResponse, $relyingParty->manage($request));
$actualIdentityProviderResponse = $relyingParty->manage($request);
$this->assertInstanceOf('Fp\OpenIdBundle\RelyingParty\IdentityProviderResponse', $actualIdentityProviderResponse);
$this->assertEquals($expectedIdentity,$actualIdentityProviderResponse->getIdentity());
$this->assertEquals($expectedAttributes,$actualIdentityProviderResponse->getAttributes());
}

/**
* @test
*/
public function shouldRemoveErrorFromSessionOnManage()
{
{
$error = new AuthenticationException('an error');
$error->setExtraInformation(new IdentityProviderResponse('an_identity'));
$error->setToken(new OpenIdToken('aProviderKey', 'anIdentity'));

$session = $this->createSessionStub($returnGet = $error);
$session
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ public function shouldCreateAuthenticatedTokenUsingUserProviderAndSearchByIdenti
/**
* @test
*
* @expectedException Symfony\Component\Security\Core\Exception\AuthenticationServiceException
* @expectedException \Symfony\Component\Security\Core\Exception\AuthenticationServiceException
* @expectedExceptionMessage User provider did not return an implementation of user interface.
*/
public function throwIfUserProviderReturnNotUserInstance()
Expand Down Expand Up @@ -304,7 +304,7 @@ public function throwIfUserProviderReturnNotUserInstance()
/**
* @test
*
* @expectedException Symfony\Component\Security\Core\Exception\UsernameNotFoundException
* @expectedException \Symfony\Component\Security\Core\Exception\UsernameNotFoundException
* @expectedExceptionMessage Cannot find user by openid identity
*/
public function shouldNotCreateUserIfNotExistIfFlagNotSet()
Expand Down Expand Up @@ -399,7 +399,7 @@ public function shouldCreateAuthenticatedTokenUsingUserManagerCreateFromIdentity
/**
* @test
*
* @expectedException Symfony\Component\Security\Core\Exception\AuthenticationServiceException
* @expectedException \Symfony\Component\Security\Core\Exception\AuthenticationServiceException
* @expectedExceptionMessage User provider did not return an implementation of user interface.
*/
public function throwIfUserManagerCreateNotUserInstance()
Expand Down Expand Up @@ -467,7 +467,7 @@ public function shouldWrapAnyThrownExceptionsAsAuthenticatedServiceException()
$this->assertSame($expectedPreviousException, $e->getPrevious());
$this->assertEquals($expectedMessage, $e->getMessage());
$this->assertEquals($expectedCode, $e->getCode());
$this->assertNull($e->getExtraInformation());
$this->assertNull($e->getToken());

return;
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/Security/Http/OpenIdAuthenticationListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ public function throwIfRelyingPartyReturnNeitherRedirectResponseOrIdentityProvid
/**
* @test
*/
public function shouldAddIdentityProviderResponseToEachThrownAuthenticationExceptionAsExtraInformation()
public function shouldAddTokenToEachThrownAuthenticationException()
{
$expectedIdentityProviderResponse = new IdentityProviderResponse('an_identity');
$expectedAuthenticationException = new AuthenticationException('an error');
Expand Down Expand Up @@ -360,7 +360,7 @@ public function shouldAddIdentityProviderResponseToEachThrownAuthenticationExcep
->method('onAuthenticationFailure')
->will($this->returnCallback(function($request, $exception) use($testcase, $expectedAuthenticationException, $expectedIdentityProviderResponse) {
$testcase->assertSame($exception, $expectedAuthenticationException);
$testcase->assertSame($expectedIdentityProviderResponse, $exception->getExtraInformation());
$testcase->assertInstanceOf('Fp\OpenIdBundle\Security\Core\Authentication\Token\OpenIdToken', $exception->getToken());

return new Response('');
}))
Expand Down

0 comments on commit 80c0c40

Please sign in to comment.