Skip to content

Commit 0f75964

Browse files
authored
Merge pull request #39 from tmilos/idp-loop
Prevent IDP loop when misconfigured
2 parents f0018bb + afb1444 commit 0f75964

4 files changed

Lines changed: 12 additions & 8 deletions

File tree

src/LightSaml/SpBundle/DependencyInjection/Security/Factory/LightSamlSpFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function addConfiguration(NodeDefinition $node)
2424
parent::addConfiguration($node);
2525
$node
2626
->children()
27-
->booleanNode('force')->defaultFalse()->end()
27+
->booleanNode('force')->defaultTrue()->end()
2828
->scalarNode('username_mapper')->defaultValue('lightsaml_sp.username_mapper.simple')->end()
2929
->scalarNode('user_creator')->defaultNull()->end()
3030
->scalarNode('attribute_mapper')->defaultValue('lightsaml_sp.attribute_mapper.simple')->end()

src/LightSaml/SpBundle/Security/Authentication/Provider/LightsSamlSpAuthenticationProvider.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,15 +201,19 @@ private function createUser(SamlSpResponseToken $token)
201201
/**
202202
* @param SamlSpResponseToken $token
203203
*
204-
* @return null|string
204+
* @return string
205205
*/
206206
private function createDefaultUser(SamlSpResponseToken $token)
207207
{
208-
if (null === $this->usernameMapper) {
209-
return null;
208+
$result = null;
209+
if ($this->usernameMapper) {
210+
$result = $this->usernameMapper->getUsername($token->getResponse());
211+
}
212+
if (!$result) {
213+
$result = 'Anon.';
210214
}
211215

212-
return $this->usernameMapper->getUsername($token->getResponse());
216+
return $result;
213217
}
214218

215219
/**

tests/LightSaml/SpBundle/Tests/DependencyInjection/Security/Factory/LightSamlSpFactoryTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function test_position()
3131
public function configuration_provider()
3232
{
3333
return [
34-
['force', BooleanNode::class, false],
34+
['force', BooleanNode::class, true],
3535
['username_mapper', ScalarNode::class, 'lightsaml_sp.username_mapper.simple'],
3636
['user_creator', ScalarNode::class, null],
3737
['attribute_mapper', ScalarNode::class, 'lightsaml_sp.attribute_mapper.simple'],
@@ -177,7 +177,7 @@ public function test_injects_token_factory_to_auth_provider()
177177
private function getDefaultConfig()
178178
{
179179
return [
180-
'force' => false,
180+
'force' => true,
181181
'username_mapper' => 'lightsaml_sp.username_mapper.simple',
182182
'token_factory' => 'lightsaml_sp.token_factory',
183183
'user_creator' => 'some.user.creator',

tests/LightSaml/SpBundle/Tests/Security/Authentication/Provider/LightsSamlSpAuthenticationProviderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ public function test_throws_logic_exception_if_attribute_mapper_does_not_return_
427427
*/
428428
public function test_throws_authentication_exception_when_unable_to_resolve_user()
429429
{
430-
$provider = new LightsSamlSpAuthenticationProvider('main', null, true);
430+
$provider = new LightsSamlSpAuthenticationProvider('main', null, false);
431431
$provider->authenticate(new SamlSpResponseToken(new Response(), 'main'));
432432
}
433433

0 commit comments

Comments
 (0)