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

Commit deddb85

Browse files
Merge pull request #68 from pajavyskocil/ds_metadata_endpoint
Ds metadata endpoint
2 parents b9b588b + 71bebba commit deddb85

File tree

3 files changed

+103
-32
lines changed

3 files changed

+103
-32
lines changed

CHANGELOG.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@
22
All notable changes to this project will be documented in this file.
33

44
## [Unreleased]
5+
#### Added
6+
- Added endpoint to get filtered list of metadata in format:
7+
```json
8+
[
9+
{
10+
"entityid": "https://entityid1/",
11+
"name": {
12+
"en": "IdP1",
13+
"cs": "IdP1"
14+
}
15+
},
16+
{ ... }
17+
]
18+
```
19+
520
#### Changed
621
- RpcConnector now stores cookie into file
722
- Set CONNECTTIMEOUT and TIMEOUT in RpcConnector
@@ -10,6 +25,7 @@ All notable changes to this project will be documented in this file.
1025
#### Fixed
1126
- Fixed bug in redirect to registration in case only one VO and one group is available
1227

28+
1329
## [v3.2.0]
1430
#### Added
1531
- Added filter JoinGroupsAndEduPersonEntitlement
@@ -157,7 +173,6 @@ when storing one Perun attribute to more SAML attribute
157173
## [v1.0.0]
158174

159175
[Unreleased]: https://github.com/CESNET/perun-simplesamlphp-module/tree/master
160-
[v3.2.1]: https://github.com/CESNET/perun-simplesamlphp-module/tree/v3.2.1
161176
[v3.2.0]: https://github.com/CESNET/perun-simplesamlphp-module/tree/v3.2.0
162177
[v3.1.1]: https://github.com/CESNET/perun-simplesamlphp-module/tree/v3.1.1
163178
[v3.1.0]: https://github.com/CESNET/perun-simplesamlphp-module/tree/v3.1.0

lib/Disco.php

Lines changed: 65 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace SimpleSAML\Module\perun;
44

5+
use SimpleSAML\Module\discopower\PowerIdPDisco;
56
use SimpleSAML\Utils\HTTP;
67
use SimpleSAML\Error\Exception;
78
use SimpleSAML\Auth\State;
@@ -20,7 +21,7 @@
2021
* @author Ondrej Velisek <[email protected]>
2122
* @author Pavel Vyskocil <[email protected]>
2223
*/
23-
class Disco extends \SimpleSAML\Module\discopower\PowerIdPDisco
24+
class Disco extends PowerIdPDisco
2425
{
2526
const CONFIG_FILE_NAME = 'module_perun.php';
2627
const PROPNAME_DISABLE_WHITELISTING = 'disco.disableWhitelisting';
@@ -66,9 +67,6 @@ public function __construct(array $metadataSets, $instance)
6667
$this->originalsp = $state['SPMetadata'];
6768
}
6869

69-
$this->service = IdpListsService::getInstance();
70-
$this->whitelist = $this->service->getWhitelistEntityIds();
71-
$this->greylist = $this->service->getGreylistEntityIds();
7270
}
7371

7472
/**
@@ -135,11 +133,7 @@ protected function filterList($list)
135133
|| !$this->originalsp['disco.doNotFilterIdps']
136134
) {
137135
$list = parent::filterList($list);
138-
$list = $this->scoping($list);
139-
if (!$disableWhitelisting) {
140-
$list = $this->whitelisting($list);
141-
}
142-
$list = $this->greylisting($list);
136+
self::doFilter($list, $disableWhitelisting, $this->scopedIDPList);
143137
$list = $this->greylistingPerSP($list, $this->originalsp);
144138
}
145139

@@ -150,6 +144,34 @@ protected function filterList($list)
150144
return $list;
151145
}
152146

147+
/**
148+
* Filter out IdP which:
149+
* 1. are not in SAML2 Scoping attribute list (SAML2 feature)
150+
* 2. are not whitelisted (if whitelisting is allowed)
151+
* 3. are greylisted
152+
*
153+
* @param array $list A map of entities to filter.
154+
* @param bool $disableWhitelisting
155+
* @param array $scopedIdPList
156+
*
157+
* @return array The list in $list after filtering entities.
158+
* @throws Exception In case
159+
*/
160+
public static function doFilter($list, $disableWhitelisting = false, $scopedIdPList = [])
161+
{
162+
$service = IdpListsService::getInstance();
163+
$whitelist = $service->getWhitelistEntityIds();
164+
$greylist = $service->getGreylistEntityIds();
165+
166+
$list = self::scoping($list, $scopedIdPList);
167+
if (!$disableWhitelisting) {
168+
$list = self::whitelisting($list, $whitelist);
169+
}
170+
$list = self::greylisting($list, $greylist);
171+
172+
return $list;
173+
}
174+
153175
/**
154176
* Filter a list of entities for addInstitution app according to if entityID is whitelisted or not
155177
*
@@ -159,8 +181,10 @@ protected function filterList($list)
159181
*/
160182
protected function filterAddInstitutionList($list)
161183
{
184+
$service = IdpListsService::getInstance();
185+
$whitelist = $service->getWhitelistEntityIds();
162186
foreach ($list as $entityId => $idp) {
163-
if (in_array($entityId, $this->whitelist)) {
187+
if (in_array($entityId, $whitelist)) {
164188
unset($list[$entityId]);
165189
}
166190
}
@@ -174,30 +198,41 @@ protected function filterAddInstitutionList($list)
174198

175199
/**
176200
* Filter out IdP which are not in SAML2 Scoping attribute list (SAML2 feature)
177-
* @param $list
178-
* @return array of idps
201+
*
202+
* @param array $list A map of entities to filter.
203+
* @param array $scopedIDPList
204+
*
205+
* @return array The list in $list after filtering entities.
179206
*/
180-
protected function scoping($list)
207+
protected static function scoping($list, $scopedIDPList)
181208
{
182-
if (!empty($this->scopedIDPList)) {
209+
if (!empty($scopedIDPList)) {
183210
foreach ($list as $entityId => $idp) {
184-
if (!in_array($entityId, $this->scopedIDPList)) {
211+
if (!in_array($entityId, $scopedIDPList)) {
185212
unset($list[$entityId]);
186213
}
187214
}
188215
}
189-
//SimpleSAML\Logger::debug(
190-
//'perun.Disco.filterList: Idps after SAML2 Scoping: ' . var_export(array_keys($list), true)
191-
//);
192216
return $list;
193217
}
194218

195-
protected function whitelisting($list)
219+
/**
220+
* Filter out IdP which:
221+
* 1. are not whitelisted
222+
* 2. are not supported research and scholarship
223+
* 3. are not supported code of conduct
224+
*
225+
* @param array $list A map of entities to filter.
226+
* @param array $whitelist The list of whitelisted IdPs
227+
*
228+
* @return array The list in $list after filtering entities.
229+
*/
230+
protected static function whitelisting($list, $whitelist)
196231
{
197232
foreach ($list as $entityId => $idp) {
198233
$unset = true;
199234

200-
if (in_array($entityId, $this->whitelist)) {
235+
if (in_array($entityId, $whitelist)) {
201236
$unset = false;
202237
}
203238
if (isset($idp['EntityAttributes']['http://macedir.org/entity-category-support'])) {
@@ -223,23 +258,25 @@ protected function whitelisting($list)
223258
unset($list[$entityId]);
224259
}
225260
}
226-
//SimpleSAML\Logger::debug(
227-
//'perun.Disco.filterList: Idps after Whitelisting: ' . var_export(array_keys($list), true)
228-
//);
229261
return $list;
230262
}
231263

232-
protected function greylisting($list)
264+
/**
265+
* Filter out IdP which are greylisted
266+
*
267+
* @param array $list A map of entities to filter.
268+
* @param array $greylist The list of greylisted IdPs
269+
*
270+
* @return array The list in $list after filtering entities.
271+
*/
272+
protected static function greylisting($list, $greylist)
233273
{
234274
foreach ($list as $entityId => $idp) {
235-
if (in_array($entityId, $this->greylist)) {
275+
if (in_array($entityId, $greylist)) {
236276
unset($list[$entityId]);
237277
}
238278
}
239279

240-
//SimpleSAML\Logger::debug(
241-
//'perun.Disco.filterList: Idps after Greylisting: ' . var_export(array_keys($list), true)
242-
//);
243280
return $list;
244281
}
245282

@@ -253,9 +290,6 @@ protected function greylistingPerSP($list, $sp)
253290
}
254291
}
255292

256-
//SimpleSAML\Logger::debug(
257-
//'perun.Disco.filterList: Idps after Greylisting per SP: ' . var_export(array_keys($list), true)
258-
//);
259293
return $list;
260294
}
261295

www/listOfMetadata.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
use SimpleSAML\Metadata\MetaDataStorageHandler;
4+
use \SimpleSAML\Module\perun\Disco;
5+
6+
$metadataHandler = MetaDataStorageHandler::getMetadataHandler();
7+
8+
$metadata = $metadataHandler->getList();
9+
$filteredMetadata = Disco::doFilter($metadata);
10+
11+
$data = [];
12+
13+
foreach ($filteredMetadata as $metadata) {
14+
$item = [];
15+
$item['entityid'] = $metadata['entityid'];
16+
$item['name'] = $metadata['name'];
17+
array_push($data, $item);
18+
}
19+
20+
header('Content-type: application/json');
21+
echo json_encode($data);
22+
exit;

0 commit comments

Comments
 (0)