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

Commit e2778a9

Browse files
author
Dominik František Bučík
authored
Merge pull request #161 from CESNET/melanger-callable-entityID
allow callable for entityID configuration option in PerunEntitlement(Extended)
2 parents d309cec + 906732f commit e2778a9

4 files changed

Lines changed: 19 additions & 2 deletions

File tree

CHANGELOG.md

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

44
## [Unreleased]
5+
- Added possibility to use a callable for entityID parameter in PerunEntitlement(Extended)
56

67
## [v5.1.1]
78
#### Fixed

config-templates/processFilterConfigurations-example.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ Example how to enable/configure filter PerunEntitlement:
5454
# forwarded entitlement are released by default
5555
#'releaseForwardedEntitlement' => false, OPTIONAL
5656
'forwardedEduPersonEntitlement' => 'eduPersonEntitlement',
57+
#'entityID' => function($request){return empty($request["saml:RequesterID"]) ? $request["SPMetadata"]["entityid"] : $request["saml:RequesterID"][0];},
5758
),
5859
```
5960

@@ -69,6 +70,7 @@ Example how to enable/configure filter PerunEntitlement:
6970
# forwarded entitlement are released by default
7071
#'releaseForwardedEntitlement' => false, OPTIONAL
7172
'forwardedEduPersonEntitlement' => 'eduPersonEntitlement',
73+
#'entityID' => function($request){return empty($request["saml:RequesterID"]) ? $request["SPMetadata"]["entityid"] : $request["saml:RequesterID"][0];},
7274
),
7375
```
7476

lib/Auth/Process/PerunEntitlement.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function __construct($config, $reserved)
6464
$this->groupNameAARC ? Configuration::REQUIRED_OPTION : ''
6565
);
6666

67-
$this->entityId = $configuration->getString(self::ENTITY_ID, null);
67+
$this->entityId = $configuration->getValue(self::ENTITY_ID, null);
6868

6969
$interface = $configuration->getValueValidate(
7070
self::INTERFACE_PROPNAME,
@@ -82,6 +82,13 @@ public function process(&$request)
8282

8383
if ($this->entityId === null) {
8484
$this->entityId = EntitlementUtils::getSpEntityId($request);
85+
} elseif (is_callable($this->entityId)) {
86+
$this->entityId = call_user_func($this->entityId, $request);
87+
} elseif (!is_string($this->entityId)) {
88+
throw new Exception(
89+
'perun:PerunEntitlement: invalid configuration option entityID. ' .
90+
'It must be a string or a callable.'
91+
);
8592
}
8693

8794
if (isset($request['perun']['groups'])) {

lib/Auth/Process/PerunEntitlementExtended.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function __construct($config, $reserved)
6464
$this->groupNameAARC ? Configuration::REQUIRED_OPTION : ''
6565
);
6666

67-
$this->entityId = $configuration->getString(self::ENTITY_ID, null);
67+
$this->entityId = $configuration->getValue(self::ENTITY_ID, null);
6868

6969
$interface = $configuration->getValueValidate(
7070
self::INTERFACE_PROPNAME,
@@ -82,6 +82,13 @@ public function process(&$request)
8282

8383
if ($this->entityId === null) {
8484
$this->entityId = EntitlementUtils::getSpEntityId($request);
85+
} elseif (is_callable($this->entityId)) {
86+
$this->entityId = call_user_func($this->entityId, $request);
87+
} elseif (!is_string($this->entityId)) {
88+
throw new Exception(
89+
'perun:PerunEntitlement: invalid configuration option entityID. ' .
90+
'It must be a string or a callable.'
91+
);
8592
}
8693

8794
if (isset($request['perun']['groups'])) {

0 commit comments

Comments
 (0)