Skip to content

Commit

Permalink
Merge pull request #269 from silinternational/feature/throw-exception
Browse files Browse the repository at this point in the history
throw exception if SP entityID can't be found in the state
  • Loading branch information
briskt authored Jul 22, 2024
2 parents 2fab743 + 11f5138 commit dc91be4
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions modules/sildisco/src/IdPDisco.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
use Sil\SspUtils\DiscoUtils;
use Sil\SspUtils\Metadata;
use SimpleSAML\Auth;
use SimpleSAML\Error\NoState;
use SimpleSAML\Logger;
use SimpleSAML\Utils\HTTP;
use SimpleSAML\XHTML\IdPDisco as SSPIdPDisco;
use SimpleSAML\XHTML\Template;
use yii\db\Exception;

/**
* This class implements a custom IdP discovery service, for use with a ssp hub (proxy)
Expand Down Expand Up @@ -39,6 +41,10 @@ private function getMetadataPath()
return __DIR__ . '/../../../metadata/';
}

/**
* @throws NoState
* @throws Exception
*/
private function getSPEntityIDAndReducedIdpList(): array
{

Expand All @@ -50,18 +56,23 @@ private function getSPEntityIDAndReducedIdpList(): array
// Before the SimpleSAMLphp 2 upgrade, we added it to the state ourselves by overriding the SAML2.php file
parse_str(parse_url($_GET['return'], PHP_URL_QUERY), $returnState);
$state = Auth\State::loadState($returnState['AuthID'], 'saml:sp:sso');
assert($state && array_key_exists('SPMetadata', $state));
if (!array_key_exists('SPMetadata', $state)) {
throw new Exception('SPMetadata not found in state');
}

$spmd = $state['SPMetadata'];
$spEntityId = $spmd['entityid'];

if (!empty($spEntityId)) {
$idpList = DiscoUtils::getReducedIdpList(
$idpList,
$this->getMetadataPath(),
$spEntityId
);
if (empty($spEntityId)) {
throw new Exception('empty SP entityID');
}

$idpList = DiscoUtils::getReducedIdpList(
$idpList,
$this->getMetadataPath(),
$spEntityId
);


return array($spEntityId, $idpList);
}

Expand Down

0 comments on commit dc91be4

Please sign in to comment.