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

Commit 6e1e30f

Browse files
tauceti2vyskocilpavel
authored andcommitted
Support for AARC spec for groupNames
1 parent e2f237f commit 6e1e30f

File tree

1 file changed

+31
-7
lines changed

1 file changed

+31
-7
lines changed

lib/Auth/Process/PerunGroups.php

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
* This filter extracts group names from cached groups from PerunIdentity filter and save them into attribute defined by attrName.
77
* By default attribute value will be filled with the groupNamePrefix + groupName.
88
*
9+
* If groupNameAARC is enabled for SP or it is enabled globaly in perun_module.conf, then use groupNamePrefix
10+
* and groupNameAuthority to construct group name according to the
11+
* https://aarc-project.eu/wp-content/uploads/2017/11/AARC-JRA1.4A-201710.pdf
12+
*
913
* It is also capable of translation of (renames) group names using 'groupMapping' attribute in SP metadata.
1014
*
1115
* @author Ondrej Velisek <[email protected]>
@@ -14,28 +18,38 @@
1418
class sspmod_perun_Auth_Process_PerunGroups extends SimpleSAML_Auth_ProcessingFilter
1519
{
1620

21+
const CONFIG_FILE_NAME = 'module_perun.php';
22+
1723
const GROUPNAMEPREFIX_ATTR = 'groupNamePrefix';
24+
const GROUPNAMEAARC_ATTR = 'groupNameAARC';
25+
const GROUPNAMEAUTHORITY_ATTR = 'groupNameAuthority';
1826

1927
private $attrName;
2028
private $groupNamePrefix;
29+
private $groupNameAARC;
30+
private $groupNameAuthority;
2131

2232
public function __construct($config, $reserved)
2333
{
2434
parent::__construct($config, $reserved);
2535

36+
$conf = SimpleSAML_Configuration::getConfig(self::CONFIG_FILE_NAME);
37+
38+
$this->groupNamePrefix = $conf->getString(self::GROUPNAMEPREFIX_ATTR, '');
39+
$this->groupNameAuthority = $conf->getString(self::GROUPNAMEAUTHORITY_ATTR, '');
40+
$this->groupNameAARC = $conf->getBoolean(self::GROUPNAMEAARC_ATTR, false);
41+
42+
if ($this->groupNameAARC && (empty($this->groupNameAuthority) || empty($this->groupNamePrefix))) {
43+
throw new SimpleSAML_Error_Exception("perun:PerunGroups: 'groupNameAARC' has been set, 'groupNameAuthority' and 'groupNamePrefix' options must be set as well");
44+
}
45+
2646
assert('is_array($config)');
2747

2848
if (!isset($config['attrName'])) {
2949
throw new SimpleSAML_Error_Exception("perun:PerunGroups: missing mandatory configuration option 'attrName'.");
3050
}
3151
$this->attrName = (string) $config['attrName'];
3252

33-
if (!isset($config[self::GROUPNAMEPREFIX_ATTR])) {
34-
SimpleSAML\Logger::warning("perun:PerunGroups: optional attribute '". self::GROUPNAMEPREFIX_ATTR . "' is missing, assuming empty prefix");
35-
$this->groupNamePrefix = '';
36-
} else {
37-
$this->groupNamePrefix = (string) $config[self::GROUPNAMEPREFIX_ATTR];
38-
}
3953
}
4054

4155

@@ -55,7 +69,17 @@ public function process(&$request)
5569

5670
$request['Attributes'][$this->attrName] = array();
5771
foreach ($groups as $group) {
58-
$groupName = $this->mapGroupName($request, $group->getName());
72+
if (isset($request["SPMetadata"]["groupNameAARC"]) || $this->groupNameAARC) {
73+
# https://aarc-project.eu/wp-content/uploads/2017/11/AARC-JRA1.4A-201710.pdf
74+
# Example: urn:geant:einfra.cesnet.cz:perun.cesnet.cz:group:einfra:<groupName>:<subGroupName>#perun.cesnet.cz
75+
if (empty($this->groupNameAuthority) || empty($this->groupNamePrefix)) {
76+
throw new SimpleSAML_Error_Exception("perun:PerunGroups: missing mandatory configuration options 'groupNameAuthority' or 'groupNamePrefix'.");
77+
}
78+
79+
$groupName = $this->groupNamePrefix . $group->getName() . '#' . $this->groupNameAuthority;
80+
} else {
81+
$groupName = $this->mapGroupName($request, $group->getName());
82+
}
5983
array_push($request['Attributes'][$this->attrName], $groupName);
6084
}
6185
}

0 commit comments

Comments
 (0)