Skip to content

Commit 7aca365

Browse files
committed
Fix SAML-Toolkits#443. Incorrect Destination in LogoutResponse when using responseUrl. Add IdP value getters to the Settings class
1 parent c51877e commit 7aca365

File tree

6 files changed

+115
-22
lines changed

6 files changed

+115
-22
lines changed

lib/Saml2/Auth.php

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -586,43 +586,33 @@ public function logout($returnTo = null, $parameters = array(), $nameId = null,
586586
}
587587

588588
/**
589-
* Gets the SSO url.
589+
* Gets the IdP SSO url.
590590
*
591-
* @return string The url of the Single Sign On Service
591+
* @return string The url of the IdP Single Sign On Service
592592
*/
593593
public function getSSOurl()
594594
{
595-
$idpData = $this->_settings->getIdPData();
596-
return $idpData['singleSignOnService']['url'];
595+
return $this->_settings->getIdPSSOUrl();
597596
}
598597

599598
/**
600-
* Gets the SLO url.
599+
* Gets the IdP SLO url.
601600
*
602-
* @return string|null The url of the Single Logout Service
601+
* @return string|null The url of the IdP Single Logout Service
603602
*/
604603
public function getSLOurl()
605604
{
606-
$url = null;
607-
$idpData = $this->_settings->getIdPData();
608-
if (isset($idpData['singleLogoutService']) && isset($idpData['singleLogoutService']['url'])) {
609-
$url = $idpData['singleLogoutService']['url'];
610-
}
611-
return $url;
605+
return $this->_settings->getIdPSLOUrl();
612606
}
613607

614608
/**
615-
* Gets the SLO response url.
609+
* Gets the IdP SLO response url.
616610
*
617-
* @return string|null The response url of the Single Logout Service
611+
* @return string|null The response url of the IdP Single Logout Service
618612
*/
619613
public function getSLOResponseUrl()
620614
{
621-
$idpData = $this->_settings->getIdPData();
622-
if (isset($idpData['singleLogoutService']) && isset($idpData['singleLogoutService']['responseUrl'])) {
623-
return $idpData['singleLogoutService']['responseUrl'];
624-
}
625-
return $this->getSLOurl();
615+
return $this->_settings->getIdPSLOResponseUrl();
626616
}
627617

628618
/**

lib/Saml2/LogoutRequest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,15 @@ public function __construct(OneLogin_Saml2_Settings $settings, $request = null,
106106
$sessionIndexStr = isset($sessionIndex) ? "<samlp:SessionIndex>{$sessionIndex}</samlp:SessionIndex>" : "";
107107

108108
$spEntityId = htmlspecialchars($spData['entityId'], ENT_QUOTES);
109+
$destination = $this->_settings->getIdPSLOUrl();
109110
$logoutRequest = <<<LOGOUTREQUEST
110111
<samlp:LogoutRequest
111112
xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
112113
xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"
113114
ID="{$id}"
114115
Version="2.0"
115116
IssueInstant="{$issueInstant}"
116-
Destination="{$idpData['singleLogoutService']['url']}">
117+
Destination="{$destination}">
117118
<saml:Issuer>{$spEntityId}</saml:Issuer>
118119
{$nameIdObj}
119120
{$sessionIndexStr}

lib/Saml2/LogoutResponse.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,13 +240,14 @@ public function build($inResponseTo)
240240
$issueInstant = OneLogin_Saml2_Utils::parseTime2SAML(time());
241241

242242
$spEntityId = htmlspecialchars($spData['entityId'], ENT_QUOTES);
243+
$destination = $this->_settings->getIdPSLOResponseUrl();
243244
$logoutResponse = <<<LOGOUTRESPONSE
244245
<samlp:LogoutResponse xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
245246
xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"
246247
ID="{$this->id}"
247248
Version="2.0"
248249
IssueInstant="{$issueInstant}"
249-
Destination="{$idpData['singleLogoutService']['url']}"
250+
Destination="{$destination}"
250251
InResponseTo="{$inResponseTo}"
251252
>
252253
<saml:Issuer>{$spEntityId}</saml:Issuer>

lib/Saml2/Settings.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,47 @@ public function shouldCompressResponses()
838838
return $this->_compress['responses'];
839839
}
840840

841+
/**
842+
* Gets the IdP SSO url.
843+
*
844+
* @return string|null The url of the IdP Single Sign On Service
845+
*/
846+
public function getIdPSSOUrl()
847+
{
848+
$ssoUrl = null;
849+
if (isset($this->_idp['singleSignOnService']) && isset($this->_idp['singleSignOnService']['url'])) {
850+
$ssoUrl = $this->_idp['singleSignOnService']['url'];
851+
}
852+
return $ssoUrl;
853+
}
854+
855+
/**
856+
* Gets the IdP SLO url.
857+
*
858+
* @return string|null The request url of the IdP Single Logout Service
859+
*/
860+
public function getIdPSLOUrl()
861+
{
862+
$sloUrl = null;
863+
if (isset($this->_idp['singleLogoutService']) && isset($this->_idp['singleLogoutService']['url'])) {
864+
$sloUrl = $this->_idp['singleLogoutService']['url'];
865+
}
866+
return $sloUrl;
867+
}
868+
869+
/**
870+
* Gets the IdP SLO response url.
871+
*
872+
* @return string|null The response url of the IdP Single Logout Service
873+
*/
874+
public function getIdPSLOResponseUrl()
875+
{
876+
if (isset($this->_idp['singleLogoutService']) && isset($this->_idp['singleLogoutService']['responseUrl'])) {
877+
return $this->_idp['singleLogoutService']['responseUrl'];
878+
}
879+
return $this->getIdPSLOUrl();
880+
}
881+
841882
/**
842883
* Gets the SP metadata. The XML representation.
843884
*

tests/src/OneLogin/Saml2/AuthTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function testGetSLOurl()
8282
/**
8383
* Tests the getSLOResponseUrl method of the OneLogin_Saml2_Auth class
8484
*
85-
* @covers OneLogin_Saml2_Auth::getSLOurl
85+
* @covers OneLogin_Saml2_Auth::getSLOResponseUrl
8686
*/
8787
public function testGetSLOResponseUrl()
8888
{

tests/src/OneLogin/Saml2/SettingsTest.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,66 @@ public function testCheckSettings()
419419
}
420420
}
421421

422+
/**
423+
* Tests the getIdPSSOurl method of the OneLogin_Saml2_Settings class
424+
*
425+
* @covers OneLogin_Saml2_Settings::getIdPSSOurl
426+
*/
427+
public function testGetIdPSSOurl()
428+
{
429+
$settingsDir = TEST_ROOT .'/settings/';
430+
include $settingsDir.'settings1.php';
431+
432+
$settings = new OneLogin_Saml2_Settings($settingsInfo);
433+
434+
$ssoUrl = "http://idp.example.com/SSOService.php";
435+
$this->assertEquals($settings->getIdPSSOUrl(), $ssoUrl);
436+
}
437+
438+
/**
439+
* Tests the getIdPSLOurl method of the OneLogin_Saml2_Settings class
440+
*
441+
* @covers OneLogin_Saml2_Settings::getIdPSLOurl
442+
*/
443+
public function testGetIdPSLOurl()
444+
{
445+
$settingsDir = TEST_ROOT .'/settings/';
446+
include $settingsDir.'settings1.php';
447+
448+
$settings = new OneLogin_Saml2_Settings($settingsInfo);
449+
450+
$sloUrl = "http://idp.example.com/SingleLogoutService.php";
451+
$this->assertEquals($settings->getIdPSLOUrl(), $sloUrl);
452+
453+
include $settingsDir.'settings2.php';
454+
$settings2 = new OneLogin_Saml2_Settings($settingsInfo);
455+
456+
$sloUrl = "http://idp.example.com/SingleLogoutService.php";
457+
$this->assertEquals($settings2->getIdPSLOUrl(), $sloUrl);
458+
}
459+
460+
/**
461+
* Tests the getIdPSLOResponseUrl method of the OneLogin_Saml2_Settings class
462+
*
463+
* @covers OneLogin_Saml2_Settings::getIdPSLOResponseUrl
464+
*/
465+
public function testGetIdPSLOResponseUrl()
466+
{
467+
$settingsDir = TEST_ROOT .'/settings/';
468+
include $settingsDir.'settings1.php';
469+
470+
$settings = new OneLogin_Saml2_Settings($settingsInfo);
471+
472+
$sloUrl = "http://idp.example.com/SingleLogoutServiceResponse.php";
473+
$this->assertEquals($settings->getIdPSLOResponseUrl(), $sloUrl);
474+
475+
include $settingsDir.'settings2.php';
476+
$settings2 = new OneLogin_Saml2_Settings($settingsInfo);
477+
478+
$sloUrl = "http://idp.example.com/SingleLogoutService.php";
479+
$this->assertEquals($settings2->getIdPSLOUrl(), $sloUrl);
480+
}
481+
422482
/**
423483
* Tests the getSPMetadata method of the OneLogin_Saml2_Settings
424484
* Case unsigned metadata

0 commit comments

Comments
 (0)