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

Commit 451efe9

Browse files
BaranekDvyskocilpavel
authored andcommitted
Fixed the problem where LDAP calls RPC method in PerunIdentity
Signed-off-by: Pavel Vyskočil <[email protected]>
1 parent 3a32f2b commit 451efe9

File tree

5 files changed

+51
-10
lines changed

5 files changed

+51
-10
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file.
55
[Added]
66
- List of services is displayed as JSON if parameter 'output=json' is set in URL
77

8+
[Fixed]
9+
- Fixed the problem where LDAP calls RPC method in PerunIdentity filter
10+
811
## [v2.1.0]
912
[Added]
1013
- Added new atribute in PerunIdentity process filter with list of Services identifier's for which we don't want to show page with information, that the user will be redirected to other page

lib/Adapter.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,13 @@ public abstract function getUserExtSourceAttributes($userExtSourceId, $attribute
156156
*/
157157
public abstract function setUserExtSourceAttributes($userExtSourceId, $attributes);
158158

159+
/**
160+
* @param sspmod_perun_model_User $user user
161+
* @param sspmod_perun_model_Vo $vo vo
162+
* @return string status, null if member does not exist
163+
*/
164+
public abstract function getMemberStatusByUserAndVo($user, $vo);
165+
159166
/**
160167
* @param sspmod_perun_model_HasId[] $entities
161168
* @return sspmod_perun_model_HasId[] without duplicates

lib/AdapterLdap.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,5 +264,19 @@ public function getUsersGroupsOnFacility($spEntityId, $userId)
264264
return $resultGroups;
265265
}
266266

267+
public function getMemberStatusByUserAndVo($user, $vo)
268+
{
269+
$groupId = $this->connector->searchForEntity($this->ldapBase,
270+
"(&(objectClass=perunGroup)(cn=members)(perunVoId=" . $vo->getId() . ")(uniqueMember=perunUserId=" . $user->getId() . ",ou=People,dc=perun,dc=cesnet,dc=cz))",
271+
array("perunGroupid")
272+
);
273+
274+
if (empty($groupId)) {
275+
return sspmod_perun_model_Member::INVALID;
276+
} else {
277+
return sspmod_perun_model_Member::VALID;
278+
}
279+
}
280+
267281

268282
}

lib/AdapterRpc.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,4 +391,15 @@ public function setUserExtSourceAttributes($userExtSourceId, $attributes)
391391
"attributes" => $attributes
392392
));
393393
}
394+
395+
public function getMemberStatusByUserAndVo($user, $vo)
396+
{
397+
try {
398+
$member = $this->getMemberByUser($user, $vo);
399+
} catch (Exception $ex) {
400+
return null;
401+
}
402+
return $member->getStatus();
403+
}
404+
394405
}

lib/Auth/Process/PerunIdentity.php

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -411,34 +411,40 @@ protected function getSPAttributes($spEntityID) {
411411
* @param $uids
412412
*/
413413
protected function checkMemberStateDefaultVo($request, $user, $uids) {
414-
$member = null;
415-
$vo = null;
414+
$status = null;
416415
try {
417416
$vo = $this->adapter->getVoByShortName($this->voShortName);
418417
if (!is_null($user)) {
419-
$member = $this->rpcAdapter->getMemberByUser($user, $vo);
418+
$status = $this->adapter->getMemberStatusByUserAndVo($user, $vo);
420419
}
421420
} catch (Exception $ex) {
422-
SimpleSAML\Logger::warning("perun:PerunIdentity: " . $ex);
421+
throw new SimpleSAML_Error_Exception('perun:PerunIdentity: ' . $ex);
423422
}
424423

425424
if (is_null($vo)) {
426425
throw new SimpleSAML_Error_Exception('perun:PerunIdentity: Vo with short name ' . $this->voShortName . ' does not exist.');
427426
}
428427

429-
if (is_null($user) || is_null($member) || $member->getStatus() === sspmod_perun_model_Member::EXPIRED) {
428+
if ($this->adapter instanceof sspmod_perun_AdapterLdap && $status === sspmod_perun_model_Member::INVALID) {
429+
try {
430+
$status = $this->rpcAdapter->getMemberStatusByUserAndVo($user, $vo);
431+
} catch (Exception $ex) {
432+
SimpleSAML\Logger::info('Member status for perun user with identity/ies: ' . implode(',', $uids) . ' was not VALID and it is not possible to get more info (RPC is not working)');
433+
$this->unauthorized($request);
434+
}
435+
}
436+
437+
if (is_null($user) || is_null($status) || $status === sspmod_perun_model_Member::EXPIRED) {
430438
if (is_null($user)) {
431439
SimpleSAML\Logger::info('Perun user with identity/ies: '. implode(',', $uids).' has NOT been found. He is being redirected to register.');
432-
}
433-
elseif (is_null($member)) {
440+
} elseif (is_null($status)) {
434441
SimpleSAML\Logger::info('Perun user with identity/ies: '. implode(',', $uids).' is NOT member in vo with short name ' . $this->voShortName . '(default VO). He is being redirected to register.');
435-
}
436-
else {
442+
} else {
437443
SimpleSAML\Logger::info('Member status for perun user with identity/ies: '. implode(',', $uids).' was expired. He is being redirected to register.');
438444
}
439445
$this->register($request, array($vo), $this->defaultRegisterUrl,false);
440446

441-
} elseif (!($member->getStatus() === sspmod_perun_model_Member::VALID)) {
447+
} elseif (!($status === sspmod_perun_model_Member::VALID)) {
442448
SimpleSAML\Logger::warning('Member status for perun user with identity/ies: '. implode(',', $uids).' was INVALID/SUSPENDED/DISABLED. ');
443449
$this->unauthorized($request);
444450
}

0 commit comments

Comments
 (0)