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

Commit 4e2e475

Browse files
committed
Initial commit
1 parent 513a196 commit 4e2e475

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+2825
-1
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
# perun-simplesamlphp-module
2-
Module which allows simpleSAMLphp to get data from Perun
2+
Module which allows simpleSAMLphp to get data from Perun.
3+
4+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This directory is needed to save and keeping whitelist and greylist of remote idps.
2+
Please add it to config folder and set sufficient write permissions to allow
3+
the module filter idps properly.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/*
3+
* Configuration for the DiscoPower module.
4+
*/
5+
6+
$config = array (
7+
8+
// Which tab should be set as default. 0 is the first tab
9+
'defaulttab' => 0,
10+
11+
/*
12+
* List a set of tags (Tabs) that should be listed in a specific order.
13+
* All other available tabs will be listed after the ones specified below.
14+
*/
15+
'taborder' => array('social, misc'),
16+
/*
17+
* the 'tab' parameter allows you to limit the tabs to a specific list. (excluding unlisted tags)
18+
*
19+
* 'tabs' => array('norway', 'finland'),
20+
*/
21+
22+
/*
23+
* If you want to change the scoring algorithm to a more google suggest like one
24+
* (filters by start of words) uncomment this ...
25+
*/
26+
'score' => 'suggest',
27+
28+
/*
29+
* The domain to use for common domain cookie support.
30+
* This must be a parent domain of the domain hosting the discovery service.
31+
*
32+
* If this is NULL (the default), common domain cookie support will be disabled.
33+
*/
34+
'cdc.domain' => NULL,
35+
36+
/*
37+
* The lifetime of the common domain cookie, in seconds.
38+
*
39+
* If this is NULL (the default), the common domain cookie will be deleted when the browser closes.
40+
*
41+
* Example: 'cdc.lifetime' => 180*24*60*60, // 180 days
42+
*/
43+
'cdc.lifetime' => NULL,
44+
45+
);

config-templates/module_perun.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
/**
4+
* This is example configuration of SimpleSAMLphp Perun interface and additional features.
5+
* Copy this file to default config directory and edit the properties.
6+
*
7+
* copy command (from SimpleSAML base dir)
8+
* cp modules/perun/module_perun.php config/
9+
*/
10+
$config = array(
11+
12+
/**
13+
* base url to rpc with slash at the end.
14+
*/
15+
'rpc.url' => 'https://perun.inside.cz/krb/rpc/',
16+
17+
/**
18+
* rpc credentials if rpc url is protected with basic auth.
19+
*/
20+
'rpc.username' => '_proxy-idp',
21+
'rpc.password' => 'password',
22+
23+
/**
24+
* hostname of perun ldap with ldap(s):// at the beginning.
25+
*/
26+
'ldap.hostname' => 'ldaps://perun.inside.cz',
27+
28+
/**
29+
* ldap credentials if ldap search is protected. If it is null or not set at all. No user is used for bind.
30+
*/
31+
//'ldap.username' => '_proxy-idp',
32+
//'ldap.password' => 'password'
33+
34+
/**
35+
* specify if disco module should filter out IdPs which are not whitelisted neither commited to CoCo or RaS.
36+
* default is false.
37+
*/
38+
//'disco.disableWhitelisting' => true,
39+
40+
);

default-disable

Whitespace-only changes.

enable

Whitespace-only changes.

lib/Adapter.php

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
3+
/**
4+
* Interface sspmod_perun_Adapter
5+
* specify interface to get information from Perun.
6+
*/
7+
abstract class sspmod_perun_Adapter
8+
{
9+
const RPC = 'rpc';
10+
const LDAP = 'ldap';
11+
12+
/**
13+
* @param string $interface code of interface. Check constants of this class.
14+
* @return sspmod_perun_Adapter instance of this class. note it is NOT singleton.
15+
* @throws SimpleSAML_Error_Exception thrown if interface does not match any supported interface
16+
*/
17+
public static function getInstance($interface) {
18+
if ($interface === self::RPC) {
19+
return new sspmod_perun_AdapterRpc();
20+
} else if ($interface === self::LDAP) {
21+
return new sspmod_perun_AdapterLdap();
22+
} else {
23+
throw new SimpleSAML_Error_Exception('Unknown perun interface. Hint: try ' . self::RPC . ' or ' . self::LDAP);
24+
}
25+
}
26+
27+
/**
28+
* @param string $idpEntityId entity id of hosted idp used as extSourceName
29+
* @param string $uid user identifier received from remote idp used as userExtSourceLogin
30+
* @return sspmod_perun_model_User or null if not exists
31+
*/
32+
public abstract function getPerunUser($idpEntityId, $uid);
33+
34+
/**
35+
* @param sspmod_perun_model_Vo $vo
36+
* @param string $name group name. Note that name of group is without VO name prefix.
37+
* @return sspmod_perun_model_Group
38+
* @throws SimpleSAML_Error_Exception if does not exists
39+
*/
40+
public abstract function getGroupByName($vo, $name);
41+
42+
/**
43+
* @param string $voShortName
44+
* @return sspmod_perun_model_Vo
45+
* @throws SimpleSAML_Error_Exception if does not exists
46+
*/
47+
public abstract function getVoByShortName($voShortName);
48+
49+
/**
50+
* @param sspmod_perun_model_User $user perun user
51+
* @param sspmod_perun_model_Vo $vo vo we are working with.
52+
* @return sspmod_perun_model_Group[] groups from vo which member is. Including VO members group.
53+
*/
54+
public abstract function getMemberGroups($user, $vo);
55+
56+
/**
57+
* @param string $spEntityId entity id of the sp
58+
* @param sspmod_perun_model_Vo $vo
59+
* @return sspmod_perun_model_Group[] from vo which are assigned to all facilities with spEntityId.
60+
* registering to those groups should should allow access to the service
61+
*/
62+
public abstract function getSpGroups($spEntityId, $vo);
63+
64+
/**
65+
* @param sspmod_perun_model_User $user
66+
* @param array $attrNames.
67+
* @return array associative of attributes. Keys are attribute names
68+
* and values are attr values (can be null, string, array, associative array)
69+
*/
70+
public abstract function getUserAttributes($user, $attrNames);
71+
72+
73+
/**
74+
* @param sspmod_perun_model_HasId[] $entities
75+
* @return sspmod_perun_model_HasId[] without duplicates
76+
*/
77+
protected function removeDuplicateEntities($entities) {
78+
$removed = array();
79+
$ids = array();
80+
foreach ($entities as $entity) {
81+
if (!in_array($entity->getId(), $ids)) {
82+
array_push($ids, $entity->getId());
83+
array_push($removed, $entity);
84+
}
85+
}
86+
return $removed;
87+
88+
}
89+
}

lib/AdapterLdap.php

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
<?php
2+
3+
/**
4+
* Class sspmod_perun_AdapterLdap
5+
*
6+
* Perun adapter which uses Perun LDAP interface
7+
*/
8+
class sspmod_perun_AdapterLdap extends sspmod_perun_Adapter
9+
{
10+
11+
12+
public function getPerunUser($idpEntityId, $uid)
13+
{
14+
$user = sspmod_perun_LdapConnector::searchForEntity("ou=People,dc=perun,dc=cesnet,dc=cz",
15+
"(eduPersonPrincipalNames=$uid)",
16+
array("perunUserId", "displayName", "cn", "givenName", "sn", "preferredMail", "mail")
17+
);
18+
if (is_null($user)) {
19+
return $user;
20+
}
21+
22+
if (isset($user['displayName'][0])) {
23+
$name = $user['displayName'][0];
24+
} else if (isset($user['cn'][0])) {
25+
$name = $user['cn'][0];
26+
} else {
27+
$name = null;
28+
}
29+
return new sspmod_perun_model_User($user['perunUserId'][0], $name);
30+
}
31+
32+
33+
public function getMemberGroups($user, $vo)
34+
{
35+
$userId = $user->getId();
36+
$userWithMembership = sspmod_perun_LdapConnector::searchForEntity("perunUserId=$userId,ou=People,dc=perun,dc=cesnet,dc=cz",
37+
"(objectClass=perunUser)",
38+
array("perunUserId", "memberOf")
39+
);
40+
41+
$groups = array();
42+
foreach ($userWithMembership['memberOf'] as $groupDn) {
43+
$voId = explode('=', explode(',', $groupDn)[1], 2)[1];
44+
if ($voId != $vo->getId()) {
45+
continue;
46+
}
47+
48+
$group = sspmod_perun_LdapConnector::searchForEntity($groupDn,
49+
"(objectClass=perunGroup)",
50+
array("perunGroupId", "cn", "perunUniqueGroupName", "perunVoId", "description")
51+
);
52+
# SHOULD BE REMOVED, because Perun cannot work with groupName which do not contain voName - edited on 28.6.2017 by michalp
53+
#$groupName = substr($group['perunUniqueGroupName'][0], strlen($vo->getShortName().':'));
54+
array_push($groups, new sspmod_perun_model_Group($group['perunGroupId'][0], $group['perunUniqueGroupName'][0], $group['description'][0]));
55+
}
56+
57+
return $groups;
58+
}
59+
60+
61+
public function getSpGroups($spEntityId, $vo)
62+
{
63+
$resources = sspmod_perun_LdapConnector::searchForEntities("dc=perun,dc=cesnet,dc=cz",
64+
"(&(objectClass=perunResource)(entityID=$spEntityId))",
65+
array("perunResourceId", "assignedGroupId")
66+
);
67+
$voId = $vo->getId();
68+
69+
$groups = array();
70+
foreach ($resources as $resource) {
71+
foreach ($resource['assignedGroupId'] as $groupId) {
72+
$group = sspmod_perun_LdapConnector::searchForEntity("perunGroupId=$groupId,perunVoId=$voId,dc=perun,dc=cesnet,dc=cz",
73+
"(objectClass=perunGroup)",
74+
array("perunGroupId", "cn", "perunUniqueGroupName", "perunVoId", "description")
75+
);
76+
# SHOULD BE REMOVED, because Perun cannot work with groupName which do not contain voName - edited on 28.6.2017 by michalp
77+
#$groupName = substr($group['perunUniqueGroupName'][0], strlen($vo->getShortName().':'));
78+
array_push($groups, new sspmod_perun_model_Group($group['perunGroupId'][0], $group['perunUniqueGroupName'][0], $group['description'][0]));
79+
}
80+
}
81+
82+
$groups = $this->removeDuplicateEntities($groups);
83+
84+
return $groups;
85+
}
86+
87+
88+
public function getGroupByName($vo, $name)
89+
{
90+
$voId = $vo->getId();
91+
$group = sspmod_perun_LdapConnector::searchForEntity("perunVoId=$voId,dc=perun,dc=cesnet,dc=cz",
92+
"(&(objectClass=perunGroup)(perunUniqueGroupName=$name))",
93+
array("perunGroupId", "cn", "perunUniqueGroupName", "perunVoId", "description")
94+
);
95+
if (is_null($group)) {
96+
throw new SimpleSAML_Error_Exception("Group with name: $name in VO: ".$vo->getName()." does not exists in Perun LDAP.");
97+
}
98+
$groupName = substr($group['perunUniqueGroupName'][0], strlen($vo->getShortName().':'));
99+
return new sspmod_perun_model_Group($group['perunGroupId'][0], $groupName, $group['description'][0]);
100+
}
101+
102+
103+
public function getVoByShortName($voShortName)
104+
{
105+
$vo = sspmod_perun_LdapConnector::searchForEntity("dc=perun,dc=cesnet,dc=cz",
106+
"(&(objectClass=perunVo)(o=$voShortName))",
107+
array("perunVoId", "o", "description")
108+
);
109+
if (is_null($vo)) {
110+
throw new SimpleSAML_Error_Exception("Vo with name: $vo does not exists in Perun LDAP.");
111+
}
112+
113+
return new sspmod_perun_model_Vo($vo['perunVoId'][0], $vo['description'][0], $vo['o'][0]);
114+
}
115+
116+
117+
public function getUserAttributes($user, $attrNames)
118+
{
119+
$userId = $user->getId();
120+
$attributes = sspmod_perun_LdapConnector::searchForEntity("perunUserId=$userId,ou=People,dc=perun,dc=cesnet,dc=cz",
121+
"(objectClass=perunUser)",
122+
$attrNames
123+
);
124+
// user in ldap (simplified by LdapConnector method) is actually set of its attributes
125+
return $attributes;
126+
}
127+
128+
}

0 commit comments

Comments
 (0)