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

Commit e5d27e1

Browse files
Take service name in listOfSps from an attribute (#126)
Take service name in listOfSps from an attribute * New attribute is required in config: 'listOfSps.serviceNameAttr'
2 parents 58f229a + 05f0824 commit e5d27e1

File tree

5 files changed

+28
-9
lines changed

5 files changed

+28
-9
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ All notable changes to this project will be documented in this file.
1111
- Changed the way of getting attribute names for interfaces: through internal attribute names in perun_attributes.php config
1212
- Return sorted eduPersonEntitlement
1313
- Don't show previous selection when user show all entries on the discovery page
14-
- ListOfSps - Don't show the description by default
14+
- ListOfSps
15+
- Don't show the description by default
16+
- Added required attribute 'listOfSps.serviceNameAttr' !!!
1517

1618
## [v3.9.0]
1719
#### Added

config-templates/module_perun.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@
144144
* Specify attribute name for facility attribute proxy identifiers
145145
*/
146146
'listOfSps.perunProxyIdentifierAttr' => '',
147+
148+
/**
149+
* Specify attribute name for facility attribute with service name
150+
*/
151+
'listOfSps.serviceNameAttr' => '',
147152

148153
/**
149154
* Specify attribute name for facility attribute with loginUrL for service

lib/ListOfSps.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,13 @@ public static function getClass($attribute)
2525
}
2626
}
2727

28-
public static function printServiceName($service)
28+
public static function printServiceName($name, $loginURL = null)
2929
{
30-
if (empty($service['loginURL']['value'])
31-
) {
32-
return $service['facility']->getName();
30+
if (empty($loginURL)) {
31+
return $name;
3332
}
3433

35-
return "<a class='customLink' href='" . $service['loginURL']['value'] . "'>" .
36-
$service['facility']->getName() . "</a>";
34+
return "<a class='customLink' href='" . htmlspecialchars($loginURL) . "'>" . htmlspecialchars($name) . "</a>";
3735
}
3836

3937
public static function printAttributeValue($attribute, $service, $attr)

templates/listOfSps-tpl.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@
115115
continue;
116116
}
117117
echo '<tr>';
118-
echo '<td>' . ListOfSps::printServiceName($service) . '</td>';
118+
echo '<td>'
119+
. ListOfSps::printServiceName($service['name']['value'], $service['loginURL']['value'] ?? null)
120+
. '</td>';
119121
if (array_key_exists($service['facility']->getID(), $samlServices)) {
120122
echo '<td>' . $this->t('{perun:listOfSps:saml}') . '</td>';
121123
} else {

www/listOfSps.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
const ATTRIBUTES_DEFINITIONS = 'listOfSps.attributesDefinitions';
1212
const SHOW_OIDC_SERVICES = 'listOfSps.showOIDCServices';
1313

14+
const PERUN_SERVICE_NAME_ATTR_NAME = 'listOfSps.serviceNameAttr';
1415
const PERUN_PROXY_IDENTIFIER_ATTR_NAME = 'listOfSps.perunProxyIdentifierAttr';
1516
const PERUN_LOGIN_URL_ATTR_NAME = 'listOfSps.loginURLAttr';
1617
const PERUN_TEST_SP_ATTR_NAME = 'listOfSps.isTestSpAttr';
@@ -62,6 +63,13 @@
6263
);
6364
}
6465

66+
$perunServiceNameAttr = $conf->getString(PERUN_SERVICE_NAME_ATTR_NAME, null);
67+
if (empty($perunServiceNameAttr)) {
68+
throw new Exception(
69+
'perun:listOfSps: missing mandatory config option \''
70+
. PERUN_SERVICE_NAME_ATTR_NAME . '\'.'
71+
);
72+
}
6573
$perunLoginURLAttr = $conf->getString(PERUN_LOGIN_URL_ATTR_NAME, null);
6674
$perunTestSpAttr = $conf->getString(PERUN_TEST_SP_ATTR_NAME, null);
6775
$perunShowOnServiceListAttr
@@ -76,6 +84,7 @@
7684
$attrNames = [];
7785

7886
array_push($attrNames, $perunSaml2EntityIdAttr);
87+
array_push($attrNames, $perunServiceNameAttr);
7988
if (!empty($perunOidcClientIdAttr)) {
8089
array_push($attrNames, $perunOidcClientIdAttr);
8190
}
@@ -106,6 +115,7 @@
106115
if (!empty($facilityAttributes[$perunSaml2EntityIdAttr]['value'])) {
107116
$samlServices[$facility->getId()] = [
108117
'facility' => $facility,
118+
'name' => $facilityAttributes[$perunServiceNameAttr],
109119
'loginURL' => $facilityAttributes[$perunLoginURLAttr],
110120
'showOnServiceList' => $facilityAttributes[$perunShowOnServiceListAttr],
111121
'facilityAttributes' => $facilityAttributes
@@ -118,6 +128,7 @@
118128
if ($showOIDCServices && !empty($facilityAttributes[$perunOidcClientIdAttr]['value'])) {
119129
$oidcServices[$facility->getId()] = [
120130
'facility' => $facility,
131+
'name' => $facilityAttributes[$perunServiceNameAttr],
121132
'loginURL' => $facilityAttributes[$perunLoginURLAttr],
122133
'showOnServiceList' => $facilityAttributes[$perunShowOnServiceListAttr],
123134
'facilityAttributes' => $facilityAttributes
@@ -137,6 +148,7 @@
137148
$attributesToShow = [];
138149
foreach ($attrNames as $attrName) {
139150
if ($attrName !== $perunLoginURLAttr
151+
&& $attrName !== $perunServiceNameAttr
140152
&& $attrName !== $perunShowOnServiceListAttr
141153
&& $attrName !== $perunTestSpAttr
142154
&& $attrName !== $perunOidcClientIdAttr
@@ -161,7 +173,7 @@
161173
$json['statistics']['oidcTestServicesCount'] = $statistics['oidcTestServicesCount'];
162174
foreach ($allServices as $service) {
163175
$a = [];
164-
$a['name'] = $service['facility']->getName();
176+
$a['name'] = $service['facilityAttributes'][$perunServiceNameAttr]['value'];
165177

166178
if (array_key_exists($service['facility']->getID(), $samlServices)) {
167179
$a['authenticationProtocol'] = 'SAML';

0 commit comments

Comments
 (0)