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

Commit c763ad9

Browse files
author
Dominik Frantisek Bucik
committed
feat: 🎸 DropUserAttributes authProcFilter
1 parent 301139a commit c763ad9

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

config-templates/processFilterConfigurations-example.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,17 @@ Configuration options:
229229
'perun_approval_url' => 'https://signup.perun.cesnet.cz/fed/registrar/?vo=cesnet&group=aup'
230230
],
231231
```
232+
233+
## DropUserAttributes
234+
235+
Drops specified user attributes from the `$request['Attributes']` variable.
236+
237+
Configuration options:
238+
* `attribute_names`: list of attribute names which will be dropped.
239+
240+
```php
241+
10 => [
242+
'class' => 'perun:DropUserAttributes',
243+
'attribute_names' => ['aup', 'eppn', 'eduPersonTargetedID']
244+
],
245+
```
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\Module\perun\Auth\Process;
6+
7+
use SimpleSAML\Auth\ProcessingFilter;
8+
use SimpleSAML\Configuration;
9+
use SimpleSAML\Logger;
10+
use SimpleSAML\Module\perun\PerunConstants;
11+
12+
/**
13+
* Drop specified user attributes
14+
*/
15+
class DropUserAttributes extends ProcessingFilter
16+
{
17+
public const STAGE = 'perun:DropUserAttributes';
18+
public const DEBUG_PREFIX = self::STAGE . ' - ';
19+
20+
public const ATTRIBUTE_NAMES = 'attribute_names';
21+
22+
private $attributeNames;
23+
private $filterConfig;
24+
25+
public function __construct($config, $reserved)
26+
{
27+
parent::__construct($config, $reserved);
28+
$this->filterConfig = Configuration::loadFromArray($config);
29+
30+
$this->attributeNames = $this->filterConfig->getArray(self::ATTRIBUTE_NAMES, []);
31+
if (empty($this->attributeNames)) {
32+
Logger::warning(
33+
self::DEBUG_PREFIX . 'Invalid configuration: no name of attributes to be dropped has '
34+
. 'been configured. Use option \'' . self::ATTRIBUTE_NAMES . '\' to configure the name of the attribute.'
35+
);
36+
}
37+
}
38+
39+
public function process(&$request)
40+
{
41+
assert(is_array($request));
42+
if (empty($this->attributeNames)) {
43+
Logger::warning(
44+
self::DEBUG_PREFIX . 'List of attribute names which should be dropped is empty. Skip processing.'
45+
);
46+
} elseif (empty($request[PerunConstants::ATTRIBUTES])) {
47+
Logger::warning(self::DEBUG_PREFIX . 'There are no attributes in the request. Skip processing.');
48+
49+
return;
50+
}
51+
52+
$attributes = &$request[PerunConstants::ATTRIBUTES];
53+
foreach ($this->attributeNames as $attributeName) {
54+
if (isset($attributes[$attributeName])) {
55+
unset($attributes[$attributeName]);
56+
Logger::debug(self::DEBUG_PREFIX . 'Removed attribute \'' . $attributeName . '\'.');
57+
}
58+
}
59+
}
60+
}

0 commit comments

Comments
 (0)