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

Commit 766386d

Browse files
authored
Merge pull request #33 from pajavyskocil/fixGetPerunUser
Changed login and registration process
2 parents 807cb12 + 35fb1c3 commit 766386d

17 files changed

+798
-216
lines changed

CHANGELOG.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,18 @@ All notable changes to this project will be documented in this file.
44
## [Unreleased]
55
[Added]
66
- Added badges to README
7-
- Added new property to Facility model: description
87
- Added page with configurable table of SPs on Proxy
8+
- Added new model Member
9+
- Added new model Resource
10+
- New methods for getting data from Perun LDAP and Perun RPC
911

10-
[Changed]
11-
- Connectors methods are not static for now.
12-
- Added constructors to Adapters, which allows specified config file for each connections.
13-
- New properties voId and uniqueName in Group model
12+
[Changed]
13+
- Connectors methods are not static for now.
14+
- Added constructors to Adapters, which allows specified config file for each connections.
15+
- New properties voId and uniqueName in Group model
16+
- Function getSpGroup require only one param($spEntityId)
17+
- Function unauthorize in PerunIdentity is now public
18+
- Changed the login and registration process
1419

1520
## [v1.0.0]
1621

config-templates/processFilterConfigurations-example.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
## PerunIdentity
2+
3+
Example how to configure PerunIdentity module:
4+
```php
5+
24 => array(
6+
'class' => 'perun:ProxyFilter',
7+
'filterSPs' => $perunEntityIds,
8+
'config' => array(
9+
'class' => 'perun:PerunIdentity',
10+
'uidsAttr' => array('eduPersonUniqueId', 'eduPersonPrincipalName', 'eduPersonTargetedIDString', 'nameid', 'uid'),
11+
'voShortName' => 'einfra',
12+
'registerUrlBase' => 'https://perun.cesnet.cz/allfed/registrar',
13+
'registerUrl' => 'https://login.cesnet.cz/register',
14+
'interface' => 'ldap',
15+
'facilityCheckGroupMembershipAttr' => 'urn:perun:facility:attribute-def:def:checkGroupMembership',
16+
'facilityVoShortNamesAttr' => 'urn:perun:facility:attribute-def:virt:voShortNames',
17+
'facilityDynamicRegistrationAttr' => 'urn:perun:facility:attribute-def:def:dynamicRegistration',
18+
'facilityRegisterUrlAttr' => 'urn:perun:facility:attribute-def:def:registerUrl',
19+
'facilityAllowRegistrationToGroups' => 'urn:perun:facility:attribute-def:def:allowRegistration',
20+
),
21+
),
22+
```
23+
24+
125
## IdPAttribute
226

327
Example how to enable filter IdPAttribute:

dictionaries/perun.definition.json

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
11
{
2-
"choose-group-tpl_header": {
3-
"en": "Select group which fits you most",
4-
"cs": "Vyberte si odpovídající skupinu"
2+
"choose-vo-and-group-tpl_header": {
3+
"en": "Access forbidden",
4+
"cs": "Přístup odepřen"
55
},
6-
"choose-group-tpl_text": {
7-
"en": "It will give you access to the requested service.",
8-
"cs": "Získáte tak přístup k požadované službě."
6+
"choose-vo-and-group-tpl_text": {
7+
"en": "You don't meet the prerequisites for accessing the service: ",
8+
"cs": "Nesplňujete prerekvizity pro přístup ke službě: "
9+
},
10+
"choose-vo-and-group-tpl_message": {
11+
"en": "To access the service it is necessary to have a valid membership in one of the following groups. Please proceed with selection of organization and group for registration.",
12+
"cs": "Pro získání přístupu k dané službě je nutné se zaregistrovat do jedné z následujících skupin. Pokračujte výběrem příslušné organizace a skupiny."
13+
},
14+
"choose-vo-and-group-tpl_select-vo": {
15+
"en": "Select virtual organization for registration: ",
16+
"cs": "Vyberte virtuální organizaci: "
17+
},
18+
"choose-vo-and-group-tpl_select-group": {
19+
"en": "Select group for registration: ",
20+
"cs": "Vyberte skupinu pro registraci: "
21+
},
22+
"choose-vo-and-group-tpl_continue": {
23+
"en": "Continue",
24+
"cs": "Pokračovat"
925
},
1026
"disco-tpl_previous-selection": {
1127
"en": "your previous selection",
@@ -63,6 +79,10 @@
6379
"en": "Go back to ",
6480
"cs": "Vraťte se zpět na "
6581
},
82+
"unauthorized-access_redirect_to_registration": {
83+
"en": "Now you will be redirected to registration to Perun system.",
84+
"cs": "Nyní budete přesměrování na registraci do systému Perun."
85+
},
6686
"listOfSps_header": {
6787
"en": "List of Service providers",
6888
"cs": "Seznam služeb"

lib/Adapter.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ public abstract function getGroupByName($vo, $name);
5555
*/
5656
public abstract function getVoByShortName($voShortName);
5757

58+
/**
59+
* @param integer $id
60+
* @return sspmod_perun_model_Vo
61+
* @throws SimpleSAML_Error_Exception if does not exists
62+
*/
63+
public abstract function getVoById($id);
64+
5865
/**
5966
* @param sspmod_perun_model_User $user perun user
6067
* @param sspmod_perun_model_Vo $vo vo we are working with.
@@ -64,11 +71,10 @@ public abstract function getMemberGroups($user, $vo);
6471

6572
/**
6673
* @param string $spEntityId entity id of the sp
67-
* @param sspmod_perun_model_Vo $vo
6874
* @return sspmod_perun_model_Group[] from vo which are assigned to all facilities with spEntityId.
6975
* registering to those groups should should allow access to the service
7076
*/
71-
public abstract function getSpGroups($spEntityId, $vo);
77+
public abstract function getSpGroups($spEntityId);
7278

7379
/**
7480
* @param sspmod_perun_model_User $user

lib/AdapterLdap.php

Lines changed: 23 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;
@@ -151,6 +153,19 @@ public function getVoByShortName($voShortName)
151153
return new sspmod_perun_model_Vo($vo['perunVoId'][0], $vo['description'][0], $vo['o'][0]);
152154
}
153155

156+
public function getVoById($id)
157+
{
158+
$vo = sspmod_perun_LdapConnector::searchForEntity($this->ldapBase,
159+
"(&(objectClass=perunVo)(perunVoId=$id))",
160+
array("o", "description")
161+
);
162+
if (is_null($vo)) {
163+
throw new SimpleSAML_Error_Exception("Vo with id: $id does not exists in Perun LDAP.");
164+
}
165+
166+
return new sspmod_perun_model_Vo($id, $vo['description'][0], $vo['o'][0]);
167+
}
168+
154169

155170
public function getUserAttributes($user, $attrNames)
156171
{

lib/AdapterRpc.php

Lines changed: 58 additions & 25 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) {
125+
foreach ($resources as $resource) {
134126
$groups = $this->connector->get('resourcesManager', 'getAssignedGroups', array(
135-
'resource' => $spResource['id'],
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);
@@ -176,6 +167,14 @@ public function getVoByShortName($voShortName)
176167
return new sspmod_perun_model_Vo($vo['id'], $vo['name'], $vo['shortName']);
177168
}
178169

170+
public function getVoById($id)
171+
{
172+
$vo = $this->connector->get('vosManager', 'getVoById', array(
173+
'id' => $id,
174+
));
175+
176+
return new sspmod_perun_model_Vo($vo['id'], $vo['name'], $vo['shortName']);
177+
}
179178

180179
public function getUserAttributes($user, $attrNames)
181180
{
@@ -300,6 +299,40 @@ public function getFacilitiesByEntityId($spEntityId)
300299
return $facilities;
301300
}
302301

302+
/**
303+
* Returns member by User and Vo
304+
* @param sspmod_perun_model_User $user
305+
* @param sspmod_perun_model_Vo $vo
306+
* @return sspmod_perun_model_Member
307+
*/
308+
public function getMemberByUser($user, $vo) {
309+
$member = $this->connector->get('membersManager', 'getMemberByUser', array(
310+
'user' => $user->getId(),
311+
'vo' => $vo->getId(),
312+
));
313+
if (is_null($member)) {
314+
throw new SimpleSAML_Error_Exception("Member for User with name " . $user->getName() . " and Vo with shortName " .
315+
$vo->getShortName() . "does not exist in Perun!");
316+
}
317+
return new sspmod_perun_model_Member($member['id'], $member['voId'], $member['status']);
318+
}
319+
320+
/**
321+
* Returns true if group has registration form, false otherwise
322+
* @param sspmod_perun_model_Group $group
323+
* @return bool
324+
*/
325+
public function hasRegistrationForm($group) {
326+
try {
327+
$this->connector->get( 'registrarManager', 'getApplicationForm', array(
328+
'group' => $group->getId(),
329+
));
330+
return true;
331+
} catch (Exception $exception) {
332+
return false;
333+
}
334+
}
335+
303336
public function searchFacilitiesByAttributeValue($attribute)
304337
{
305338
$perunAttrs = $this->connector->post('searcher', 'getFacilities', array(

0 commit comments

Comments
 (0)