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

SAML2_Assertion: Use the new SubjectConfirmation class.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@2552 44740490-163a-0410-bde0-09ae8108e29a
parent b0f7d641
No related branches found
No related tags found
No related merge requests found
...@@ -287,41 +287,34 @@ class SAML2_Assertion implements SAML2_SignedElement { ...@@ -287,41 +287,34 @@ class SAML2_Assertion implements SAML2_SignedElement {
throw new Exception('More than one <saml:SubjectConfirmation> in <saml:Subject>.'); throw new Exception('More than one <saml:SubjectConfirmation> in <saml:Subject>.');
} }
$subjectConfirmation = $subjectConfirmation[0]; $subjectConfirmation = $subjectConfirmation[0];
$subjectConfirmation = new SAML2_XML_saml_SubjectConfirmation($subjectConfirmation);
if (!$subjectConfirmation->hasAttribute('Method')) { if ($subjectConfirmation->Method !== SAML2_Const::CM_BEARER) {
throw new Exception('Missing required attribute "Method" on <saml:SubjectConfirmation>-node.');
}
$method = $subjectConfirmation->getAttribute('Method');
if ($method !== SAML2_Const::CM_BEARER) {
throw new Exception('Unsupported subject confirmation method: ' . var_export($method, TRUE)); throw new Exception('Unsupported subject confirmation method: ' . var_export($method, TRUE));
} }
$confirmationData = SAML2_Utils::xpQuery($subjectConfirmation, './saml_assertion:SubjectConfirmationData'); $confirmationData = $subjectConfirmation->SubjectConfirmationData;
if (empty($confirmationData)) { if ($confirmationData === NULL) {
return; return;
} elseif (count($confirmationData) > 1) {
throw new Exception('More than one <saml:SubjectConfirmationData> in <saml:SubjectConfirmation> is currently unsupported.');
} }
$confirmationData = $confirmationData[0];
if ($confirmationData->hasAttribute('NotBefore')) { if ($confirmationData->NotBefore !== NULL) {
$notBefore = SimpleSAML_Utilities::parseSAML2Time($confirmationData->getAttribute('NotBefore')); $notBefore = $confirmationData->NotBefore;
if ($this->notBefore === NULL || $this->notBefore < $notBefore) { if ($this->notBefore === NULL || $this->notBefore < $notBefore) {
$this->notBefore = $notBefore; $this->notBefore = $notBefore;
} }
} }
if ($confirmationData->hasAttribute('NotOnOrAfter')) { if ($confirmationData->NotOnOrAfter !== NULL) {
$notOnOrAfter = SimpleSAML_Utilities::parseSAML2Time($confirmationData->getAttribute('NotOnOrAfter')); $notOnOrAfter = $confirmationData->NotOnOrAfter;
if ($this->notOnOrAfter === NULL || $this->notOnOrAfter > $notOnOrAfter) { if ($this->notOnOrAfter === NULL || $this->notOnOrAfter > $notOnOrAfter) {
$this->notOnOrAfter = $notOnOrAfter; $this->notOnOrAfter = $notOnOrAfter;
} }
} }
if ($confirmationData->hasAttribute('InResponseTo')) { if ($confirmationData->InResponseTo !== NULL) {
$this->inResponseTo = $confirmationData->getAttribute('InResponseTo');; $this->inResponseTo = $confirmationData->InResponseTo;
} }
if ($confirmationData->hasAttribute('Recipient')) { if ($confirmationData->Recipient !== NULL) {
$this->destination = $confirmationData->getAttribute('Recipient');; $this->destination = $confirmationData->Recipient;
} }
} }
...@@ -1166,23 +1159,22 @@ class SAML2_Assertion implements SAML2_SignedElement { ...@@ -1166,23 +1159,22 @@ class SAML2_Assertion implements SAML2_SignedElement {
SAML2_Utils::addNameId($subject, $this->nameId); SAML2_Utils::addNameId($subject, $this->nameId);
$sc = $root->ownerDocument->createElementNS(SAML2_Const::NS_SAML, 'saml:SubjectConfirmation'); $sc = new SAML2_XML_saml_SubjectConfirmation();
$subject->appendChild($sc); $sc->Method = SAML2_Const::CM_BEARER;
$sc->SubjectConfirmationData = new SAML2_XML_saml_SubjectConfirmationData();
$sc->setAttribute('Method', SAML2_Const::CM_BEARER); $sc->SubjectConfirmationData->Recipient = $this->destination;
$scd = $root->ownerDocument->createElementNS(SAML2_Const::NS_SAML, 'saml:SubjectConfirmationData');
$sc->appendChild($scd);
if ($this->notOnOrAfter !== NULL) { if ($this->notOnOrAfter !== NULL) {
$scd->setAttribute('NotOnOrAfter', gmdate('Y-m-d\TH:i:s\Z', $this->notOnOrAfter)); $sc->SubjectConfirmationData->NotOnOrAfter = $this->notOnOrAfter;
} }
if ($this->destination !== NULL) { if ($this->destination !== NULL) {
$scd->setAttribute('Recipient', $this->destination); $sc->SubjectConfirmationData->Recipient = $this->destination;
} }
if ($this->inResponseTo !== NULL) { if ($this->inResponseTo !== NULL) {
$scd->setAttribute('InResponseTo', $this->inResponseTo); $sc->SubjectConfirmationData->InResponseTo = $this->inResponseTo;
} }
$sc->toXML($subject);
} }
......
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