Skip to content
Snippets Groups Projects
Commit 3c5c3b60 authored by Thijs Kinkhorst's avatar Thijs Kinkhorst
Browse files

Move NameId generation to separate method for understandability

No functional changes
parent e11c0eaf
No related branches found
No related tags found
No related merge requests found
...@@ -1214,9 +1214,32 @@ class SAML2 ...@@ -1214,9 +1214,32 @@ class SAML2
$a->setAttributes($attributes); $a->setAttributes($attributes);
} }
$nameId = self::generateNameId($idpMetadata, $spMetadata, $state);
$state['saml:idp:NameID'] = $nameId;
$a->setNameId($nameId);
$encryptNameId = $spMetadata->getOptionalBoolean('nameid.encryption', null);
if ($encryptNameId === null) {
$encryptNameId = $idpMetadata->getOptionalBoolean('nameid.encryption', false);
}
if ($encryptNameId) {
$a->encryptNameId(\SimpleSAML\Module\saml\Message::getEncryptionKey($spMetadata));
}
return $a;
}
/**
* Helper for buildAssertion to decide on an NameID to set
*/
private static function generateNameId(
Configuration $idpMetadata,
Configuration $spMetadata,
array $state
): NameID
{
$nameIdFormat = null; $nameIdFormat = null;
// generate the NameID for the assertion
if (isset($state['saml:NameIDFormat'])) { if (isset($state['saml:NameIDFormat'])) {
$nameIdFormat = $state['saml:NameIDFormat']; $nameIdFormat = $state['saml:NameIDFormat'];
} }
...@@ -1236,6 +1259,7 @@ class SAML2 ...@@ -1236,6 +1259,7 @@ class SAML2
} else { } else {
if ($nameIdFormat === Constants::NAMEID_TRANSIENT) { if ($nameIdFormat === Constants::NAMEID_TRANSIENT) {
// generate a random id // generate a random id
$randomUtils = new Utils\Random();
$nameIdValue = $randomUtils->generateID(); $nameIdValue = $randomUtils->generateID();
} }
...@@ -1250,22 +1274,9 @@ class SAML2 ...@@ -1250,22 +1274,9 @@ class SAML2
$nameId->setSPNameQualifier($spNameQualifier); $nameId->setSPNameQualifier($spNameQualifier);
} }
$state['saml:idp:NameID'] = $nameId; return $nameId;
$a->setNameId($nameId);
$encryptNameId = $spMetadata->getOptionalBoolean('nameid.encryption', null);
if ($encryptNameId === null) {
$encryptNameId = $idpMetadata->getOptionalBoolean('nameid.encryption', false);
}
if ($encryptNameId) {
$a->encryptNameId(\SimpleSAML\Module\saml\Message::getEncryptionKey($spMetadata));
}
return $a;
} }
/** /**
* Encrypt an assertion. * Encrypt an assertion.
* *
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment