Skip to content

Commit deec5b9

Browse files
authored
Merge pull request #468 from OpenConext/feature/467-fix-InstitutionConfigNotFound
Fix InstitutionConfigurationNotFoundException when GSSP fallback attr…
2 parents ff63557 + 5e3a78a commit deec5b9

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

src/Surfnet/StepupGateway/SecondFactorOnlyBundle/Service/Gateway/GsspFallbackService.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use Surfnet\StepupGateway\GatewayBundle\Controller\SecondFactorController;
2525
use Surfnet\StepupGateway\GatewayBundle\Entity\InstitutionConfigurationRepository;
2626
use Surfnet\StepupGateway\GatewayBundle\Entity\SecondFactorRepository;
27+
use Surfnet\StepupGateway\GatewayBundle\Exception\InstitutionConfigurationNotFoundException;
2728
use Surfnet\StepupGateway\GatewayBundle\Saml\Proxy\ProxyStateHandler;
2829
use Surfnet\StepupGateway\GatewayBundle\Service\SecondFactor\SecondFactorInterface;
2930
use Surfnet\StepupGateway\GatewayBundle\Service\WhitelistService;
@@ -87,6 +88,10 @@ public function handleSamlGsspExtension(LoggerInterface $logger, ReceivedAuthnRe
8788
}
8889
}
8990

91+
/**
92+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
93+
* @SuppressWarnings(PHPMD.NPathComplexity)
94+
*/
9095
public function determineGsspFallbackNeeded(
9196
string $identityNameId,
9297
string $authenticationMode,
@@ -135,7 +140,14 @@ public function determineGsspFallbackNeeded(
135140
return false;
136141
}
137142

138-
$institutionConfiguration = $this->institutionConfigurationRepository->getInstitutionConfiguration($institution);
143+
try {
144+
$institutionConfiguration = $this->institutionConfigurationRepository->getInstitutionConfiguration($institution);
145+
} catch (InstitutionConfigurationNotFoundException) {
146+
$this->stateHandler->setSecondFactorIsFallback(false);
147+
$logger->info('Gssp Fallback configured but not used, GSSP institution configuration is not found');
148+
return false;
149+
}
150+
139151
if (!$institutionConfiguration->ssoRegistrationBypass) {
140152
$this->stateHandler->setSecondFactorIsFallback(false);
141153
$logger->info('Gssp Fallback configured but not used, GSSP fallback is not enabled for the institution');

src/Surfnet/StepupGateway/SecondFactorOnlyBundle/Tests/Service/Gateway/GsspFallback/GsspFallbackServiceTest.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use Surfnet\StepupGateway\GatewayBundle\Entity\InstitutionConfiguration;
2727
use Surfnet\StepupGateway\GatewayBundle\Entity\InstitutionConfigurationRepository;
2828
use Surfnet\StepupGateway\GatewayBundle\Entity\SecondFactorRepository;
29+
use Surfnet\StepupGateway\GatewayBundle\Exception\InstitutionConfigurationNotFoundException;
2930
use Surfnet\StepupGateway\GatewayBundle\Saml\Proxy\ProxyStateHandler;
3031
use Surfnet\StepupGateway\GatewayBundle\Service\WhitelistService;
3132
use Surfnet\StepupGateway\GatewayBundle\Tests\TestCase\GatewaySamlTestCase;
@@ -299,4 +300,53 @@ public function it_can_create_a_gssp_fallback_token(): void
299300
$this->assertSame($locale, $token->getDisplayLocale());
300301
}
301302

303+
/**
304+
* @test
305+
*/
306+
public function it_treats_missing_institution_configuration_as_default(): void
307+
{
308+
$subject = 'urn:collab:person:dev.openconext.local:john_haack';
309+
$gsspSubject = 'john_haack@dev.openconext.local';
310+
$gsspInstitution = 'dev.openconext.local';
311+
$locale = 'en_GB';
312+
$preferredLoa = 1.5;
313+
$authenticationMode = SecondFactorController::MODE_SFO;
314+
315+
$this->stateHandler->shouldReceive('getGsspUserAttributeSubject')
316+
->once()
317+
->andReturn($gsspSubject);
318+
319+
$this->stateHandler->shouldReceive('getGsspUserAttributeInstitution')
320+
->once()
321+
->andReturn($gsspInstitution);
322+
323+
$this->institutionConfiguration->shouldReceive('getInstitutionConfiguration')
324+
->with($gsspInstitution)
325+
->andThrow(new InstitutionConfigurationNotFoundException());
326+
327+
$whitelistService = m::mock(WhitelistService::class);
328+
$whitelistService->shouldReceive('contains')
329+
->once()
330+
->with($gsspInstitution)
331+
->andReturn(true);
332+
333+
// When institution configuration is not found, it means default config
334+
// So the fallback should not be started
335+
$this->stateHandler->shouldReceive('setSecondFactorIsFallback')
336+
->with(false)
337+
->once();
338+
339+
$this->stateHandler->shouldNotReceive('setPreferredLocale');
340+
341+
$result = $this->service->determineGsspFallbackNeeded(
342+
$subject,
343+
$authenticationMode,
344+
new Loa($preferredLoa, 'example.org:loa-level'),
345+
$whitelistService,
346+
$this->logger,
347+
$locale,
348+
);
349+
350+
$this->assertFalse($result);
351+
}
302352
}

0 commit comments

Comments
 (0)