Skip to content

Commit 6c7e221

Browse files
committed
Een werkende integratie flow
1 parent b47631f commit 6c7e221

File tree

53 files changed

+147
-45
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+147
-45
lines changed

app/config/parameters.yml.dist

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,10 @@ parameters:
316316
##########################################################################################
317317
## SRAM Settings
318318
##########################################################################################
319-
## Currently this is used for the outgoing requests with the PDP and AA client
319+
## Config for connecting with SBS server
320+
## base_url must end with /. Locations must not start with /.
320321
sram.api_token: "xxx"
321-
sram.authz_location: "http://127.0.0.1:12345/api"
322-
sram.interrupt_location: "/interrupt"
323-
sram.entitlements_location: "/entitlements"
322+
sram.base_url: "http://127.0.0.1:12345/api/"
323+
sram.authz_location: "authz"
324+
sram.interrupt_location: "interrupt"
325+
sram.entitlements_location: "entitlements"

ci/qa/behat.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ echo -e "\nInstalling database fixtures...\n"
1616
./app/console doctrine:schema:drop --force --env=ci
1717
./app/console doctrine:schema:create --env=ci
1818

19-
echo -e "\nPreparing frontend assets\n"
20-
EB_THEME=skeune ./theme/scripts/prepare-test.js > /dev/null
19+
#echo -e "\nPreparing frontend assets\n"
20+
#EB_THEME=skeune ./theme/scripts/prepare-test.js > /dev/null
2121

2222
chown -R www-data app/cache/
2323
chmod -R 0777 /tmp/eb-fixtures

library/EngineBlock/Corto/Filter/Command/SRAMTestFilter.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?php
22

33
use OpenConext\EngineBlockBundle\Configuration\FeatureConfigurationInterface;
4-
use OpenConext\EngineBlockBundle\Sbs\Dto\InterruptRequest;
4+
use OpenConext\EngineBlockBundle\Exception\InvalidSbsResponseException;
5+
use OpenConext\EngineBlockBundle\Sbs\Dto\AuthzRequest;
56

67
/**
78
* Copyright 2021 Stichting Kennisnet
@@ -37,8 +38,6 @@ public function getResponse()
3738

3839
public function execute(): void
3940
{
40-
$this->_response->setSRAMInterruptNonce('hoeuoeu');
41-
return;
4241
if (!$this->getFeatureConfiguration()->isEnabled('eb.feature_enable_sram_interrupt')) {
4342
return;
4443
}
@@ -49,20 +48,29 @@ public function execute(): void
4948

5049
try {
5150
$request = $this->buildRequest();
52-
$interruptResponse = $this->getSbsClient()->interruptCheck($request);
51+
$interruptResponse = $this->getSbsClient()->authz($request);
5352

5453
if ($interruptResponse->msg === 'interrupt') {
5554
// @TODO Consider if this should be an attribute?
5655
$this->_response->setSRAMInterruptNonce($interruptResponse->nonce);
5756
} elseif ($interruptResponse->msg === 'authorized' && !empty($interruptResponse->attributes)) {
5857
// @TODO make sure this has test coverage
5958
// @TODO Discussed with Bas/Peter: Add list of allowed parameter names via parameters.yml
59+
/**
60+
* "eduPersonEntitlement": ["[email protected]", "[email protected]"],
61+
* "eduPersonPrincipalName": ["[email protected]"],
62+
* "uid": ["test_user"],
63+
* "sshkey": ["ssh_key1", "ssh_key2"]
64+
*/
6065
$this->_responseAttributes = array_merge_recursive(
6166
$this->_responseAttributes,
6267
$interruptResponse->attributes
6368
);
69+
} else {
70+
throw new InvalidSbsResponseException(sprintf('Invalid SBS response received: %s', $interruptResponse->msg));
6471
}
6572
}catch (Throwable $e){
73+
die($e->getMessage());
6674
throw new EngineBlock_Exception_SbsCheckFailed('The SBS server could not be queried: ' . $e->getMessage());
6775
}
6876
}
@@ -78,10 +86,10 @@ private function getFeatureConfiguration(): FeatureConfigurationInterface
7886
}
7987

8088
/**
81-
* @return InterruptRequest
89+
* @return AuthzRequest
8290
* @throws EngineBlock_Corto_ProxyServer_Exception
8391
*/
84-
private function buildRequest(): InterruptRequest
92+
private function buildRequest(): AuthzRequest
8593
{
8694
$attributes = $this->getResponseAttributes();
8795
$id = $this->_request->getId();
@@ -92,7 +100,7 @@ private function buildRequest(): InterruptRequest
92100
$service_id = $this->_serviceProvider->entityId;
93101
$issuer_id = $this->_identityProvider->entityId;
94102

95-
return InterruptRequest::create(
103+
return AuthzRequest::create(
96104
$user_id,
97105
$continue_url,
98106
$service_id,

src/OpenConext/EngineBlock/Http/HttpClient.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ final class HttpClient
3535
*/
3636
public function __construct(ClientInterface $httpClient)
3737
{
38+
// var_dump($httpClient);
3839
$this->httpClient = $httpClient;
3940
}
4041

src/OpenConext/EngineBlockBundle/Resources/config/services.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ services:
208208
class: OpenConext\EngineBlockBundle\Sbs\SbsClient
209209
arguments:
210210
- "@engineblock.sbs.http_client"
211+
- "%sram.base_url%"
211212
- "%sram.authz_location%"
212213
- "%sram.interrupt_location%"
213214
- "%sram.entitlements_location%"
@@ -221,7 +222,7 @@ services:
221222
engineblock.sbs.guzzle_http_client:
222223
class: GuzzleHttp\Client
223224
arguments:
224-
- base_uri: "%sram.authz_location%"
225+
- base_uri: "%sram.base_url%"
225226
options:
226227
headers:
227228
Authentication: "%sram.api_token%"

src/OpenConext/EngineBlockBundle/Sbs/InterruptResponse.php renamed to src/OpenConext/EngineBlockBundle/Sbs/AuthzResponse.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
use OpenConext\EngineBlockBundle\Exception\InvalidSbsResponseException;
2222

23-
final class InterruptResponse
23+
final class AuthzResponse
2424
{
2525
/**
2626
* @var string
@@ -37,7 +37,7 @@ final class InterruptResponse
3737
*/
3838
public $attributes;
3939

40-
public static function fromData(array $jsonData) : InterruptResponse
40+
public static function fromData(array $jsonData) : AuthzResponse
4141
{
4242
if (!isset($jsonData['msg'])) {
4343
throw new InvalidSbsResponseException('Key: "msg" was not found in the SBS response');

src/OpenConext/EngineBlockBundle/Sbs/Dto/InterruptRequest.php renamed to src/OpenConext/EngineBlockBundle/Sbs/Dto/AuthzRequest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
use JsonSerializable;
2222
use OpenConext\EngineBlock\Assert\Assertion;
2323

24-
final class InterruptRequest implements JsonSerializable
24+
final class AuthzRequest implements JsonSerializable
2525
{
2626
/**
2727
* @var string
@@ -48,7 +48,7 @@ public static function create(
4848
string $continueUrl,
4949
string $serviceId,
5050
string $issuerId
51-
) : InterruptRequest {
51+
) : AuthzRequest {
5252
Assertion::string($userId, 'The userId must be a string.');
5353
Assertion::string($continueUrl, 'The continueUrl must be a string.');
5454
Assertion::string($serviceId, 'The serviceId must be a string.');

src/OpenConext/EngineBlockBundle/Sbs/Dto/EntitlementsRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ final class EntitlementsRequest implements JsonSerializable
2929
public $nonce;
3030

3131
public static function create(
32-
string $nonce,
32+
string $nonce
3333
) : EntitlementsRequest {
3434
Assertion::string($nonce, 'The nonce must be a string.');
3535

src/OpenConext/EngineBlockBundle/Sbs/SbsClient.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
use OpenConext\EngineBlock\Http\HttpClient;
2222
use OpenConext\EngineBlockBundle\Sbs\Dto\EntitlementsRequest;
23-
use OpenConext\EngineBlockBundle\Sbs\Dto\InterruptRequest;
23+
use OpenConext\EngineBlockBundle\Sbs\Dto\AuthzRequest;
2424

2525
/***
2626
* @TODO Make sure it has tests
@@ -51,31 +51,38 @@ final class SbsClient implements SbsClientInterface
5151
*/
5252
private $sbsBaseUrl;
5353

54+
/**
55+
* @var string
56+
*/
57+
private $authzLocation;
58+
5459

5560
public function __construct(
5661
HttpClient $httpClient,
5762
string $sbsBaseUrl,
63+
string $authzLocation,
5864
string $interruptLocation,
5965
string $entitlementsLocation,
6066
string $apiToken
6167
) {
6268
$this->httpClient = $httpClient;
6369
$this->sbsBaseUrl = $sbsBaseUrl;
70+
$this->authzLocation = $authzLocation;
6471
$this->interruptLocation = $interruptLocation;
6572
$this->entitlementsLocation = $entitlementsLocation;
6673
$this->apiToken = $apiToken;
6774
}
6875

69-
public function interruptCheck(InterruptRequest $request): InterruptResponse
76+
public function authz(AuthzRequest $request): AuthzResponse
7077
{
7178
$jsonData = $this->httpClient->post(
7279
json_encode($request),
73-
$this->interruptLocation,
80+
$this->authzLocation,
7481
[],
7582
$this->requestHeaders()
7683
);
7784

78-
return InterruptResponse::fromData($jsonData);
85+
return AuthzResponse::fromData($jsonData);
7986
}
8087

8188
public function requestEntitlementsFor(EntitlementsRequest $request): EntitlementsResponse

src/OpenConext/EngineBlockBundle/Sbs/SbsClientInterface.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@
1919
namespace OpenConext\EngineBlockBundle\Sbs;
2020

2121
use OpenConext\EngineBlockBundle\Sbs\Dto\EntitlementsRequest;
22-
use OpenConext\EngineBlockBundle\Sbs\Dto\InterruptRequest;
22+
use OpenConext\EngineBlockBundle\Sbs\Dto\AuthzRequest;
2323

2424
interface SbsClientInterface
2525
{
2626
public function getInterruptLocationLink(string $nonce);
2727

2828
public function requestEntitlementsFor(EntitlementsRequest $request) : EntitlementsResponse;
29-
public function interruptCheck(InterruptRequest $request) : InterruptResponse;
29+
30+
public function authz(AuthzRequest $request) : AuthzResponse;
3031
}

0 commit comments

Comments
 (0)