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

Commit ac72b64

Browse files
committed
Added resource capabilities into entitlements
1 parent 4322a18 commit ac72b64

File tree

8 files changed

+347
-200
lines changed

8 files changed

+347
-200
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file.
44
## [Unreleased]
55
#### Added
66
- Added method getFacilityByEntityId
7+
- Added resource capabilities into entitlements
78

89
#### Changed
910
- Slightly modified text displayed on WAYF
@@ -14,6 +15,7 @@ All notable changes to this project will be documented in this file.
1415
- Double quotes changed to single quotes
1516
- getFacilitiesByEntityId marked as deprecated (getFacilityByEntityId should be used instead)
1617
- Using of getFacilityByEntityId instead of getFacilitiesByEntityId
18+
- Filters JoinGroupsAdnEduPersonEntitlement and PerunGroups merged into PerunEntitlement
1719

1820
#### Fixed
1921
- Fixed wrong dictionary name in post.php

config-templates/module_perun.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@
3333
//'ldap.username' => '_proxy-idp',
3434
//'ldap.password' => 'password'
3535

36+
/**
37+
* Perun group name to eduPersonEntitlement mapping. Mapping is according to the spec in
38+
* https://aarc-project.eu/wp-content/uploads/2017/11/AARC-JRA1.4A-201710.pdf
39+
* groupNameAARC - enable group naming according to AARC spec globally,
40+
* every SP can overide it with groupMapping option
41+
* entitlementPrefix - prefix put in front of the Perun entitlement, do not forget to add ':' at the end
42+
* entitlementAuthority - name of the authority issuing the entitlement
43+
*/
44+
'groupNameAARC' => true/false,
45+
'entitlementPrefix' => 'prefix',
46+
'entitlementAuthority' => 'authority',
47+
3648
/**
3749
* specify if disco module should filter out IdPs which are not whitelisted neither commited to CoCo or RaS.
3850
* default is false.

lib/Adapter.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,13 @@ abstract public function setUserExtSourceAttributes($userExtSourceId, $attribute
183183
*/
184184
abstract public function getMemberStatusByUserAndVo($user, $vo);
185185

186+
/**
187+
* @param $entityId int entityId
188+
* @param $userGroups array of groups where user belongs to
189+
* @return array of resource capabilities
190+
*/
191+
abstract public function getResourceCapabilities($entityId, $userGroups);
192+
186193
/**
187194
* @param HasId[] $entities
188195
* @return HasId[] without duplicates

lib/AdapterLdap.php

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ class AdapterLdap extends Adapter
3232
const PERUN_FACILITY_ID = 'perunFacilityId';
3333
const CN = 'cn';
3434
const DESCRIPTION = 'description';
35+
const CAPABILITIES = 'capabilities';
36+
const ASSIGNED_GROUP_ID = 'assignedGroupId';
3537

3638
private $ldapBase;
3739

@@ -228,7 +230,8 @@ public function getUserAttributes($user, $attrNames)
228230

229231
public function getFacilitiesByEntityId($spEntityId)
230232
{
231-
// TODO: Implement getEntityByEntityId() method.
233+
throw new BadMethodCallException('NotImplementedException');
234+
// TODO: Implement getFacilitiesByEntityId() method.
232235
}
233236

234237
public function getFacilityByEntityId($spEntityId)
@@ -372,4 +375,47 @@ public function getMemberStatusByUserAndVo($user, $vo)
372375
}
373376
return Member::VALID;
374377
}
378+
379+
public function getResourceCapabilities($entityId, $userGroups)
380+
{
381+
$facility = $this->getFacilityByEntityId($entityId);
382+
383+
if ($facility === null) {
384+
return [];
385+
}
386+
387+
$facilityId = $facility->getId();
388+
389+
$resources = $this->connector->searchForEntities(
390+
$this->ldapBase,
391+
'(&(objectClass=perunResource)(perunFacilityDn=perunFacilityId=' . $facilityId . ','
392+
. $this->ldapBase . '))',
393+
[self::CAPABILITIES, self::ASSIGNED_GROUP_ID]
394+
);
395+
396+
$userGroupsIds = [];
397+
foreach ($userGroups as $userGroup) {
398+
array_push($userGroupsIds, $userGroup->getId());
399+
}
400+
401+
$resourceCapabilities = [];
402+
foreach ($resources as $resource) {
403+
if (
404+
!array_key_exists(self::ASSIGNED_GROUP_ID, $resource) ||
405+
!array_key_exists(self::CAPABILITIES, $resource)
406+
) {
407+
continue;
408+
}
409+
foreach ($resource[self::ASSIGNED_GROUP_ID] as $groupId) {
410+
if (in_array($groupId, $userGroupsIds)) {
411+
foreach ($resource[self::CAPABILITIES] as $resourceCapability) {
412+
array_push($resourceCapabilities, $resourceCapability);
413+
}
414+
break;
415+
}
416+
}
417+
}
418+
419+
return $resourceCapabilities;
420+
}
375421
}

lib/AdapterRpc.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,4 +505,49 @@ public function getMemberStatusByUserAndVo($user, $vo)
505505
}
506506
return $member->getStatus();
507507
}
508+
509+
public function getResourceCapabilities($entityId, $userGroups)
510+
{
511+
$facility = $this->getFacilityByEntityId($entityId);
512+
513+
if ($facility === null) {
514+
return [];
515+
}
516+
517+
$resources = $this->connector->get('facilitiesManager', 'getAssignedResources', [
518+
'facility' => $facility->getId()
519+
]);
520+
521+
$userGroupsIds = [];
522+
foreach ($userGroups as $userGroup) {
523+
array_push($userGroupsIds, $userGroup->getId());
524+
}
525+
526+
$capabilities = [];
527+
foreach ($resources as $resource) {
528+
$resourceGroups = $this->connector->get('resourcesManager', 'getAssignedGroups', [
529+
'resource' => $resource['id']
530+
]);
531+
532+
$resourceCapabilities = $this->connector->get('attributesManager', 'getAttribute', [
533+
'resource' => $resource['id'],
534+
'attributeName' => 'urn:perun:resource:attribute-def:def:capabilities'
535+
])['value'];
536+
537+
if ($resourceCapabilities === null) {
538+
continue;
539+
}
540+
541+
foreach ($resourceGroups as $resourceGroup) {
542+
if (in_array($resourceGroup['id'], $userGroupsIds)) {
543+
foreach ($resourceCapabilities as $capability) {
544+
array_push($capabilities, $capability);
545+
}
546+
break;
547+
}
548+
}
549+
}
550+
551+
return $capabilities;
552+
}
508553
}

lib/Auth/Process/JoinGroupsAndEduPersonEntitlement.php

Lines changed: 0 additions & 63 deletions
This file was deleted.

0 commit comments

Comments
 (0)