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

Commit 27503e5

Browse files
authored
feat: entityId in entitlement filters can be now set in config (#151)
Co-authored-by: Jan Pavlicek <[email protected]>
1 parent c1643a2 commit 27503e5

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

lib/Auth/Process/PerunEntitlement.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class PerunEntitlement extends ProcessingFilter
2828
const ENTITLEMENTAUTHORITY_ATTR = 'entitlementAuthority';
2929
const GROUPNAMEAARC_ATTR = 'groupNameAARC';
3030
const INTERFACE_PROPNAME = 'interface';
31+
const ENTITY_ID = 'entityID';
3132

3233
private $eduPersonEntitlement;
3334
private $releaseForwardedEntitlement;
@@ -36,6 +37,7 @@ class PerunEntitlement extends ProcessingFilter
3637
private $entitlementAuthority;
3738
private $groupNameAARC;
3839
private $adapter;
40+
private $entityId;
3941

4042
public function __construct($config, $reserved)
4143
{
@@ -62,6 +64,8 @@ public function __construct($config, $reserved)
6264
$this->groupNameAARC ? Configuration::REQUIRED_OPTION : ''
6365
);
6466

67+
$this->entityId = $modulePerunConfiguration->getString(self::ENTITY_ID, null);
68+
6569
$interface = $configuration->getValueValidate(
6670
self::INTERFACE_PROPNAME,
6771
[Adapter::RPC, Adapter::LDAP],
@@ -76,13 +80,18 @@ public function process(&$request)
7680
$capabilities = [];
7781
$forwardedEduPersonEntitlement = [];
7882

83+
if ($this->entityId === null) {
84+
$this->entityId = EntitlementUtils::getSpEntityId($request);
85+
}
86+
7987
if (isset($request['perun']['groups'])) {
8088
$eduPersonEntitlement = $this->getEduPersonEntitlement($request);
8189
$capabilities = EntitlementUtils::getCapabilities(
8290
$request,
8391
$this->adapter,
8492
$this->entitlementPrefix,
85-
$this->entitlementAuthority
93+
$this->entitlementAuthority,
94+
$this->entityId
8695
);
8796
} else {
8897
Logger::debug(
@@ -156,19 +165,19 @@ protected function mapGroupName($request, $groupName)
156165
isset($request['SPMetadata']['groupMapping'][$groupName])) {
157166
Logger::debug(
158167
'Mapping ' . $groupName . ' to ' . $request['SPMetadata']['groupMapping'][$groupName] .
159-
' for SP ' . $request['SPMetadata']['entityid']
168+
' for SP ' . $this->entityId
160169
);
161170
return $request['SPMetadata']['groupMapping'][$groupName];
162171
} elseif (isset($request['SPMetadata'][self::ENTITLEMENTPREFIX_ATTR])) {
163172
Logger::debug(
164-
'EntitlementPrefix overridden by a SP ' . $request['SPMetadata']['entityid'] .
173+
'EntitlementPrefix overridden by a SP ' . $this->entityId .
165174
' to ' . $request['SPMetadata'][self::ENTITLEMENTPREFIX_ATTR]
166175
);
167176
return $request['SPMetadata'][self::ENTITLEMENTPREFIX_ATTR] . $groupName;
168177
} else {
169178
# No mapping defined, so just put groupNamePrefix in front of the group
170179
Logger::debug(
171-
'No mapping found for group ' . $groupName . ' for SP ' . $request['SPMetadata']['entityid']
180+
'No mapping found for group ' . $groupName . ' for SP ' . $this->entityId
172181
);
173182
return $this->entitlementPrefix . 'group:' . $groupName;
174183
}

lib/Auth/Process/PerunEntitlementExtended.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class PerunEntitlementExtended extends ProcessingFilter
2828
const ENTITLEMENTAUTHORITY_ATTR = 'entitlementAuthority';
2929
const GROUPNAMEAARC_ATTR = 'groupNameAARC';
3030
const INTERFACE_PROPNAME = 'interface';
31+
const ENTITY_ID = 'entityID';
3132

3233
private $outputAttrName;
3334
private $releaseForwardedEntitlement;
@@ -36,6 +37,7 @@ class PerunEntitlementExtended extends ProcessingFilter
3637
private $entitlementAuthority;
3738
private $groupNameAARC;
3839
private $adapter;
40+
private $entityId;
3941

4042
public function __construct($config, $reserved)
4143
{
@@ -62,6 +64,8 @@ public function __construct($config, $reserved)
6264
$this->groupNameAARC ? Configuration::REQUIRED_OPTION : ''
6365
);
6466

67+
$this->entityId = $modulePerunConfiguration->getString(self::ENTITY_ID, null);
68+
6569
$interface = $configuration->getValueValidate(
6670
self::INTERFACE_PROPNAME,
6771
[Adapter::RPC, Adapter::LDAP],
@@ -76,14 +80,19 @@ public function process(&$request)
7680
$capabilities = [];
7781
$forwardedEduPersonEntitlement = [];
7882

83+
if ($this->entityId === null) {
84+
$this->entityId = EntitlementUtils::getSpEntityId($request);
85+
}
86+
7987
if (isset($request['perun']['groups'])) {
8088
$eduPersonEntitlementExtended = $this->getEduPersonEntitlementExtended($request);
8189

8290
$capabilities = EntitlementUtils::getCapabilities(
8391
$request,
8492
$this->adapter,
8593
$this->entitlementPrefix,
86-
$this->entitlementAuthority
94+
$this->entitlementAuthority,
95+
$this->entityId
8796
);
8897
} else {
8998
Logger::debug(

lib/EntitlementUtils.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,12 @@ public static function getForwardedEduPersonEntitlement(&$request, $adapter, $fo
5353
return $result;
5454
}
5555

56-
public static function getCapabilities(&$request, $adapter, $prefix, $authority)
56+
public static function getCapabilities(&$request, $adapter, $prefix, $authority, $spEntityId)
5757
{
5858
$resourceCapabilities = [];
5959
$facilityCapabilities = [];
6060
$capabilitiesResult = [];
6161

62-
$spEntityId = self::getSpEntityId($request);
6362
try {
6463
$resourceCapabilities = $adapter->getResourceCapabilities($spEntityId, $request['perun']['groups']);
6564
$facilityCapabilities = $adapter->getFacilityCapabilities($spEntityId);
@@ -142,7 +141,7 @@ public static function groupEntitlementWithAttributesWrapper($uuid, $groupName,
142141
EntitlementUtils::encodeName($groupName) . '#' . $authority;
143142
}
144143

145-
private static function getSpEntityId(&$request)
144+
public static function getSpEntityId(&$request)
146145
{
147146
if (isset($request['SPMetadata']['entityid'])) {
148147
return $request['SPMetadata']['entityid'];

0 commit comments

Comments
 (0)