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

Commit 7cda96e

Browse files
Merge pull request #60 from BaranekD/JoinGroupsAndEduPersonEntitlement
Created filter JoinGroupsAndEduPersonEntitlement
2 parents 2131700 + 53bd18a commit 7cda96e

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
All notable changes to this project will be documented in this file.
33

44
## [Unreleased]
5+
#### Added
6+
- Added filter JoinGroupsAndEduPersonEntitlement
7+
58
#### Fixed
69
- Fixed the problem that IDP filter on WAYF didn't work correctly
710

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
namespace SimpleSAML\Module\perun\Auth\Process;
4+
5+
use SimpleSAML\Error\Exception;
6+
7+
/**
8+
* Class JoinGroupsAndEduPersonEntitlement
9+
*
10+
* This filter joins eduPersonEntitlement attribute from perun with groups from PerunGroups filter.
11+
*
12+
* @author Dominik Baránek <[email protected]>
13+
*/
14+
class JoinGroupsAndEduPersonEntitlement extends \SimpleSAML\Auth\ProcessingFilter
15+
{
16+
const EDU_PERSON_ENTITLEMENT = 'eduPersonEntitlement';
17+
const FORWARDED_EDU_PERSON_ENTITLEMENT = 'forwardedEduPersonEntitlement';
18+
19+
private $eduPersonEntitlement;
20+
private $forwardedEduPersonEntitlement;
21+
22+
public function __construct($config, $reserved)
23+
{
24+
parent::__construct($config, $reserved);
25+
26+
assert('is_array($config)');
27+
28+
if (!isset($config[self::EDU_PERSON_ENTITLEMENT])) {
29+
throw new Exception(
30+
"perun:JoinGroupsAndEduPersonEntitlement: missing mandatory configuration option " .
31+
self::EDU_PERSON_ENTITLEMENT . "."
32+
);
33+
}
34+
$this->eduPersonEntitlement = $config[self::EDU_PERSON_ENTITLEMENT];
35+
36+
if (!isset($config[self::FORWARDED_EDU_PERSON_ENTITLEMENT])) {
37+
throw new Exception(
38+
"perun:JoinGroupsAndEduPersonEntitlement: missing mandatory configuration option " .
39+
self::FORWARDED_EDU_PERSON_ENTITLEMENT . "."
40+
);
41+
}
42+
$this->forwardedEduPersonEntitlement = $config[self::FORWARDED_EDU_PERSON_ENTITLEMENT];
43+
}
44+
45+
public function process(&$request)
46+
{
47+
if (isset($request['Attributes'][$this->eduPersonEntitlement]) &&
48+
isset($request['Attributes'][$this->forwardedEduPersonEntitlement])) {
49+
$request['Attributes'][$this->eduPersonEntitlement] = array_merge(
50+
$request['Attributes'][$this->eduPersonEntitlement],
51+
$request['Attributes'][$this->forwardedEduPersonEntitlement]
52+
);
53+
} else {
54+
throw new Exception(
55+
"perun:JoinGroupsAndEduPersonEntitlement: " .
56+
"missing at least one of mandatory fields ('Attributes." . $this->eduPersonEntitlement .
57+
"' or 'Attributes." . $this->forwardedEduPersonEntitlement . "' in request."
58+
);
59+
}
60+
61+
unset($request['Attributes'][$this->forwardedEduPersonEntitlement]);
62+
}
63+
}

0 commit comments

Comments
 (0)