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

Commit 9416f39

Browse files
author
Dominik František Bučík
authored
Merge pull request #246 from BaranekD/disco_previousSelection
feat: Do not show previous selection for SPs listed in config
2 parents 04c6082 + dda8140 commit 9416f39

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

config-templates/module_perun.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,8 @@
264264
'display_sp_name' => false,
265265
// interface needed just in case of display_sp_name => true
266266
'interface' => 'rpc',
267+
// don't show 'previous selection' for entity/client ids listed below
268+
'skip_previous_selection_services' => [],
267269
],
268270

269271
'warning_test_sp_config' => [

lib/Disco.php

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ class Disco extends PowerIdPDisco
5353

5454
public const ADD_AUTHN_CONTEXT_CLASSES_FOR_MFA = 'add_authn_context_classes_for_mfa';
5555

56+
public const SKIP_PREVIOUS_SELECTION = 'skip_previous_selection_services';
57+
5658
// CONFIGURATION ENTRIES IDP BLOCKS
5759
public const IDP_BLOCKS = 'idp_blocks_config';
5860

@@ -117,6 +119,8 @@ class Disco extends PowerIdPDisco
117119

118120
public const IDP_ENTITY_ID = 'entityid';
119121

122+
public const SP_ENTITY_ID = 'entityid';
123+
120124
public const IDP_COLOR = 'color';
121125

122126
public const IDP_FULL_DISPLAY_NAME = 'fullDisplayName';
@@ -282,6 +286,11 @@ public function handleRequest()
282286
$this->fillSpName($t);
283287
}
284288

289+
$spsToSkipPreviousSelection = $this->wayfConfiguration->getArray(self::SKIP_PREVIOUS_SELECTION, []);
290+
$spIdentifier = $this->getSpIdentifier($t);
291+
292+
$skipPreviousSelection = in_array($spIdentifier, $spsToSkipPreviousSelection, true);
293+
285294
$t->data[self::ORIGINAL_SP] = $this->originalsp;
286295
$t->data[self::IDP_LIST] = $this->idplistStructured($idpList);
287296
$t->data[self::PREFERRED_IDP] = $preferredIdP;
@@ -293,6 +302,7 @@ public function handleRequest()
293302
$t->data[self::WAYF] = $this->wayfConfiguration;
294303
$t->data[self::NAME] = $this->spName;
295304
$t->data[self::DISPLAY_SP] = $this->displaySpName;
305+
$t->data[self::SKIP_PREVIOUS_SELECTION] = $skipPreviousSelection;
296306
$t->show();
297307
}
298308

@@ -961,8 +971,8 @@ private function fillSpNameForOidc($t, $clientIdWithPrefix)
961971
private function fillSpNameForSaml($t)
962972
{
963973
$this->spName = null;
964-
if (!empty($this->originalsp['entityid'])) {
965-
$entityId = $this->originalsp['entityid'];
974+
if (!empty($this->originalsp[self::SP_ENTITY_ID])) {
975+
$entityId = $this->originalsp[self::SP_ENTITY_ID];
966976
$entityIdAttr = $this->wayfConfiguration->getString(self::ENTITY_ID_ATTR, null);
967977
if (null === $entityIdAttr) {
968978
$facility = $this->adapter->getFacilityByEntityId($entityId);
@@ -994,4 +1004,17 @@ private function prepareAcrsForMfa(array &$state)
9941004
$contextsToAdd = $this->wayfConfiguration->getArray(self::ADD_AUTHN_CONTEXT_CLASSES_FOR_MFA, []);
9951005
MultifactorAcrs::addAndStoreAcrs($state, $contextsToAdd);
9961006
}
1007+
1008+
private function getSpIdentifier()
1009+
{
1010+
$clientIdWithPrefix = self::substrInArray(self::CLIENT_ID_PREFIX, $this->originalAuthnContextClassRef);
1011+
1012+
if (null !== $clientIdWithPrefix) {
1013+
$parts = explode(':', $clientIdWithPrefix);
1014+
1015+
return end($parts); // clientId
1016+
}
1017+
1018+
return empty($this->originalsp[self::SP_ENTITY_ID]) ? null : $this->originalsp[self::SP_ENTITY_ID];
1019+
}
9971020
}

themes/perun/perun/disco-tpl.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
$wayfConfig = $this->data[Disco::WAYF];
3131
$displaySpName = $this->data[Disco::DISPLAY_SP];
3232
$spName = $this->data[Disco::NAME];
33+
$skipPreviousSelection = $this->data[Disco::SKIP_PREVIOUS_SELECTION];
3334

3435
$translateModule = $wayfConfig->getString(Disco::TRANSLATE_MODULE, 'disco');
3536
$addInstitutionConfig = $wayfConfig->getConfigItem(Disco::ADD_INSTITUTION, null);
@@ -94,7 +95,7 @@
9495
} else {
9596
// CHECK IF WE HAVE PREVIOUS SELECTION, IF YES, DISPLAY IT
9697
// Last selection is not null => Firstly show last selection
97-
if (!empty($this->getPreferredIdp())) {
98+
if (!empty($this->getPreferredIdp()) && !$skipPreviousSelection) {
9899
// ENTRY FOR PREVIOUS SELECTION
99100
echo '<div id="last-used-idp-wrap" class="d-none">' . PHP_EOL;
100101
echo ' <p class="discoDescription-left" id="last-used-idp-desc">'

0 commit comments

Comments
 (0)