Skip to content
Snippets Groups Projects
Unverified Commit a1b84cf2 authored by Dominik František Bučík's avatar Dominik František Bučík Committed by GitHub
Browse files

Merge pull request #49 from CESNET/melanger-patch-1

fix: do not prefer MFA at upstream when not preferred at SP
parents c757817f c1b50daa
No related branches found
No related tags found
No related merge requests found
...@@ -46,13 +46,24 @@ class DiscoUtils ...@@ -46,13 +46,24 @@ class DiscoUtils
$upstreamRequestedContexts = []; $upstreamRequestedContexts = [];
if (empty($spRequestedContexts)) { if (empty($spRequestedContexts)) {
Logger::debug(self::DEBUG_PREFIX . 'No AuthnContextClassRef requested, not sending any to upstream IdP.'); Logger::debug(self::DEBUG_PREFIX . 'No AuthnContextClassRef requested, not sending any to upstream IdP.');
} elseif ($authnContextHelper->MFAin($spRequestedContexts)) { } elseif ($authnContextHelper->MFAin($spRequestedContexts) && !$authnContextHelper->SFAin($spRequestedContexts)) {
Logger::debug(self::DEBUG_PREFIX . 'SP requested MFA, will prefer MFA at upstream IdP.'); Logger::debug(self::DEBUG_PREFIX . 'SP requires MFA, will prefer MFA at upstream IdP.');
$upstreamRequestedContexts = array_values(
array_unique(array_merge($mfa_contexts, $spRequestedContexts, $password_contexts))
);
} elseif (
$authnContextHelper->MFAin($spRequestedContexts)
&& self::getMinIndex($spRequestedContexts, $mfa_contexts) < self::getMinIndex(
$spRequestedContexts,
$password_contexts
)
) {
Logger::debug(self::DEBUG_PREFIX . 'SP prefers MFA, will prefer MFA at upstream IdP.');
$upstreamRequestedContexts = array_values( $upstreamRequestedContexts = array_values(
array_unique(array_merge($mfa_contexts, $spRequestedContexts, $password_contexts)) array_unique(array_merge($mfa_contexts, $spRequestedContexts, $password_contexts))
); );
} else { } else {
Logger::debug(self::DEBUG_PREFIX . 'SP did not request MFA, will prefer SFA at upstream IdP.'); Logger::debug(self::DEBUG_PREFIX . 'SP does not prefer MFA, will prefer SFA at upstream IdP.');
$upstreamRequestedContexts = array_values( $upstreamRequestedContexts = array_values(
array_unique(array_merge($spRequestedContexts, $password_contexts, $mfa_contexts)) array_unique(array_merge($spRequestedContexts, $password_contexts, $mfa_contexts))
); );
...@@ -67,4 +78,12 @@ class DiscoUtils ...@@ -67,4 +78,12 @@ class DiscoUtils
$state['saml:RequestedAuthnContext']['AuthnContextClassRef'] = $upstreamRequestedContexts; $state['saml:RequestedAuthnContext']['AuthnContextClassRef'] = $upstreamRequestedContexts;
} }
} }
/**
* Returns first index in arr1 of any element from arr2
*/
private static function getMinIndex($arr1, $arr2)
{
return min(array_keys(array_intersect($arr1, $arr2)));
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment