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

SAML2-SP: Add authentication processing filter support.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@816 44740490-163a-0410-bde0-09ae8108e29a
parent c29d45cb
No related branches found
No related tags found
No related merge requests found
...@@ -19,11 +19,50 @@ $config = SimpleSAML_Configuration::getInstance(); ...@@ -19,11 +19,50 @@ $config = SimpleSAML_Configuration::getInstance();
*/ */
$session = SimpleSAML_Session::getInstance(); $session = SimpleSAML_Session::getInstance();
/**
* Finish login operation.
*
* This helper function finishes a login operation and redirects the user back to the page which
* requested the login.
*
* @param array $authProcState The state of the authentication process.
*/
function finishLogin($authProcState) {
assert('is_array($authProcState)');
assert('array_key_exists("Attributes", $authProcState)');
assert('array_key_exists("core:saml20-sp:NameID", $authProcState)');
assert('array_key_exists("core:saml20-sp:SessionIndex", $authProcState)');
assert('array_key_exists("core:saml20-sp:TargetURL", $authProcState)');
assert('array_key_exists("Source", $authProcState)');
assert('array_key_exists("entityid", $authProcState["Source"])');
global $session;
/* Update the session information */
$session->doLogin('saml2');
$session->setAttributes($authProcState['Attributes']);
$session->setNameID($authProcState['core:saml20-sp:NameID']);
$session->setSessionIndex($authProcState['core:saml20-sp:SessionIndex']);
$session->setIdP($authProcState['Source']['entityid']);
SimpleSAML_Utilities::redirect($authProcState['core:saml20-sp:TargetURL']);
}
SimpleSAML_Logger::info('SAML2.0 - SP.AssertionConsumerService: Accessing SAML 2.0 SP endpoint AssertionConsumerService'); SimpleSAML_Logger::info('SAML2.0 - SP.AssertionConsumerService: Accessing SAML 2.0 SP endpoint AssertionConsumerService');
if (!$config->getValue('enable.saml20-sp', false)) if (!$config->getValue('enable.saml20-sp', false))
SimpleSAML_Utilities::fatalError($session->getTrackID(), 'NOACCESS'); SimpleSAML_Utilities::fatalError($session->getTrackID(), 'NOACCESS');
if (array_key_exists(SimpleSAML_Auth_ProcessingChain::AUTHPARAM, $_REQUEST)) {
/* We have returned from the authentication processing filters. */
$authProcId = $_REQUEST[SimpleSAML_Auth_ProcessingChain::AUTHPARAM];
$authProcState = SimpleSAML_Auth_ProcessingChain::fetchProcessedState($authProcId);
finishLogin($authProcState);
}
if (empty($_POST['SAMLResponse'])) if (empty($_POST['SAMLResponse']))
SimpleSAML_Utilities::fatalError($session->getTrackID(), 'ACSPARAMS', $exception); SimpleSAML_Utilities::fatalError($session->getTrackID(), 'ACSPARAMS', $exception);
...@@ -104,18 +143,27 @@ try { ...@@ -104,18 +143,27 @@ try {
SimpleSAML_Logger::info('SAML2.0 - SP.AssertionConsumerService: Completed attribute handling'); SimpleSAML_Logger::info('SAML2.0 - SP.AssertionConsumerService: Completed attribute handling');
/* Update the session information */ /* Begin module attribute processing */
$session->doLogin('saml2');
$session->setAttributes($attributes); $pc = new SimpleSAML_Auth_ProcessingChain($idpmetadata, $spmetadata);
$session->setNameID($authnResponse->getNameID());
$session->setSessionIndex($authnResponse->getSessionIndex()); $authProcState = array(
$session->setIdP($idpentityid); 'core:saml20-sp:NameID' => $authnResponse->getNameID(),
'core:saml20-sp:SessionIndex' => $authnResponse->getSessionIndex(),
'core:saml20-sp:TargetURL' => $info['RelayState'],
'ReturnURL' => SimpleSAML_Utilities::selfURLNoQuery(),
SimpleSAML_Utilities::redirect($info['RelayState']); 'Attributes' => $attributes,
'Destination' => $spmetadata,
'Source' => $idpmetadata,
);
$pc->processState($authProcState);
/* Since this function returns, processing has completed and attributes have
* been updated.
*/
finishLogin($authProcState);
} catch(Exception $exception) { } catch(Exception $exception) {
SimpleSAML_Utilities::fatalError($session->getTrackID(), 'PROCESSASSERTION', $exception); SimpleSAML_Utilities::fatalError($session->getTrackID(), 'PROCESSASSERTION', $exception);
......
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