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

Commit b88373c

Browse files
committed
Change getting data from LDAP
Added method isUserOnFacility. Edit getSpGroups method. Now is get voId by resource, not by metadata.
1 parent b7a8e56 commit b88373c

File tree

4 files changed

+48
-44
lines changed

4 files changed

+48
-44
lines changed

lib/Adapter.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ public abstract function getSpGroups($spEntityId, $vo);
6969
*/
7070
public abstract function getUserAttributes($user, $attrNames);
7171

72+
/**
73+
* @param string $spEntityId entity id of the sp
74+
* @param int $userId
75+
* @return sspmod_perun_model_Group[] from vo which are assigned to all facilities with spEntityId for this userId
76+
*/
77+
public abstract function isUserOnFacility($spEntityId, $userId);
7278

7379
/**
7480
* @param sspmod_perun_model_HasId[] $entities

lib/AdapterLdap.php

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,13 @@ public function getSpGroups($spEntityId, $vo)
7171
{
7272
$resources = sspmod_perun_LdapConnector::searchForEntities("dc=perun,dc=cesnet,dc=cz",
7373
"(&(objectClass=perunResource)(entityID=$spEntityId))",
74-
array("perunResourceId", "assignedGroupId")
74+
array("perunResourceId", "assignedGroupId", "perunVoId")
7575
);
76-
$voId = $vo->getId();
7776

7877
$groups = array();
7978
foreach ($resources as $resource) {
8079
foreach ($resource['assignedGroupId'] as $groupId) {
81-
$group = sspmod_perun_LdapConnector::searchForEntity("perunGroupId=$groupId,perunVoId=$voId,dc=perun,dc=cesnet,dc=cz",
80+
$group = sspmod_perun_LdapConnector::searchForEntity("perunGroupId=$groupId,perunVoId=" . $resource['perunVoId'][0] . ",dc=perun,dc=cesnet,dc=cz",
8281
"(objectClass=perunGroup)",
8382
array("perunGroupId", "cn", "perunUniqueGroupName", "perunVoId", "description")
8483
);
@@ -132,4 +131,37 @@ public function getUserAttributes($user, $attrNames)
132131
return $attributes;
133132
}
134133

134+
135+
public function isUserOnFacility($spEntityId, $userId)
136+
{
137+
$resources = sspmod_perun_LdapConnector::searchForEntities("dc=perun,dc=cesnet,dc=cz",
138+
"(&(objectClass=perunResource)(entityID=$spEntityId))",
139+
array("perunResourceId")
140+
);
141+
SimpleSAML_Logger::debug("Resources - ".var_export($resources, true));
142+
143+
if (is_null($resources)) {
144+
throw new SimpleSAML_Error_Exception("Service with spEntityId: ". $spEntityId ." hasn't assigned any resource.");
145+
}
146+
$resourcesString = "(|";
147+
foreach ($resources as $resource){
148+
$resourcesString .= "(assignedToResourceId=".$resource['perunResourceId'][0].")";
149+
}
150+
$resourcesString .= ")";
151+
152+
$resultGroups = array();
153+
$groups = sspmod_perun_LdapConnector::searchForEntities("dc=perun,dc=cesnet,dc=cz",
154+
"(&(uniqueMember=perunUserId=".$userId.",ou=People,dc=perun,dc=cesnet,dc=cz)".$resourcesString.")",
155+
array("perunGroupId", "cn", "perunUniqueGroupName", "perunVoId", "description")
156+
);
157+
158+
foreach ($groups as $group) {
159+
array_push($resultGroups, new sspmod_perun_model_Group($group['perunGroupId'][0], $group['perunUniqueGroupName'][0], $group['description'][0]));
160+
161+
}
162+
$resultGroups = $this->removeDuplicateEntities($resultGroups);
163+
SimpleSAML_Logger::debug("Groups - ".var_export($resultGroups, true));
164+
return $resultGroups;
165+
}
166+
135167
}

lib/AdapterRpc.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,4 +152,9 @@ public function getUserAttributes($user, $attrNames)
152152
}
153153

154154

155+
public function isUserOnFacility($spEntityId, $userId)
156+
{
157+
throw new BadMethodCallException("NotImplementedException");
158+
}
159+
155160
}

lib/Auth/Process/PerunIdentity.php

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
*
2020
* @author Ondrej Velisek <[email protected]>
2121
* @author Michal Prochazka <[email protected]>
22+
* @author Pavel Vyskocil <[email protected]>
2223
*/
2324
class sspmod_perun_Auth_Process_PerunIdentity extends SimpleSAML_Auth_ProcessingFilter
2425
{
@@ -143,13 +144,7 @@ public function process(&$request)
143144
$this->register($request, $this->registerUrl, $this->callbackParamName, $vo, $spGroups, $this->interface);
144145
}
145146

146-
147-
$memberGroups = $this->adapter->getMemberGroups($user, $vo);
148-
149-
SimpleSAML_Logger::debug('member groups: '.var_export($memberGroups, true));
150-
SimpleSAML_Logger::debug('sp groups: '.var_export($spGroups, true));
151-
152-
$groups = $this->intersectById($spGroups, $memberGroups);
147+
$groups = $this->adapter->isUserOnFacility($spEntityId,$user->getId());
153148

154149
if (empty($groups)) {
155150
SimpleSAML_Logger::warning('Perun user with identity/ies: '. implode(',', $uids) .' is not member of any assigned group for resource (' . $spEntityId . ')');
@@ -253,40 +248,6 @@ protected function registerChooseGroup($registerUrl, $callbackParamName, $callba
253248

254249
}
255250

256-
257-
258-
259-
/**
260-
* @param sspmod_perun_model_HasId[] $spGroups
261-
* @param sspmod_perun_model_HasId[] $memberGroups
262-
* @return sspmod_perun_model_HasId[]
263-
*/
264-
private function intersectById($spGroups, $memberGroups)
265-
{
266-
$intersection = array();
267-
foreach ($spGroups as $spGroup) {
268-
if ($this->containsId($memberGroups, $spGroup->getId())) {
269-
array_push($intersection, $spGroup);
270-
}
271-
}
272-
return $intersection;
273-
}
274-
275-
/**
276-
* @param sspmod_perun_model_HasId[] $entities
277-
* @param int $value
278-
* @return bool
279-
*/
280-
private function containsId($entities, $value)
281-
{
282-
foreach ($entities as $entity) {
283-
if ($entity->getId() === $value) {
284-
return true;
285-
}
286-
}
287-
return false;
288-
}
289-
290251
/**
291252
* Returns true, if entities contains VO members group
292253
*

0 commit comments

Comments
 (0)