Skip to content
Snippets Groups Projects
Commit 6d742a2d authored by Olav Morken's avatar Olav Morken
Browse files

idp/SingleLogoutServiceiFrame: Use the new SAML2 library.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1619 44740490-163a-0410-bde0-09ae8108e29a
parent 2bf76272
No related branches found
No related tags found
No related merge requests found
...@@ -24,6 +24,7 @@ if (!$config->getValue('enable.saml20-idp', false)) ...@@ -24,6 +24,7 @@ if (!$config->getValue('enable.saml20-idp', false))
try { try {
$idpentityid = $metadata->getMetaDataCurrentEntityID('saml20-idp-hosted'); $idpentityid = $metadata->getMetaDataCurrentEntityID('saml20-idp-hosted');
$idpMetadata = $metadata->getMetaDataConfig($idpentityid, 'saml20-idp-hosted');
} catch (Exception $exception) { } catch (Exception $exception) {
SimpleSAML_Utilities::fatalError($session->getTrackID(), 'METADATA', $exception); SimpleSAML_Utilities::fatalError($session->getTrackID(), 'METADATA', $exception);
} }
...@@ -173,19 +174,27 @@ $xajax->processRequests(); ...@@ -173,19 +174,27 @@ $xajax->processRequests();
/* /*
* If we get an LogoutRequest then we initiate the logout process. * If we get an LogoutRequest then we initiate the logout process.
*/ */
if (isset($_GET['SAMLRequest'])) { if (isset($_REQUEST['SAMLRequest'])) {
SimpleSAML_Logger::debug('SAML2.0 - IdP.SingleLogoutService: Got SAML reuqest'); SimpleSAML_Logger::debug('SAML2.0 - IdP.SingleLogoutService: Got SAML reuqest');
$binding = new SimpleSAML_Bindings_SAML20_HTTPRedirect($config, $metadata); $binding = SAML2_Binding::getCurrentBinding();
try { try {
$logoutrequest = $binding->decodeLogoutRequest($_GET); $logoutrequest = $binding->receive();
if (!($logoutrequest instanceof SAML2_LogoutRequest)) {
throw new Exception('Not a valid logout request.');
}
if ($binding->validateQuery($logoutrequest->getIssuer(),'IdP')) { $spEntityId = $logoutrequest->getIssuer();
SimpleSAML_Logger::info('SAML2.0 - IdP.SingleLogoutService: Valid signature found for '.$logoutrequest->getRequestID()); if ($spEntityId === NULL) {
throw new Exception('Missing issuer in logout request.');
} }
$spMetadata = $metadata->getMetaDataConfig($spEntityId, 'saml20-sp-remote');
sspmod_saml2_Message::validateMessage($spMetadata, $idpMetadata, $logoutrequest);
} catch(Exception $exception) { } catch(Exception $exception) {
SimpleSAML_Utilities::fatalError($session->getTrackID(), 'LOGOUTREQUEST', $exception); SimpleSAML_Utilities::fatalError($session->getTrackID(), 'LOGOUTREQUEST', $exception);
} }
...@@ -205,7 +214,7 @@ if (isset($_GET['SAMLRequest'])) { ...@@ -205,7 +214,7 @@ if (isset($_GET['SAMLRequest'])) {
/* Fill in the $logoutInfo associative array with information about this logout request. */ /* Fill in the $logoutInfo associative array with information about this logout request. */
$logoutInfo['Issuer'] = $logoutrequest->getIssuer(); $logoutInfo['Issuer'] = $logoutrequest->getIssuer();
$logoutInfo['RequestID'] = $logoutrequest->getRequestID(); $logoutInfo['RequestID'] = $logoutrequest->getId();
$relayState = $logoutrequest->getRelayState(); $relayState = $logoutrequest->getRelayState();
if($relayState !== NULL) { if($relayState !== NULL) {
...@@ -221,7 +230,7 @@ if (isset($_GET['SAMLRequest'])) { ...@@ -221,7 +230,7 @@ if (isset($_GET['SAMLRequest'])) {
* We receive a Logout Response to a Logout Request that we have issued earlier. * We receive a Logout Response to a Logout Request that we have issued earlier.
* If so, there is a misconfiguration. * If so, there is a misconfiguration.
*/ */
} elseif (isset($_GET['SAMLResponse'])) { } elseif (isset($_REQUEST['SAMLResponse'])) {
SimpleSAML_Utilities::fatalError($session->getTrackID(), 'LOGOUTRESPONSE', SimpleSAML_Utilities::fatalError($session->getTrackID(), 'LOGOUTRESPONSE',
new Exception('The SP is likely to be misconfigured. The LogoutResponse is sent to wrong endpoint. This iFrame endpoint only accepts LogoutRequests, and the response is to be sent to a separate endpoint. Please revisit the IdP-Remote metadata on the SP.') new Exception('The SP is likely to be misconfigured. The LogoutResponse is sent to wrong endpoint. This iFrame endpoint only accepts LogoutRequests, and the response is to be sent to a separate endpoint. Please revisit the IdP-Remote metadata on the SP.')
...@@ -256,24 +265,25 @@ foreach ($listofsps AS $spentityid) { ...@@ -256,24 +265,25 @@ foreach ($listofsps AS $spentityid) {
$nameId = $session->getNameID(); $nameId = $session->getNameID();
} }
/* Convert to new-style NameId format. */
$nameId['Value'] = $nameId['value'];
unset($nameId['value']);
$spmetadata = $metadata->getMetaData($spentityid, 'saml20-sp-remote'); $spMetadata = $metadata->getMetaDataConfig($spentityid, 'saml20-sp-remote');
$name = array_key_exists('name', $spmetadata) ? $spmetadata['name'] : $spentityid; $name = $spMetadata->getValue('name', $spentityid);
try { try {
$lr = new SimpleSAML_XML_SAML20_LogoutRequest($config, $metadata); $lr = sspmod_saml2_Message::buildLogoutRequest($idpMetadata, $spMetadata);
$req = $lr->generate($idpentityid, $spentityid, $nameId, $session->getSessionIndex(), 'IdP'); $lr->setSessionIndex($session->getSessionIndex());
$httpredirect = new SimpleSAML_Bindings_SAML20_HTTPRedirect($config, $metadata); $lr->setNameId($nameId);
// $request, $localentityid, $remoteentityid, $relayState = null, $endpoint = 'SingleSignOnService', $direction = 'SAMLRequest', $mode = 'SP'
$url = $httpredirect->getRedirectURL($req, $idpentityid, $spentityid, NULL, 'SingleLogoutService', 'SAMLRequest', 'IdP'); $httpredirect = new SAML2_HTTPRedirect();
$url = $httpredirect->getRedirectURL($lr);
$sparray[$spentityid] = array('url' => $url, 'name' => $name); $sparray[$spentityid] = array('url' => $url, 'name' => $name);
} catch (Exception $e) { } catch (Exception $e) {
$sparrayNoLogout[$spentityid] = array('name' => $name); $sparrayNoLogout[$spentityid] = array('name' => $name);
} }
} }
...@@ -302,30 +312,27 @@ try { ...@@ -302,30 +312,27 @@ try {
* Check if the Single Logout procedure is initated by an SP (alternatively IdP initiated SLO) * Check if the Single Logout procedure is initated by an SP (alternatively IdP initiated SLO)
*/ */
if (array_key_exists('Issuer', $logoutInfo)) { if (array_key_exists('Issuer', $logoutInfo)) {
/** $spMetadata = $metadata->getMetaDataConfig($logoutInfo['Issuer'], 'saml20-sp-remote');
* Create a Logot Response.
*/
$rg = new SimpleSAML_XML_SAML20_LogoutResponse($config, $metadata);
// generate($issuer, $receiver, $inresponseto, $mode )
$logoutResponseXML = $rg->generate($idpentityid, $logoutInfo['Issuer'], $logoutInfo['RequestID'], 'IdP');
// Create a HTTP-REDIRECT Binding.
$httpredirect = new SimpleSAML_Bindings_SAML20_HTTPRedirect($config, $metadata);
// Find the relaystate if cached. // Find the relaystate if cached.
$relayState = isset($logoutInfo['RelayState']) ? $logoutInfo['RelayState'] : null; $relayState = isset($logoutInfo['RelayState']) ? $logoutInfo['RelayState'] : null;
$logoutresponse = NULL; /* Create a Logout Response. */
$rg = sspmod_saml2_Message::buildLogoutResponse($idpMetadata, $spMetadata);
$rg->setInResponseTo($logoutInfo['RequestID']);
$rg->setRelayState($relayState);
$httpredirect = new SAML2_HTTPRedirect();
/* /*
* If the user is not logged into any other SPs, send the LogoutResponse immediately * If the user is not logged into any other SPs, send the LogoutResponse immediately
*/ */
if (count($sparray) === 0) { if (count($sparray) === 0) {
$httpredirect->sendMessage($logoutResponseXML, $idpentityid, $logoutInfo['Issuer'], $relayState, 'SingleLogoutService', 'SAMLResponse', 'IdP'); $httpredirect->setDestination(sspmod_SAML2_Message::getDebugDestination());
exit; $httpredirect->send($rg);
} else { } else {
$logoutresponse = $httpredirect->getRedirectURL($logoutResponseXML, $idpentityid, $logoutInfo['Issuer'], $relayState, 'SingleLogoutService', 'SAMLResponse', 'IdP'); $logoutresponse = $httpredirect->getRedirectURL($rg);
} }
......
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