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

Commit 0cd018e

Browse files
committed
Changed logic for getSpGroups method
* Function getSpGroup require only one parameter($spEntityId) * Uses new model Resource * Changed logic for getting list of assigned groups for facility from Perun
1 parent 45b2096 commit 0cd018e

File tree

4 files changed

+29
-36
lines changed

4 files changed

+29
-36
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ All notable changes to this project will be documented in this file.
1414
- Connectors methods are not static for now.
1515
- Added constructors to Adapters, which allows specified config file for each connections.
1616
- New properties voId and uniqueName in Group model
17+
- Function getSpGroup require only one param($spEntityId)
1718

1819
## [v1.0.0]
1920

lib/Adapter.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,10 @@ public abstract function getMemberGroups($user, $vo);
7171

7272
/**
7373
* @param string $spEntityId entity id of the sp
74-
* @param sspmod_perun_model_Vo $vo
7574
* @return sspmod_perun_model_Group[] from vo which are assigned to all facilities with spEntityId.
7675
* registering to those groups should should allow access to the service
7776
*/
78-
public abstract function getSpGroups($spEntityId, $vo);
77+
public abstract function getSpGroups($spEntityId);
7978

8079
/**
8180
* @param sspmod_perun_model_User $user

lib/AdapterLdap.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function getMemberGroups($user, $vo)
100100
}
101101

102102

103-
public function getSpGroups($spEntityId, $vo)
103+
public function getSpGroups($spEntityId)
104104
{
105105
$resources = $this->connector->searchForEntities($this->ldapBase,
106106
"(&(objectClass=perunResource)(entityID=$spEntityId))",
@@ -109,15 +109,17 @@ public function getSpGroups($spEntityId, $vo)
109109

110110
$groups = array();
111111
foreach ($resources as $resource) {
112-
foreach ($resource['assignedGroupId'] as $groupId) {
113-
$group = $this->connector->searchForEntity("perunGroupId=$groupId,perunVoId=" . $resource['perunVoId'][0] . "," . $this->ldapBase,
114-
"(objectClass=perunGroup)",
115-
array("perunGroupId", "cn", "perunUniqueGroupName", "perunVoId", "description")
116-
);
117-
array_push($groups, new sspmod_perun_model_Group($group['perunGroupId'][0], $group['perunVoId'][0], $group['cn'], $group['perunUniqueGroupName'][0], $group['description'][0]));
112+
if (isset($resource['assignedGroupId'])) {
113+
foreach ($resource['assignedGroupId'] as $groupId) {
114+
$group = $this->connector->searchForEntity("perunGroupId=$groupId,perunVoId=" . $resource['perunVoId'][0] . "," . $this->ldapBase,
115+
"(objectClass=perunGroup)",
116+
array("perunGroupId", "cn", "perunUniqueGroupName", "perunVoId", "description")
117+
);
118+
array_push($groups, new sspmod_perun_model_Group($group['perunGroupId'][0], $group['perunVoId'][0], $group['cn'], $group['perunUniqueGroupName'][0], $group['description'][0]));
119+
}
118120
}
119-
}
120121

122+
}
121123
$groups = $this->removeDuplicateEntities($groups);
122124

123125
return $groups;

lib/AdapterRpc.php

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -104,46 +104,37 @@ public function getMemberGroups($user, $vo)
104104
}
105105

106106

107-
public function getSpGroups($spEntityId, $vo)
107+
public function getSpGroups($spEntityId)
108108
{
109-
$resources = $this->connector->get('resourcesManager', 'getResources', array(
110-
'vo' => $vo->getId(),
109+
$perunAttr = $this->connector->get('facilitiesManager', 'getFacilitiesByAttribute', array(
110+
'attributeName' => 'urn:perun:facility:attribute-def:def:entityID',
111+
'attributeValue' => $spEntityId,
112+
))[0];
113+
$facility = new sspmod_perun_model_Facility($perunAttr['id'], $perunAttr['name'], $perunAttr['description'], $spEntityId);
114+
115+
$perunAttrs = $this->connector->get('facilitiesManager', 'getAssignedResources', array(
116+
'facility' => $facility->getId(),
111117
));
112118

113-
$spFacilityIds = array();
114-
$spResources = array();
115-
foreach ($resources as $resource) {
116-
if (!array_key_exists($resource['facilityId'], $spFacilityIds)) {
117-
$attribute = $this->connector->get('attributesManager', 'getAttribute', array(
118-
'facility' => $resource['facilityId'],
119-
'attributeName' => 'urn:perun:facility:attribute-def:def:entityID',
120-
));
121-
if ($attribute['value'] === $spEntityId) {
122-
$spFacilityIds[$resource['facilityId']] = true;
123-
} else {
124-
$spFacilityIds[$resource['facilityId']] = false;
125-
}
126-
}
127-
if ($spFacilityIds[$resource['facilityId']]) {
128-
array_push($spResources, $resource);
129-
}
119+
$resources = array();
120+
foreach ($perunAttrs as $perunAttr) {
121+
array_push($resources, new sspmod_perun_model_Resource($perunAttr['id'], $perunAttr['voId'], $perunAttr['facilityId'], $perunAttr['name']));
130122
}
131123

132124
$spGroups = array();
133-
foreach ($spResources as $spResource) {
134-
$groups = $this->connector->get('resourcesManager', 'getAssignedGroups', array(
135-
'resource' => $spResource['id'],
125+
foreach ($resources as $resource) {
126+
$groups = sspmod_perun_RpcConnector::get('resourcesManager', 'getAssignedGroups', array(
127+
'resource' => $resource->getId(),
136128
));
137-
$convertedGroups = array();
129+
138130
foreach ($groups as $group) {
139131
$attr = $this->connector->get('attributesManager', 'getAttribute', array(
140132
'group' => $group['id'],
141133
'attributeName' => 'urn:perun:group:attribute-def:virt:voShortName'
142134
));
143135
$uniqueName = $attr['value'] . ":" . $group['name'];
144-
array_push($convertedGroups, new sspmod_perun_model_Group($group['id'], $group['voId'], $group['name'], $uniqueName, $group['description']));
136+
array_push($spGroups, new sspmod_perun_model_Group($group['id'],$group['voId'], $group['name'], $uniqueName, $group['description']));
145137
}
146-
$spGroups = array_merge($spGroups, $convertedGroups);
147138
}
148139

149140
$spGroups = $this->removeDuplicateEntities($spGroups);

0 commit comments

Comments
 (0)