Skip to content

Commit

Permalink
fix sf21 changes in security.
Browse files Browse the repository at this point in the history
  • Loading branch information
makasim committed Jul 16, 2012
1 parent 0b915cd commit a32a2e0
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 10 deletions.
4 changes: 3 additions & 1 deletion DependencyInjection/Security/Factory/OpenIdFactory.php
Expand Up @@ -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');
}

/**
Expand Down
Expand Up @@ -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);
}

/**
Expand Down
1 change: 0 additions & 1 deletion Tests/Functional/app/config/config.yml
Expand Up @@ -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%

Expand Down
24 changes: 22 additions & 2 deletions Tests/Security/Http/AbstractOpenIdAuthenticationListenerTest.php
Expand Up @@ -14,7 +14,8 @@ public function couldBeConstructedWithRequiredSetOfArguments()
$this->createSessionAuthenticationStrategyMock(),
$this->createHttpUtilsMock(),
'providerKey',
$options = array()
$this->createAuthenticationSuccessHandlerMock(),
$this->createAuthenticationFailureHandlerMock(),
);

$this->getMockForAbstractClass(
Expand All @@ -34,7 +35,8 @@ public function shouldSetEmptyArrayAsRequiredAttributesOptionsInConstructor()
$this->createSessionAuthenticationStrategyMock(),
$this->createHttpUtilsMock(),
'providerKey',
$options = array()
$this->createAuthenticationSuccessHandlerMock(),
$this->createAuthenticationFailureHandlerMock(),
);

$listener = $this->getMockForAbstractClass(
Expand Down Expand Up @@ -64,6 +66,8 @@ public function shouldSetCustomRequiredAttributesToOptionsInConstructor()
$this->createSessionAuthenticationStrategyMock(),
$this->createHttpUtilsMock(),
'providerKey',
$this->createAuthenticationSuccessHandlerMock(),
$this->createAuthenticationFailureHandlerMock(),
$options = array(
'required_attributes' => $expectedRequiredAttributes
)
Expand Down Expand Up @@ -91,6 +95,8 @@ public function shouldSetEmptyArrayAsOptionalAttributesOptionsInConstructor()
$this->createSessionAuthenticationStrategyMock(),
$this->createHttpUtilsMock(),
'providerKey',
$this->createAuthenticationSuccessHandlerMock(),
$this->createAuthenticationFailureHandlerMock(),
$options = array()
);

Expand All @@ -116,6 +122,8 @@ public function shouldAddOptionalAttributesToOptionsWithEmptyArrayAsDefaultValue
$this->createSessionAuthenticationStrategyMock(),
$this->createHttpUtilsMock(),
'providerKey',
$this->createAuthenticationSuccessHandlerMock(),
$this->createAuthenticationFailureHandlerMock(),
$options = array()
);

Expand Down Expand Up @@ -146,6 +154,8 @@ public function shouldSetCustomOptionalAttributesToOptionsInConstructor()
$this->createSessionAuthenticationStrategyMock(),
$this->createHttpUtilsMock(),
'providerKey',
$this->createAuthenticationSuccessHandlerMock(),
$this->createAuthenticationFailureHandlerMock(),
$options = array(
'optional_attributes' => $expectedOptionalAttributes
)
Expand Down Expand Up @@ -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');
}
}
46 changes: 43 additions & 3 deletions Tests/Security/Http/OpenIdAuthenticationListenerTest.php
Expand Up @@ -23,6 +23,8 @@ public function couldBeConstructedWithRequiredSetOfArguments()
$this->createSessionAuthenticationStrategyMock(),
$this->createHttpUtilsMock(),
'providerKey',
$this->createAuthenticationSuccessHandlerMock(),
$this->createAuthenticationFailureHandlerMock(),
$options = array()
);
}
Expand Down Expand Up @@ -51,6 +53,8 @@ public function shouldNotContinueAuthenticationIfCheckRequestPathReturnFalse()
$this->createSessionAuthenticationStrategyMock(),
$httpUtilsMock,
'providerKey',
$this->createAuthenticationSuccessHandlerMock(),
$this->createAuthenticationFailureHandlerMock(),
$options = array()
);

Expand All @@ -73,6 +77,8 @@ public function throwIfRelyingPartyNotSet()
$this->createSessionAuthenticationStrategyMock(),
$this->createHttpUtilsStub($checkRequestPathReturn = true),
'providerKey',
$this->createAuthenticationSuccessHandlerMock(),
$this->createAuthenticationFailureHandlerMock(),
$options = array()
);

Expand Down Expand Up @@ -103,6 +109,8 @@ public function shouldNotContinueAuthenticationIfRelyingPartySupportsReturnFalse
$this->createSessionAuthenticationStrategyMock(),
$this->createHttpUtilsStub($checkRequestPathReturn = true),
'providerKey',
$this->createAuthenticationSuccessHandlerMock(),
$this->createAuthenticationFailureHandlerMock(),
$options = array()
);

Expand Down Expand Up @@ -143,6 +151,8 @@ public function shouldDuplicateRequestAndPassItToRelyingPartyManageMethod()
$this->createSessionAuthenticationStrategyMock(),
$this->createHttpUtilsStub($checkRequestPathReturn = true),
'providerKey',
$this->createAuthenticationSuccessHandlerMock(),
$this->createAuthenticationFailureHandlerMock(),
$options = array()
);

Expand Down Expand Up @@ -183,6 +193,8 @@ public function shouldAddRequiredAttributesToDuplicatedRequest()
$this->createSessionAuthenticationStrategyMock(),
$this->createHttpUtilsStub($checkRequestPathReturn = true),
'providerKey',
$this->createAuthenticationSuccessHandlerMock(),
$this->createAuthenticationFailureHandlerMock(),
$options = array('required_attributes' => $expectedRequiredAttributes)
);

Expand Down Expand Up @@ -228,6 +240,8 @@ public function shouldAddOptionalAttributesToDuplicatedRequest()
$this->createSessionAuthenticationStrategyMock(),
$this->createHttpUtilsStub($checkRequestPathReturn = true),
'providerKey',
$this->createAuthenticationSuccessHandlerMock(),
$this->createAuthenticationFailureHandlerMock(),
$options = array('optional_attributes' => $expectedOptionalAttributes)
);

Expand Down Expand Up @@ -269,6 +283,8 @@ public function shouldSetRelyingPartyRedirectResponseToEvent()
$this->createSessionAuthenticationStrategyMock(),
$this->createHttpUtilsStub($checkRequestPathReturn = true),
'providerKey',
$this->createAuthenticationSuccessHandlerMock(),
$this->createAuthenticationFailureHandlerMock(),
$options = array()
);

Expand Down Expand Up @@ -301,6 +317,8 @@ public function throwIfRelyingPartyReturnNeitherRedirectResponseOrIdentityProvid
$this->createSessionAuthenticationStrategyMock(),
$this->createHttpUtilsStub($checkRequestPathReturn = true),
'providerKey',
$this->createAuthenticationSuccessHandlerMock(),
$this->createAuthenticationFailureHandlerMock(),
$options = array()
);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -416,6 +434,8 @@ public function shouldCreateOpenIdTokenUsingIdentityProviderResponseAndPassItToA
$this->createSessionAuthenticationStrategyMock(),
$httpUtilsStub,
'providerKey',
$this->createAuthenticationSuccessHandlerStub(),
$this->createAuthenticationFailureHandlerMock(),
$options = array()
);

Expand Down Expand Up @@ -470,6 +490,8 @@ public function shouldAddOpenIdTokenToSecurityContextIfSuccessfullyAuthenticated
$this->createSessionAuthenticationStrategyMock(),
$httpUtilsStub,
'providerKey',
$this->createAuthenticationSuccessHandlerStub(),
$this->createAuthenticationFailureHandlerMock(),
$options = array()
);

Expand Down Expand Up @@ -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;
}
}
1 change: 1 addition & 0 deletions composer.json
Expand Up @@ -24,6 +24,7 @@
"psr-0": { "Fp\\OpenIdBundle": "" }
},
"target-dir": "Fp/OpenIdBundle",
"minimum-stability": "dev",
"extra": {
"branch-alias": {
"dev-master": "1.3-dev"
Expand Down

0 comments on commit a32a2e0

Please sign in to comment.