Details
Alternatively, refactor validateSignature() to throw exceptions on failure (matching the developer's original intent as documented in the comments), which would make both call sites correct as-is:
public function validateSignature(SAMLClient $client, SamlMessage $message, bool $required = false): bool {
global $gL10n;
$certPem = $client->getValue('smc_x509_certificate');
if (!$certPem) {
if ($required) {
throw new Exception($gL10n->get('SYS_SSO_SAML_SIGNATURE_KEY_MISSING'));
}
return false;
}
// ... (same cert loading logic) ...
$signatureReader = $message->getSignature();
if (is_null($signatureReader)) {
if ($required) {
throw new Exception($gL10n->get('SYS_SSO_SAML_SIGNATURE_MISSING'));
}
return false;
}
try {
if (!$signatureReader->validate($key)) {
throw new Exception($gL10n->get('SYS_SSO_SAML_SIGNATURE_FAILED'));
}
return true;
} catch (Exception $ex) {
throw new Exception($gL10n->get('SYS_SSO_SAML_SIGNATURE_FAILED'));
}
}