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

Commit c752748

Browse files
committed
allow attribute filters in ProxyFilter
1 parent b8c7365 commit c752748

File tree

1 file changed

+43
-23
lines changed

1 file changed

+43
-23
lines changed

lib/Auth/Process/ProxyFilter.php

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,26 @@
88
/**
99
* Class sspmod_perun_Auth_Process_ProxyFilter
1010
*
11-
* This filter allows to disable nested filter for particular SP.
11+
* This filter allows to disable nested filter for particular SP
12+
* or for users with one of (black)listed attribute values.
13+
* When any of the values matches, the nested filter is NOT run.
1214
* SPs are defined by theirs entityID in property 'filterSPs'.
13-
* nested filter is defined in property config as regular filter.
15+
* User attributes are defined as a map 'attrName'=>['value1','value2']
16+
* in property 'filterAttributes'.
17+
* Nested filter is defined in property config as regular filter.
1418
*
1519
* example usage:
1620
*
1721
* 10 => [
1822
* 'class' => 'perun:ProxyFilter',
1923
* 'filterSPs' => ['disableSpEntityId01', 'disableSpEntityId02'],
24+
* 'filterAttributes' => [
25+
* 'eduPersonPrincipalName' => ['[email protected]'],
26+
* 'eduPersonAffiliation' => ['affiliate','member'],
27+
* ],
2028
* 'config' => [
2129
* 'class' => 'perun:NestedFilter',
22-
* ...
30+
* // ...
2331
* ],
2432
* ]
2533
*
@@ -31,44 +39,56 @@ class ProxyFilter extends \SimpleSAML\Auth\ProcessingFilter
3139
private $config;
3240
private $nestedClass;
3341
private $filterSPs;
42+
private $filterAttributes;
3443
private $reserved;
3544

3645
public function __construct($config, $reserved)
3746
{
3847
parent::__construct($config, $reserved);
3948

40-
if (!isset($config['config'])) {
41-
throw new Exception(
42-
"perun:ProxyFilter: missing mandatory configuration option 'config'"
43-
);
44-
}
45-
if (!isset($config['config']['class'])) {
46-
throw new Exception(
47-
"perun:ProxyFilter: missing mandatory configuration option config['class']"
48-
);
49-
}
50-
if (!isset($config['filterSPs'])) {
51-
throw new Exception(
52-
"perun:ProxyFilter: missing mandatory configuration option 'filterSPs'."
53-
);
54-
}
49+
$conf = SimpleSAML\Configuration::loadFromArray($config);
50+
$this->config = $conf->getArray('config');
51+
$this->nestedClass = SimpleSAML\Configuration::loadFromArray($this->config)->getString('class');
52+
unset($this->config['class']);
53+
$this->filterSPs = $conf->getArray('filterSPs', []);
54+
$this->filterAttributes = $conf->getArray('filterAttributes', []);
5555

56-
$this->nestedClass = (string)$config['config']['class'];
57-
unset($config['config']['class']);
58-
$this->config = (array)$config['config'];
59-
$this->filterSPs = (array)$config['filterSPs'];
6056
$this->reserved = (array)$reserved;
6157
}
6258

6359
public function process(&$request)
6460
{
6561
assert('is_array($request)');
6662

63+
foreach ($this->filterAttributes as $attr => $values) {
64+
if (!isset($request['Attributes'][$attr]) || !is_array($request['Attributes'][$attr])) {
65+
continue;
66+
}
67+
foreach ($values as $value) {
68+
if (in_array($value, $request['Attributes'][$attr])) {
69+
Logger::info(
70+
sprintf(
71+
"perun.ProxyFilter: Filtering out filter %s because %s contains %s",
72+
$this->nestedClass,
73+
$attr,
74+
$value
75+
);
76+
);
77+
78+
return;
79+
}
80+
}
81+
}
82+
6783
foreach ($this->filterSPs as $sp) {
6884
$currentSp = $request['Destination']['entityid'];
6985
if ($sp == $currentSp) {
7086
Logger::info(
71-
"perun.ProxyFilter: Filtering out filter $this->nestedClass for SP $currentSp"
87+
sprintf(
88+
"perun.ProxyFilter: Filtering out filter %s for SP %s",
89+
$this->nestedClass,
90+
$currentSp
91+
);
7292
);
7393

7494
return;

0 commit comments

Comments
 (0)