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

Commit 45fd4b6

Browse files
authored
Merge pull request #24 from pajavyskocil/master_RPC
Fix the AdapterRpc
2 parents 119d7d4 + 12f98a6 commit 45fd4b6

File tree

4 files changed

+45
-5
lines changed

4 files changed

+45
-5
lines changed

lib/Adapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public abstract function getUserAttributes($user, $attrNames);
7474
* @param int $userId
7575
* @return sspmod_perun_model_Group[] from vo which are assigned to all facilities with spEntityId for this userId
7676
*/
77-
public abstract function isUserOnFacility($spEntityId, $userId);
77+
public abstract function getUsersGroupsOnFacility($spEntityId, $userId);
7878

7979
/**
8080
* @param sspmod_perun_model_HasId[] $entities

lib/AdapterLdap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public function getUserAttributes($user, $attrNames)
140140
}
141141

142142

143-
public function isUserOnFacility($spEntityId, $userId)
143+
public function getUsersGroupsOnFacility($spEntityId, $userId)
144144
{
145145
$resources = sspmod_perun_LdapConnector::searchForEntities($this->ldapBase,
146146
"(&(objectClass=perunResource)(entityID=$spEntityId))",

lib/AdapterRpc.php

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* Class sspmod_perun_AdapterRpc
55
*
66
* Perun adapter which uses Perun RPC interface
7+
* @author Michal Prochazka <[email protected]>
8+
* @author Pavel Vyskocil <[email protected]>
79
*/
810
class sspmod_perun_AdapterRpc extends sspmod_perun_Adapter
911
{
@@ -152,9 +154,47 @@ public function getUserAttributes($user, $attrNames)
152154
}
153155

154156

155-
public function isUserOnFacility($spEntityId, $userId)
157+
public function getUsersGroupsOnFacility($spEntityId, $userId)
156158
{
157-
throw new BadMethodCallException("NotImplementedException");
159+
$facilities = sspmod_perun_RpcConnector::get('facilitiesManager', 'getFacilitiesByAttribute', array(
160+
'attributeName' => 'urn:perun:facility:attribute-def:def:entityID',
161+
'attributeValue' => $spEntityId,
162+
));
163+
164+
$allowedResources = array();
165+
foreach ($facilities as $facility) {
166+
$resources = sspmod_perun_RpcConnector::get('facilitiesManager', 'getAssignedResources', array(
167+
'facility' => $facility['id'],
168+
));
169+
$allowedResources = array_merge($allowedResources, $resources);
170+
}
171+
172+
$members = sspmod_perun_RpcConnector::get('membersManager', 'getMembersByUser', array(
173+
'user' => $userId,
174+
));
175+
176+
$validMembers = array();
177+
foreach ($members as $member) {
178+
if ($member['status'] === 'VALID') {
179+
array_push($validMembers, $member);
180+
}
181+
}
182+
183+
$allGroups = array();
184+
foreach ($allowedResources as $resource) {
185+
foreach ($validMembers as $member) {
186+
$groups = sspmod_perun_RpcConnector::get('resourcesManager', 'getAssignedGroups', array(
187+
'resource' => $resource['id'],
188+
'member' => $member['id'],
189+
));
190+
foreach ($groups as $group) {
191+
array_push($allGroups, new sspmod_perun_model_Group($group['id'], $group['name'], $group['description']));
192+
}
193+
}
194+
}
195+
196+
$allGroups = $this->removeDuplicateEntities($allGroups);
197+
return $allGroups;
158198
}
159199

160200
}

lib/Auth/Process/PerunIdentity.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public function process(&$request)
137137
$this->register($request, $this->registerUrl, $this->callbackParamName, $vo, $spGroups, $this->interface);
138138
}
139139

140-
$groups = $this->adapter->isUserOnFacility($spEntityId,$user->getId());
140+
$groups = $this->adapter->getUsersGroupsOnFacility($spEntityId,$user->getId());
141141

142142
if (empty($groups)) {
143143
SimpleSAML\Logger::warning('Perun user with identity/ies: '. implode(',', $uids) .' is not member of any assigned group for resource (' . $spEntityId . ')');

0 commit comments

Comments
 (0)