Skip to content

Commit 292da61

Browse files
committed
Add possibility to handle nameId NameQualifier attribute in SLO Request
1 parent 383d62e commit 292da61

File tree

4 files changed

+52
-11
lines changed

4 files changed

+52
-11
lines changed

lib/Saml2/Auth.php

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ class OneLogin_Saml2_Auth
3434
*/
3535
private $_nameidFormat;
3636

37+
38+
/**
39+
* NameID NameQualifier
40+
*
41+
* @var string
42+
*/
43+
private $_nameidNameQualifier;
44+
3745
/**
3846
* If user is authenticated.
3947
*
@@ -177,6 +185,7 @@ public function processResponse($requestId = null)
177185
$this->_attributes = $response->getAttributes();
178186
$this->_nameid = $response->getNameId();
179187
$this->_nameidFormat = $response->getNameIdFormat();
188+
$this->_nameidNameQualifier = $response->getNameIdNameQualifier();
180189
$this->_authenticated = true;
181190
$this->_sessionIndex = $response->getSessionIndex();
182191
$this->_sessionExpiration = $response->getSessionNotOnOrAfter();
@@ -336,6 +345,16 @@ public function getNameIdFormat()
336345
return $this->_nameidFormat;
337346
}
338347

348+
/**
349+
* Returns the nameID NameQualifier
350+
*
351+
* @return string The nameID NameQualifier of the assertion
352+
*/
353+
public function getNameIdNameQualifier()
354+
{
355+
return $this->_nameidNameQualifier;
356+
}
357+
339358
/**
340359
* Returns the SessionIndex
341360
*
@@ -436,18 +455,19 @@ public function login($returnTo = null, $parameters = array(), $forceAuthn = fal
436455
/**
437456
* Initiates the SLO process.
438457
*
439-
* @param string|null $returnTo The target URL the user should be returned to after logout.
440-
* @param array $parameters Extra parameters to be added to the GET
441-
* @param string|null $nameId The NameID that will be set in the LogoutRequest.
442-
* @param string|null $sessionIndex The SessionIndex (taken from the SAML Response in the SSO process).
443-
* @param bool $stay True if we want to stay (returns the url string) False to redirect
444-
* @param string|null $nameIdFormat The NameID Format will be set in the LogoutRequest.
458+
* @param string|null $returnTo The target URL the user should be returned to after logout.
459+
* @param array $parameters Extra parameters to be added to the GET
460+
* @param string|null $nameId The NameID that will be set in the LogoutRequest.
461+
* @param string|null $sessionIndex The SessionIndex (taken from the SAML Response in the SSO process).
462+
* @param bool $stay True if we want to stay (returns the url string) False to redirect
463+
* @param string|null $nameIdFormat The NameID Format will be set in the LogoutRequest.
464+
* @param string|null $nameIdNameQualifier The NameID NameQualifier will be set in the LogoutRequest.
445465
*
446466
* @return If $stay is True, it return a string with the SLO URL + LogoutRequest + parameters
447467
*
448468
* @throws OneLogin_Saml2_Error
449469
*/
450-
public function logout($returnTo = null, $parameters = array(), $nameId = null, $sessionIndex = null, $stay = false, $nameIdFormat = null)
470+
public function logout($returnTo = null, $parameters = array(), $nameId = null, $sessionIndex = null, $stay = false, $nameIdFormat = null, $nameIdNameQualifier = null)
451471
{
452472
assert('is_array($parameters)');
453473

@@ -466,7 +486,7 @@ public function logout($returnTo = null, $parameters = array(), $nameId = null,
466486
$nameIdFormat = $this->_nameidFormat;
467487
}
468488

469-
$logoutRequest = new OneLogin_Saml2_LogoutRequest($this->_settings, null, $nameId, $sessionIndex, $nameIdFormat);
489+
$logoutRequest = new OneLogin_Saml2_LogoutRequest($this->_settings, null, $nameId, $sessionIndex, $nameIdFormat, $nameIdNameQualifier);
470490

471491
$this->_lastRequest = $logoutRequest->getXML();
472492
$this->_lastRequestID = $logoutRequest->id;

lib/Saml2/LogoutRequest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ class OneLogin_Saml2_LogoutRequest
3838
* @param string|null $nameId The NameID that will be set in the LogoutRequest.
3939
* @param string|null $sessionIndex The SessionIndex (taken from the SAML Response in the SSO process).
4040
* @param string|null $nameIdFormat The NameID Format will be set in the LogoutRequest.
41+
* @param string|null $nameIdNameQualifier The NameID NameQualifier will be set in the LogoutRequest.
4142
*/
42-
public function __construct(OneLogin_Saml2_Settings $settings, $request = null, $nameId = null, $sessionIndex = null, $nameIdFormat = null)
43+
public function __construct(OneLogin_Saml2_Settings $settings, $request = null, $nameId = null, $sessionIndex = null, $nameIdFormat = null, $nameIdNameQualifier = null)
4344
{
4445
$this->_settings = $settings;
4546

@@ -85,7 +86,8 @@ public function __construct(OneLogin_Saml2_Settings $settings, $request = null,
8586
$nameId,
8687
$spNameQualifier,
8788
$nameIdFormat,
88-
$cert
89+
$cert,
90+
$nameIdNameQualifier
8991
);
9092

9193
$sessionIndexStr = isset($sessionIndex) ? "<samlp:SessionIndex>{$sessionIndex}</samlp:SessionIndex>" : "";

lib/Saml2/Response.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,21 @@ public function getNameIdFormat()
648648
return $nameIdFormat;
649649
}
650650

651+
/**
652+
* Gets the NameID NameQualifier provided by the SAML response from the IdP.
653+
*
654+
* @return string Name ID NameQualifier
655+
*/
656+
public function getNameIdNameQualifier()
657+
{
658+
$nameIdNameQualifier = null;
659+
$nameIdData = $this->getNameIdData();
660+
if (!empty($nameIdData) && isset($nameIdData['NameQualifier'])) {
661+
$nameIdNameQualifier = $nameIdData['NameQualifier'];
662+
}
663+
return $nameIdNameQualifier;
664+
}
665+
651666
/**
652667
* Gets the SessionNotOnOrAfter from the AuthnStatement.
653668
* Could be used to set the local session expiration

lib/Saml2/Utils.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -951,10 +951,11 @@ public static function formatFingerPrint($fingerprint)
951951
* @param string $spnq SP Name Qualifier
952952
* @param string $format SP Format
953953
* @param string|null $cert IdP Public cert to encrypt the nameID
954+
* @param string|null $nq IdP Name Qualifier
954955
*
955956
* @return string $nameIDElement DOMElement | XMLSec nameID
956957
*/
957-
public static function generateNameId($value, $spnq, $format, $cert = null)
958+
public static function generateNameId($value, $spnq, $format, $cert = null, $nq = null)
958959
{
959960

960961
$doc = new DOMDocument();
@@ -963,6 +964,9 @@ public static function generateNameId($value, $spnq, $format, $cert = null)
963964
if (isset($spnq)) {
964965
$nameId->setAttribute('SPNameQualifier', $spnq);
965966
}
967+
if (isset($nq)) {
968+
$nameId->setAttribute('NameQualifier', $nq);
969+
}
966970
$nameId->setAttribute('Format', $format);
967971
$nameId->appendChild($doc->createTextNode($value));
968972

0 commit comments

Comments
 (0)