Skip to content

Commit 194b2b5

Browse files
mrvanesjohanib
authored andcommitted
Add sbs-stub
Align EB/stub with real SBS authz parameters Use SBS api namespace
1 parent b60fac7 commit 194b2b5

File tree

11 files changed

+141
-16
lines changed

11 files changed

+141
-16
lines changed

app/config/parameters.yml.dist

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,3 +312,12 @@ parameters:
312312
# used in the authentication log record. The attributeName will be searched in the response attributes and if present
313313
# the log data will be enriched. The values of the response attributes are the final values after ARP and Attribute Manipulation.
314314
auth.log.attributes: []
315+
316+
##########################################################################################
317+
## SRAM Settings
318+
##########################################################################################
319+
## Currently this is used for the outgoing requests with the PDP and AA client
320+
sram.api_token: "xxx"
321+
sram.authz_location: "http://127.0.0.1:12345/api"
322+
sram.interrupt_location: "http://127.0.0.1:12345/interrupt"
323+
sram.entitlements_location: "http://127.0.0.1:12345/entitlements"

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,22 @@ public function execute(): void
4141

4242
$attributes = $this->getResponseAttributes();
4343

44-
$uid = $attributes['urn:mace:dir:attribute-def:uid'][0];
4544
$id = $this->_request->getId();
45+
46+
$user_id = $attributes['urn:mace:dir:attribute-def:uid'][0];
4647
$continue_url = $this->_server->getUrl('SRAMInterruptService', '') . "?ID=$id";
48+
$service_id = $this->_serviceProvider->entityId;
49+
$issuer_id = $this->_identityProvider->entityId;
4750

4851
$headers = array(
4952
"Authorization: $sramApiToken"
5053
);
5154

5255
$post = array(
53-
'uid' => $uid,
56+
'user_id' => $user_id,
5457
'continue_url' => $continue_url,
58+
'service_id' => $service_id,
59+
'issuer_id' => $issuer_id
5560
);
5661

5762
$options = [
@@ -70,11 +75,15 @@ public function execute(): void
7075
curl_close($ch);
7176

7277
$body = json_decode($data);
73-
error_log("SRAMTestFilter " . var_export($body, true));
78+
// error_log("SRAMTestFilter " . var_export($body, true));
7479

7580
$msg = $body->msg;
7681
if ('interrupt' == $msg) {
7782
$this->_response->setSRAMInterruptNonce($body->nonce);
83+
} else {
84+
if ($body->attributes) {
85+
$this->_responseAttributes = array_merge_recursive($this->_responseAttributes, (array) $body->attributes);
86+
}
7887
}
7988

8089
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public function serve($serviceName, Request $httpRequest)
171171
$this->_server->filterInputAssertionAttributes($receivedResponse, $receivedRequest);
172172

173173
// Send SRAM Interrupt call
174-
if ($receivedResponse->getSRAMInterruptNonce() != Null) {
174+
if ("" != $receivedResponse->getSRAMInterruptNonce()) {
175175
$log->info('Handle SRAM Interrupt callout');
176176

177177
// Add the SRAM step

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,9 @@ public function serve($serviceName, Request $httpRequest)
120120
curl_close($ch);
121121

122122
$body = json_decode($data);
123-
$entitlements = $body->entitlements;
124123

125-
126-
if ($entitlements) {
127-
$attributes['eduPersonEntitlement'] = $entitlements;
124+
if ($body->attributes) {
125+
$attributes = array_merge_recursive($attributes, (array) $body->attributes);
128126
$receivedResponse->getAssertion()->setAttributes($attributes);
129127
}
130128

library/EngineBlock/Saml2/ResponseAnnotationDecorator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class EngineBlock_Saml2_ResponseAnnotationDecorator extends EngineBlock_Saml2_Me
8282

8383
protected $isTransparentErrorResponse = false;
8484

85-
protected $SRAMInterruptNonce = Null;
85+
protected $SRAMInterruptNonce = "";
8686

8787
/**
8888
* @param Response $response

sbs-stub/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
flask

sbs-stub/sbs.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/usr/bin/env python
2+
import json
3+
import logging
4+
import secrets
5+
6+
from flask import Flask, Response, request, render_template
7+
8+
logging.getLogger().setLevel(logging.DEBUG)
9+
logging.getLogger('flask_pyoidc').setLevel(logging.ERROR)
10+
logging.getLogger('oic').setLevel(logging.ERROR)
11+
logging.getLogger('jwkest').setLevel(logging.ERROR)
12+
logging.getLogger('urllib3').setLevel(logging.ERROR)
13+
logging.getLogger('werkzeug').setLevel(logging.ERROR)
14+
15+
app = Flask(__name__, template_folder='templates', static_folder='static')
16+
17+
nonces = {}
18+
19+
20+
def debug(request):
21+
for header in request.headers:
22+
logging.debug(header)
23+
for key, value in request.form.items():
24+
logging.debug(f'POST {key}: {value}')
25+
26+
27+
@app.route('/api/users/proxy_authz_eb', methods=['POST'])
28+
def api():
29+
logging.debug('-> /api/users/proxy_authz_eb')
30+
debug(request)
31+
32+
uid = request.form.get('user_id')
33+
continue_url = request.form.get('continue_url')
34+
service_entity_id = request.form.get('service_id')
35+
issuer_id = request.form.get('issuer_id')
36+
37+
nonce = secrets.token_urlsafe()
38+
nonces[nonce] = (uid, continue_url, service_entity_id, issuer_id)
39+
40+
response = Response(status=200)
41+
body = {
42+
'msg': 'interrupt',
43+
# 'msg': 'skip',
44+
'nonce': nonce,
45+
'attributes': {
46+
'urn:mace:dir:attribute-def:eduPersonEntitlement': [
47+
uid,
48+
nonce,
49+
'urn:foobar'
50+
]
51+
}
52+
}
53+
54+
logging.debug(f'<- {body}')
55+
response.data = json.dumps(body)
56+
57+
return response
58+
59+
60+
@app.route('/api/users/interrupt', methods=['GET'])
61+
def interrupt():
62+
logging.debug('-> /api/users/interrupt')
63+
nonce = request.args.get('nonce')
64+
(uid, continue_url, service_entity_id, issuer_id) = nonces.get(nonce, ('unknown', '/', '/', ''))
65+
response = render_template('interrupt.j2', uid=uid,
66+
service_entity_id=service_entity_id, issuer_id=issuer_id, url=continue_url)
67+
68+
return response
69+
70+
71+
@app.route('/api/users/attributes', methods=['POST'])
72+
def entitlements():
73+
logging.debug('-> /api/users/attributes')
74+
debug(request)
75+
76+
nonce = request.form.get('nonce')
77+
(uid, _, _, _) = nonces.pop(nonce)
78+
79+
response = Response(status=200)
80+
body = {
81+
'attributes': {
82+
'urn:mace:dir:attribute-def:eduPersonEntitlement': [
83+
uid,
84+
nonce,
85+
'urn:foobar',
86+
]
87+
}
88+
}
89+
90+
logging.debug(f'<- {body}')
91+
response.data = json.dumps(body)
92+
93+
return response
94+
95+
96+
if __name__ == "__main__":
97+
app.run(host='0.0.0.0', port=12345, debug=True)

sbs-stub/start

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
./venv/bin/python sbs.py

sbs-stub/templates/interrupt.j2

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<html>
2+
<body>
3+
<p>Hello {{uid}}!!</p>
4+
<p>Coming from {{issuer_id}}</p>
5+
<p>Going to {{service_entity_id}}</p>
6+
<p><input type=checkbox> Accept AUP</p>
7+
<p><a href="{{url}}">Continue</a></p>
8+
</body>
9+
</html>

src/OpenConext/EngineBlock/SRAM/SRAMEndpoint.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ class SRAMEndpoint
4141
*/
4242
private $entitlementsLocation;
4343

44-
public function __construct(?string $apiToken,
45-
?string $authzLocation,
46-
?string $interruptLocation,
47-
?string $entitlementsLocation
48-
)
49-
{
44+
public function __construct(
45+
?string $apiToken,
46+
?string $authzLocation,
47+
?string $interruptLocation,
48+
?string $entitlementsLocation
49+
) {
5050
$this->apiToken = $apiToken;
5151
$this->authzLocation = $authzLocation;
5252
$this->interruptLocation = $interruptLocation;
@@ -84,5 +84,4 @@ public function getEntitlementsLocation() : string
8484
{
8585
return $this->entitlementsLocation;
8686
}
87-
8887
}

0 commit comments

Comments
 (0)