Skip to content
This repository was archived by the owner on Sep 19, 2022. It is now read-only.

Commit 346f825

Browse files
authored
Merge pull request #29 from pajavyskocil/AuthnContextClassRef
Added filtering for AuthnContextClassRef
2 parents f47dbdf + 499e5c5 commit 346f825

File tree

2 files changed

+51
-6
lines changed

2 files changed

+51
-6
lines changed

config-templates/module_perun.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,10 @@
3939
*/
4040
//'disco.disableWhitelisting' => true,
4141

42+
/**
43+
* Specify prefix for filtering AuthnContextClassRef
44+
* All AuthnContextClassRef values starts with this prefix will be removed before the request will be send to IdP
45+
*/
46+
'disco.removeAuthnContextClassRefPrefix' => 'urn:cesnet:proxyidp:',
47+
4248
);

lib/Disco.php

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class sspmod_perun_Disco extends sspmod_discopower_PowerIdPDisco
1717
{
1818
const CONFIG_FILE_NAME = 'module_perun.php';
1919
const PROPNAME_DISABLE_WHITELISTING = 'disco.disableWhitelisting';
20+
const PROPNAME_PREFIX = "disco.removeAuthnContextClassRefPrefix";
2021

2122
private $originalsp;
2223
private $whitelist;
@@ -26,18 +27,33 @@ class sspmod_perun_Disco extends sspmod_discopower_PowerIdPDisco
2627

2728
public function __construct(array $metadataSets, $instance)
2829
{
29-
parent::__construct($metadataSets, $instance);
30-
31-
parse_str(parse_url($this->returnURL)['query'], $query);
30+
if (!array_key_exists('return', $_GET)) {
31+
throw new Exception('Missing parameter: return');
32+
} else {
33+
$returnURL = \SimpleSAML\Utils\HTTP::checkURLAllowed($_GET['return']);
34+
}
35+
parse_str(parse_url($returnURL)['query'], $query);
3236
$id = explode(":", $query['AuthID'])[0];
3337
$state = SimpleSAML_Auth_State::loadState($id, 'saml:sp:sso', true);
38+
39+
if (isset($state['saml:RequestedAuthnContext']['AuthnContextClassRef'])) {
40+
$this->authnContextClassRef = $state['saml:RequestedAuthnContext']['AuthnContextClassRef'];
41+
$this->removeAuthContextClassRefWithPrefix($state);
42+
}
43+
SimpleSAML\Logger::debug(print_r($state['saml:RequestedAuthnContext'], true));
44+
45+
$id = SimpleSAML_Auth_State::saveState($state, 'saml:sp:sso');
46+
47+
$e = explode("=", $returnURL)[0];
48+
$newReturnURL = $e . "=" . urlencode($id);
49+
$_GET['return'] = $newReturnURL;
50+
51+
parent::__construct($metadataSets, $instance);
52+
3453
$this->originalsp = $state['SPMetadata'];
3554
$this->service = new sspmod_perun_IdpListsServiceCsv();
3655
$this->whitelist = $this->service->listToArray("whitelist");
3756
$this->greylist = $this->service->listToArray("greylist");
38-
if (isset($state['saml:RequestedAuthnContext']['AuthnContextClassRef'])) {
39-
$this->authnContextClassRef = $state['saml:RequestedAuthnContext']['AuthnContextClassRef'];
40-
}
4157
}
4258

4359

@@ -217,4 +233,27 @@ public static function buildContinueUrlWithoutIdPEntityId($entityID, $return, $r
217233
return $url;
218234
}
219235

236+
/**
237+
* This method remove all AuthnContextClassRef which start with prefix from configuration
238+
* @param $state
239+
*/
240+
public function removeAuthContextClassRefWithPrefix(&$state) {
241+
$conf = SimpleSAML_Configuration::getConfig(self::CONFIG_FILE_NAME);
242+
$prefix = $conf->getString(self::PROPNAME_PREFIX, null);
243+
244+
if (is_null($prefix)) {
245+
return;
246+
}
247+
unset($state['saml:RequestedAuthnContext']['AuthnContextClassRef']);
248+
$array = array();
249+
foreach ($this->authnContextClassRef as $value) {
250+
if (!(substr($value, 0, strlen($prefix)) === $prefix)) {
251+
array_push($array, $value);
252+
}
253+
}
254+
if (!empty($array)) {
255+
$state['saml:RequestedAuthnContext']['AuthnContextClassRef'] = $array;
256+
}
257+
}
258+
220259
}

0 commit comments

Comments
 (0)