Skip to content

Commit e5e4d1f

Browse files
committed
refactor: replace CurrentCorrelationId getter/setter with public property
1 parent 3c4b4f2 commit e5e4d1f

11 files changed

Lines changed: 37 additions & 55 deletions

File tree

library/EngineBlock/Application/DiContainer.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use OpenConext\EngineBlock\Metadata\Factory\Factory\ServiceProviderFactory;
2121
use OpenConext\EngineBlock\Metadata\LoaRepository;
2222
use OpenConext\EngineBlock\Metadata\MetadataRepository\MetadataRepositoryInterface;
23+
use OpenConext\EngineBlock\Request\CorrelationIdService;
2324
use OpenConext\EngineBlock\Service\MfaHelperInterface;
2425
use OpenConext\EngineBlock\Service\ReleaseAsEnforcer;
2526
use OpenConext\EngineBlock\Service\TimeProvider\TimeProviderInterface;
@@ -615,11 +616,11 @@ public function getNameIdSubstituteResolver()
615616
}
616617

617618
/**
618-
* @return \OpenConext\EngineBlock\Request\CorrelationIdService
619+
* @return CorrelationIdService
619620
*/
620-
public function getCorrelationIdService(): \OpenConext\EngineBlock\Request\CorrelationIdService
621+
public function getCorrelationIdService(): CorrelationIdService
621622
{
622-
return $this->container->get(\OpenConext\EngineBlock\Request\CorrelationIdService::class);
623+
return $this->container->get(CorrelationIdService::class);
623624
}
624625

625626
/**

library/EngineBlock/Corto/Module/Service/ContinueToIdp.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ public function serve($serviceName, Request $httpRequest)
8585
);
8686
}
8787

88-
$authnRequestRepository = EngineBlock_ApplicationSingleton::getInstance()
89-
->getDiContainer()
90-
->getAuthnRequestSessionRepository();
88+
$container = EngineBlock_ApplicationSingleton::getInstance()->getDiContainer();
89+
90+
$authnRequestRepository = $container->getAuthnRequestSessionRepository();
9191
$request = $authnRequestRepository->findRequestById($id);
9292

9393
if (!$request) {
@@ -96,13 +96,7 @@ public function serve($serviceName, Request $httpRequest)
9696
);
9797
}
9898

99-
// Resolve here so log entries emitted during this leg carry the correlation ID.
100-
// ProxyServer::sendAuthenticationRequest will also call mint()+link()+resolve()
101-
// on the SP request ID — that is idempotent and sets the same value.
102-
// The IdP request ID is only resolvable in AssertionConsumer (Leg 3).
103-
$correlationIdService = EngineBlock_ApplicationSingleton::getInstance()
104-
->getDiContainer()
105-
->getCorrelationIdService();
99+
$correlationIdService = $container->getCorrelationIdService();
106100
$correlationIdService->resolve($id);
107101

108102
// Flush log if SP or IdP has additional logging enabled

library/EngineBlock/Corto/Module/Service/SingleSignOn.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public function __construct(
7373
public function serve($serviceName, Request $httpRequest)
7474
{
7575
$application = EngineBlock_ApplicationSingleton::getInstance();
76+
$container = $application->getDiContainer();
7677

7778
$log = $this->_server->getLogger();
7879

@@ -202,9 +203,9 @@ public function serve($serviceName, Request $httpRequest)
202203
// Multiple IdPs found...
203204

204205
// Auto-select IdP when 'feature_enable_sso_notification' is enabled and send AuthenticationRequest on success
205-
if ($application->getDiContainer()->getFeatureConfiguration()->isEnabled("eb.enable_sso_notification")) {
206-
$idpEntityId = $application->getDiContainer()->getSsoNotificationService()->
207-
handleSsoNotification($application->getDiContainer()->getSymfonyRequest()->cookies, $this->_server);
206+
if ($container->getFeatureConfiguration()->isEnabled("eb.enable_sso_notification")) {
207+
$idpEntityId = $container->getSsoNotificationService()->
208+
handleSsoNotification($container->getSymfonyRequest()->cookies, $this->_server);
208209

209210
if (!empty($idpEntityId)) {
210211
try {
@@ -220,8 +221,8 @@ public function serve($serviceName, Request $httpRequest)
220221
}
221222

222223
// Auto-select IdP when 'wayf.rememberChoice' feature is enabled and is allowed for the current request
223-
if (($application->getDiContainer()->getRememberChoice() === true) && !($request->getForceAuthn() || $request->isDebugRequest())) {
224-
$cookies = $application->getDiContainer()->getSymfonyRequest()->cookies->all();
224+
if (($container->getRememberChoice() === true) && !($request->getForceAuthn() || $request->isDebugRequest())) {
225+
$cookies = $container->getSymfonyRequest()->cookies->all();
225226
if (array_key_exists('rememberchoice', $cookies)) {
226227
$remembered = json_decode($cookies['rememberchoice']);
227228
if (array_search($remembered, $candidateIDPs) !== false) {
@@ -240,10 +241,10 @@ public function serve($serviceName, Request $httpRequest)
240241
return;
241242
}
242243

243-
$authnRequestRepository = $application->getDiContainer()->getAuthnRequestSessionRepository();
244+
$authnRequestRepository = $container->getAuthnRequestSessionRepository();
244245
$authnRequestRepository->store($request);
245246

246-
$correlationIdService = $application->getDiContainer()->getCorrelationIdService();
247+
$correlationIdService = $container->getCorrelationIdService();
247248
$correlationIdService->mint($request->getId());
248249
$correlationIdService->resolve($request->getId());
249250

library/EngineBlock/Corto/ProxyServer.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -461,21 +461,17 @@ public function sendAuthenticationRequest(
461461
}
462462
}
463463

464-
$authenticationState = EngineBlock_ApplicationSingleton::getInstance()->getDiContainer()
465-
->getAuthenticationStateHelper()
466-
->getAuthenticationState();
464+
$container = EngineBlock_ApplicationSingleton::getInstance()->getDiContainer();
465+
466+
$authenticationState = $container->getAuthenticationStateHelper()->getAuthenticationState();
467467
$authenticationState->startAuthenticationOnBehalfOf($ebRequest->getId(), $serviceProvider);
468468

469469
// Store the original Request
470-
$authnRequestRepository = EngineBlock_ApplicationSingleton::getInstance()
471-
->getDiContainer()
472-
->getAuthnRequestSessionRepository();
470+
$authnRequestRepository = $container->getAuthnRequestSessionRepository();
473471
$authnRequestRepository->store($spRequest);
474472
$authnRequestRepository->link($ebRequest, $spRequest);
475473

476-
$correlationIdService = EngineBlock_ApplicationSingleton::getInstance()
477-
->getDiContainer()
478-
->getCorrelationIdService();
474+
$correlationIdService = $container->getCorrelationIdService();
479475
$correlationIdService->mint($spRequest->getId());
480476
$correlationIdService->link($ebRequest->getId(), $spRequest->getId());
481477
$correlationIdService->resolve($spRequest->getId());

src/OpenConext/EngineBlock/Logger/Processor/CorrelationIdProcessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function __construct(private readonly CurrentCorrelationId $correlationId
3030

3131
public function __invoke(LogRecord $record): LogRecord
3232
{
33-
$record->extra['correlation_id'] = $this->correlationId->get();
33+
$record->extra['correlation_id'] = $this->correlationId->correlationId;
3434

3535
return $record;
3636
}

src/OpenConext/EngineBlock/Request/CorrelationId.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ public function __construct(public readonly string $correlationId)
2626

2727
public static function mint(): self
2828
{
29-
return new self(bin2hex(random_bytes(16)));
29+
return new self(bin2hex(random_bytes(8)));
3030
}
3131
}

src/OpenConext/EngineBlock/Request/CorrelationIdService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function resolve(?string $requestId): void
4747
$cid = $this->repository->find($requestId);
4848

4949
if ($cid !== null) {
50-
$this->current->set($cid->correlationId);
50+
$this->current->correlationId = $cid->correlationId;
5151
}
5252
}
5353
}

src/OpenConext/EngineBlock/Request/CurrentCorrelationId.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,5 @@
2020

2121
final class CurrentCorrelationId
2222
{
23-
private ?string $correlationId = null;
24-
25-
public function set(string $correlationId): void
26-
{
27-
$this->correlationId = $correlationId;
28-
}
29-
30-
public function get(): ?string
31-
{
32-
return $this->correlationId;
33-
}
23+
public ?string $correlationId = null;
3424
}

tests/unit/OpenConext/EngineBlock/Logger/Processor/CorrelationIdProcessorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class CorrelationIdProcessorTest extends TestCase
3434
public function correlation_id_is_added_to_the_record(): void
3535
{
3636
$correlationId = new CurrentCorrelationId();
37-
$correlationId->set('test-correlation-id');
37+
$correlationId->correlationId = 'test-correlation-id';
3838

3939
$processor = new CorrelationIdProcessor($correlationId);
4040
$record = new LogRecord(

tests/unit/OpenConext/EngineBlock/Request/CorrelationIdFlowTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,26 +77,26 @@ public function test_wayf_flow_all_four_legs_share_the_same_correlation_id(): vo
7777
// Leg 1 — SSO: mint the correlation ID.
7878
$this->service->mint($spRequestId);
7979
$this->service->resolve($spRequestId);
80-
$mintedCx = $this->current->get();
80+
$mintedCx = $this->current->correlationId;
8181
$this->assertNotNull($mintedCx, 'SSO must mint a correlation ID');
8282

8383
// Leg 2 — ContinueToIdp: resolves SP request ID A.
8484
$leg2Current = new CurrentCorrelationId();
8585
$this->newServiceWithCurrent($leg2Current)->resolve($spRequestId);
86-
$this->assertSame($mintedCx, $leg2Current->get(), 'ContinueToIdp must see the same correlation ID');
86+
$this->assertSame($mintedCx, $leg2Current->correlationId, 'ContinueToIdp must see the same correlation ID');
8787

8888
// ProxyServer links the IdP request ID to the SP request ID.
8989
$this->service->link($idpRequestId, $spRequestId);
9090

9191
// Leg 3 — ACS: IdP response InResponseTo=B, resolves via B.
9292
$leg3Current = new CurrentCorrelationId();
9393
$this->newServiceWithCurrent($leg3Current)->resolve($idpRequestId);
94-
$this->assertSame($mintedCx, $leg3Current->get(), 'ACS must see the same correlation ID');
94+
$this->assertSame($mintedCx, $leg3Current->correlationId, 'ACS must see the same correlation ID');
9595

9696
// Leg 4 — Consent: resolves SP request ID A again.
9797
$leg4Current = new CurrentCorrelationId();
9898
$this->newServiceWithCurrent($leg4Current)->resolve($spRequestId);
99-
$this->assertSame($mintedCx, $leg4Current->get(), 'Consent must see the same correlation ID');
99+
$this->assertSame($mintedCx, $leg4Current->correlationId, 'Consent must see the same correlation ID');
100100
}
101101

102102
// ── Direct path (no WAYF) ─────────────────────────────────────────────────
@@ -109,7 +109,7 @@ public function test_direct_flow_acs_and_consent_share_the_correlation_id_minted
109109
$this->service->mint($spRequestId);
110110
$this->service->link($idpRequestId, $spRequestId);
111111
$this->service->resolve($spRequestId);
112-
$mintedCx = $this->current->get();
112+
$mintedCx = $this->current->correlationId;
113113
$this->assertNotNull($mintedCx);
114114

115115
$ids = $this->session->get('CorrelationIds');
@@ -157,6 +157,6 @@ public function test_replaying_an_sso_request_does_not_change_the_correlation_id
157157
public function test_unknown_request_id_does_not_set_correlation_id(): void
158158
{
159159
$this->service->resolve('_unknown-id');
160-
$this->assertNull($this->current->get(), 'Correlation ID must remain null for unknown request IDs');
160+
$this->assertNull($this->current->correlationId, 'Correlation ID must remain null for unknown request IDs');
161161
}
162162
}

0 commit comments

Comments
 (0)