Skip to content

Commit 0908a63

Browse files
doedjethijskh
authored andcommitted
added support for conditional LOA
1 parent 7e4e30d commit 0908a63

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

docs/stepupsfo.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,28 @@ running the SFO service:
9696
- The entityid and certificate configured in the authsource above.
9797
- The namespace of the subjectattribute you're using (likely something like `urn:collab:person:example.org:`).
9898
- The AssertionConsumerService location: `<your ssp base url>/module.php/stepupsfo/acs.php`.
99+
100+
Conditional LOA
101+
---------------
102+
103+
In addition to setting the `loa` setting for the authproc's config, you can also add an extra `loa` attribute to the user's attributes, for instance by adding the attribute to the LDAP or setting it using core:PHP or any other auth proc. You should of course make sure you put this auth proc before your SFO-related auth procs.
104+
105+
Example:
106+
107+
```php
108+
'authproc' => [
109+
23 => [
110+
'class' => 'core:PHP',
111+
'code' => '
112+
if (someCondition) {
113+
$attributes["loa"] = "http://test.surfconext.nl/assurance/sfo-level3";
114+
} else {
115+
$attributes["loa"] = "http://test.surfconext.nl/assurance/sfo-level1.5";
116+
}
117+
'
118+
],
119+
],
120+
// other authprocs for SFO
121+
```
122+
123+
The `loa` set in the authproc config is used as the default (optional). The `loa` set in the user's attributes will take precedence. Setting the `loa` to an empty string will skip the SFO. Not setting the `loa` will result in an error.

src/Auth/Process/SFO.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use SimpleSAML\Module;
1818
use SimpleSAML\Module\saml\Message;
1919

20+
use function array_key_exists;
2021
use function in_array;
2122
use function sprintf;
2223
use function substr;
@@ -33,6 +34,9 @@ class SFO extends Auth\ProcessingFilter
3334
/** @var \SimpleSAML\Configuration */
3435
private Configuration $idpMetadata;
3536

37+
/** @var array */
38+
private array $config = [];
39+
3640
/** @var string */
3741
private string $subjectidattribute;
3842

@@ -57,9 +61,8 @@ public function __construct(array $config, $reserved)
5761

5862
$this->idpMetadata = $this->getIdPMetadata($config['idpEntityid']);
5963

60-
$config['AuthnContextClassRef'] = $config['loa'];
6164
$config['entityid'] = $config['entityID'];
62-
$this->metadata = Configuration::loadFromArray($config);
65+
$this->config = $config;
6366
}
6467

6568

@@ -77,6 +80,24 @@ public function process(array &$state): void
7780
}
7881
}
7982

83+
if (array_key_exists('loa', $state['Attributes'])) {
84+
// LOA is present in User's attributes
85+
$loa = $state['Attributes']['loa'];
86+
} else if (array_key_exists('loa', $this->config)) {
87+
// LOA set in SFO config is default.
88+
$loa = $this->config['loa'];
89+
} else {
90+
throw new Exception("SFO - No LOA set.");
91+
}
92+
if (empty($loa)) {
93+
// LOA is set to an empty string, skip SFO
94+
return;
95+
}
96+
Logger::info('SFO - requested LOA: ' . $loa);
97+
98+
$this->config['AuthnContextClassRef'] = $loa;
99+
$this->metadata = Configuration::loadFromArray($this->config);
100+
80101
$state['sfo:sp:metadata'] = $this->metadata;
81102
$state['sfo:idp:entityid'] = $this->idpMetadata->getString('entityid');
82103
$samlstateid = Auth\State::saveState($state, 'stepupsfo:pre');

0 commit comments

Comments
 (0)