diff --git a/DependencyInjection/Security/Factory/OpenIdFactory.php b/DependencyInjection/Security/Factory/OpenIdFactory.php index 189f5a0..7b23d20 100644 --- a/DependencyInjection/Security/Factory/OpenIdFactory.php +++ b/DependencyInjection/Security/Factory/OpenIdFactory.php @@ -14,8 +14,10 @@ class OpenIdFactory extends AbstractFactory */ public function __construct() { + $this->defaultSuccessHandlerOptions['login_path'] = '/login_openid'; + $this->defaultFailureHandlerOptions['login_path'] = '/login_openid'; + $this->addOption('create_user_if_not_exists', false); - $this->addOption('login_path', '/login_openid'); } /** diff --git a/Security/Http/Firewall/AbstractOpenIdAuthenticationListener.php b/Security/Http/Firewall/AbstractOpenIdAuthenticationListener.php index d64e59e..4c38266 100644 --- a/Security/Http/Firewall/AbstractOpenIdAuthenticationListener.php +++ b/Security/Http/Firewall/AbstractOpenIdAuthenticationListener.php @@ -22,14 +22,14 @@ abstract class AbstractOpenIdAuthenticationListener extends AbstractAuthenticati */ private $relyingParty; - public function __construct(SecurityContextInterface $securityContext, AuthenticationManagerInterface $authenticationManager, SessionAuthenticationStrategyInterface $sessionStrategy, HttpUtils $httpUtils, $providerKey, array $options = array(), AuthenticationSuccessHandlerInterface $successHandler = null, AuthenticationFailureHandlerInterface $failureHandler = null, LoggerInterface $logger = null, EventDispatcherInterface $dispatcher = null) + public function __construct(SecurityContextInterface $securityContext, AuthenticationManagerInterface $authenticationManager, SessionAuthenticationStrategyInterface $sessionStrategy, HttpUtils $httpUtils, $providerKey, AuthenticationSuccessHandlerInterface $successHandler, AuthenticationFailureHandlerInterface $failureHandler, array $options = array(), LoggerInterface $logger = null, EventDispatcherInterface $dispatcher = null) { $options = array_merge(array( 'required_attributes' => array(), 'optional_attributes' => array(), ), $options); - - parent::__construct($securityContext, $authenticationManager, $sessionStrategy, $httpUtils,$providerKey, $options, $successHandler, $failureHandler, $logger, $dispatcher); + + parent::__construct($securityContext, $authenticationManager, $sessionStrategy, $httpUtils, $providerKey, $successHandler, $failureHandler, $options, $logger, $dispatcher); } /** diff --git a/Tests/Functional/app/config/config.yml b/Tests/Functional/app/config/config.yml index ec2672b..8f53db8 100644 --- a/Tests/Functional/app/config/config.yml +++ b/Tests/Functional/app/config/config.yml @@ -32,7 +32,6 @@ framework: session: storage_id: session.storage.mock_file secret: %secret% - charset: UTF-8 router: { resource: "%kernel.root_dir%/config/routing.yml" } default_locale: %locale% diff --git a/Tests/Security/Http/AbstractOpenIdAuthenticationListenerTest.php b/Tests/Security/Http/AbstractOpenIdAuthenticationListenerTest.php index 6c07ec6..a4a0ffe 100644 --- a/Tests/Security/Http/AbstractOpenIdAuthenticationListenerTest.php +++ b/Tests/Security/Http/AbstractOpenIdAuthenticationListenerTest.php @@ -14,7 +14,8 @@ public function couldBeConstructedWithRequiredSetOfArguments() $this->createSessionAuthenticationStrategyMock(), $this->createHttpUtilsMock(), 'providerKey', - $options = array() + $this->createAuthenticationSuccessHandlerMock(), + $this->createAuthenticationFailureHandlerMock(), ); $this->getMockForAbstractClass( @@ -34,7 +35,8 @@ public function shouldSetEmptyArrayAsRequiredAttributesOptionsInConstructor() $this->createSessionAuthenticationStrategyMock(), $this->createHttpUtilsMock(), 'providerKey', - $options = array() + $this->createAuthenticationSuccessHandlerMock(), + $this->createAuthenticationFailureHandlerMock(), ); $listener = $this->getMockForAbstractClass( @@ -64,6 +66,8 @@ public function shouldSetCustomRequiredAttributesToOptionsInConstructor() $this->createSessionAuthenticationStrategyMock(), $this->createHttpUtilsMock(), 'providerKey', + $this->createAuthenticationSuccessHandlerMock(), + $this->createAuthenticationFailureHandlerMock(), $options = array( 'required_attributes' => $expectedRequiredAttributes ) @@ -91,6 +95,8 @@ public function shouldSetEmptyArrayAsOptionalAttributesOptionsInConstructor() $this->createSessionAuthenticationStrategyMock(), $this->createHttpUtilsMock(), 'providerKey', + $this->createAuthenticationSuccessHandlerMock(), + $this->createAuthenticationFailureHandlerMock(), $options = array() ); @@ -116,6 +122,8 @@ public function shouldAddOptionalAttributesToOptionsWithEmptyArrayAsDefaultValue $this->createSessionAuthenticationStrategyMock(), $this->createHttpUtilsMock(), 'providerKey', + $this->createAuthenticationSuccessHandlerMock(), + $this->createAuthenticationFailureHandlerMock(), $options = array() ); @@ -146,6 +154,8 @@ public function shouldSetCustomOptionalAttributesToOptionsInConstructor() $this->createSessionAuthenticationStrategyMock(), $this->createHttpUtilsMock(), 'providerKey', + $this->createAuthenticationSuccessHandlerMock(), + $this->createAuthenticationFailureHandlerMock(), $options = array( 'optional_attributes' => $expectedOptionalAttributes ) @@ -247,4 +257,14 @@ protected function createRelyingPartyMock() { return $this->getMock('Fp\OpenIdBundle\RelyingParty\RelyingPartyInterface'); } + + protected function createAuthenticationSuccessHandlerMock() + { + return $this->getMock('Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface'); + } + + protected function createAuthenticationFailureHandlerMock() + { + return $this->getMock('Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface'); + } } \ No newline at end of file diff --git a/Tests/Security/Http/OpenIdAuthenticationListenerTest.php b/Tests/Security/Http/OpenIdAuthenticationListenerTest.php index f5e29b8..a14f2b4 100644 --- a/Tests/Security/Http/OpenIdAuthenticationListenerTest.php +++ b/Tests/Security/Http/OpenIdAuthenticationListenerTest.php @@ -23,6 +23,8 @@ public function couldBeConstructedWithRequiredSetOfArguments() $this->createSessionAuthenticationStrategyMock(), $this->createHttpUtilsMock(), 'providerKey', + $this->createAuthenticationSuccessHandlerMock(), + $this->createAuthenticationFailureHandlerMock(), $options = array() ); } @@ -51,6 +53,8 @@ public function shouldNotContinueAuthenticationIfCheckRequestPathReturnFalse() $this->createSessionAuthenticationStrategyMock(), $httpUtilsMock, 'providerKey', + $this->createAuthenticationSuccessHandlerMock(), + $this->createAuthenticationFailureHandlerMock(), $options = array() ); @@ -73,6 +77,8 @@ public function throwIfRelyingPartyNotSet() $this->createSessionAuthenticationStrategyMock(), $this->createHttpUtilsStub($checkRequestPathReturn = true), 'providerKey', + $this->createAuthenticationSuccessHandlerMock(), + $this->createAuthenticationFailureHandlerMock(), $options = array() ); @@ -103,6 +109,8 @@ public function shouldNotContinueAuthenticationIfRelyingPartySupportsReturnFalse $this->createSessionAuthenticationStrategyMock(), $this->createHttpUtilsStub($checkRequestPathReturn = true), 'providerKey', + $this->createAuthenticationSuccessHandlerMock(), + $this->createAuthenticationFailureHandlerMock(), $options = array() ); @@ -143,6 +151,8 @@ public function shouldDuplicateRequestAndPassItToRelyingPartyManageMethod() $this->createSessionAuthenticationStrategyMock(), $this->createHttpUtilsStub($checkRequestPathReturn = true), 'providerKey', + $this->createAuthenticationSuccessHandlerMock(), + $this->createAuthenticationFailureHandlerMock(), $options = array() ); @@ -183,6 +193,8 @@ public function shouldAddRequiredAttributesToDuplicatedRequest() $this->createSessionAuthenticationStrategyMock(), $this->createHttpUtilsStub($checkRequestPathReturn = true), 'providerKey', + $this->createAuthenticationSuccessHandlerMock(), + $this->createAuthenticationFailureHandlerMock(), $options = array('required_attributes' => $expectedRequiredAttributes) ); @@ -228,6 +240,8 @@ public function shouldAddOptionalAttributesToDuplicatedRequest() $this->createSessionAuthenticationStrategyMock(), $this->createHttpUtilsStub($checkRequestPathReturn = true), 'providerKey', + $this->createAuthenticationSuccessHandlerMock(), + $this->createAuthenticationFailureHandlerMock(), $options = array('optional_attributes' => $expectedOptionalAttributes) ); @@ -269,6 +283,8 @@ public function shouldSetRelyingPartyRedirectResponseToEvent() $this->createSessionAuthenticationStrategyMock(), $this->createHttpUtilsStub($checkRequestPathReturn = true), 'providerKey', + $this->createAuthenticationSuccessHandlerMock(), + $this->createAuthenticationFailureHandlerMock(), $options = array() ); @@ -301,6 +317,8 @@ public function throwIfRelyingPartyReturnNeitherRedirectResponseOrIdentityProvid $this->createSessionAuthenticationStrategyMock(), $this->createHttpUtilsStub($checkRequestPathReturn = true), 'providerKey', + $this->createAuthenticationSuccessHandlerMock(), + $this->createAuthenticationFailureHandlerMock(), $options = array() ); @@ -356,9 +374,9 @@ public function shouldAddIdentityProviderResponseToEachThrownAuthenticationExcep $this->createSessionAuthenticationStrategyMock(), $this->createHttpUtilsStub($checkRequestPathReturn = true), 'providerKey', - $options = array(), - null, - $authenticationFailureHandlerMock + $this->createAuthenticationSuccessHandlerMock(), + $authenticationFailureHandlerMock, + $options = array() ); $listener->setRelyingParty($relyingPartyMock); @@ -416,6 +434,8 @@ public function shouldCreateOpenIdTokenUsingIdentityProviderResponseAndPassItToA $this->createSessionAuthenticationStrategyMock(), $httpUtilsStub, 'providerKey', + $this->createAuthenticationSuccessHandlerStub(), + $this->createAuthenticationFailureHandlerMock(), $options = array() ); @@ -470,6 +490,8 @@ public function shouldAddOpenIdTokenToSecurityContextIfSuccessfullyAuthenticated $this->createSessionAuthenticationStrategyMock(), $httpUtilsStub, 'providerKey', + $this->createAuthenticationSuccessHandlerStub(), + $this->createAuthenticationFailureHandlerMock(), $options = array() ); @@ -602,4 +624,22 @@ protected function createGetResponseEventStub($request = null) return $getResponseEventMock; } + + protected function createAuthenticationSuccessHandlerMock() + { + return $this->getMock('Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface'); + } + + protected function createAuthenticationSuccessHandlerStub() + { + $handlerMock = $this->createAuthenticationSuccessHandlerMock(); + + $handlerMock + ->expects($this->any()) + ->method('onAuthenticationSuccess') + ->will($this->returnValue(new Response())) + ; + + return $handlerMock; + } } \ No newline at end of file diff --git a/composer.json b/composer.json index 10800ef..9e677d7 100644 --- a/composer.json +++ b/composer.json @@ -24,6 +24,7 @@ "psr-0": { "Fp\\OpenIdBundle": "" } }, "target-dir": "Fp/OpenIdBundle", + "minimum-stability": "dev", "extra": { "branch-alias": { "dev-master": "1.3-dev"