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

SAML2_Utils: Add the new addString()-function.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@2200 44740490-163a-0410-bde0-09ae8108e29a
parent 9df140ba
No related branches found
No related tags found
No related merge requests found
...@@ -995,9 +995,7 @@ class SAML2_Assertion implements SAML2_SignedElement { ...@@ -995,9 +995,7 @@ class SAML2_Assertion implements SAML2_SignedElement {
$root->setAttribute('Version', '2.0'); $root->setAttribute('Version', '2.0');
$root->setAttribute('IssueInstant', gmdate('Y-m-d\TH:i:s\Z', $this->issueInstant)); $root->setAttribute('IssueInstant', gmdate('Y-m-d\TH:i:s\Z', $this->issueInstant));
$issuer = $document->createElementNS(SAML2_Const::NS_SAML, 'saml:Issuer'); $issuer = SAML2_Utils::addString($root, SAML2_Const::NS_SAML, 'saml:Issuer', $this->issuer);
$issuer->appendChild($document->createTextNode($this->issuer));
$root->appendChild($issuer);
$this->addSubject($root); $this->addSubject($root);
$this->addConditions($root); $this->addConditions($root);
...@@ -1111,10 +1109,7 @@ class SAML2_Assertion implements SAML2_SignedElement { ...@@ -1111,10 +1109,7 @@ class SAML2_Assertion implements SAML2_SignedElement {
$ac = $document->createElementNS(SAML2_Const::NS_SAML, 'saml:AuthnContext'); $ac = $document->createElementNS(SAML2_Const::NS_SAML, 'saml:AuthnContext');
$as->appendChild($ac); $as->appendChild($ac);
$accr = $document->createElementNS(SAML2_Const::NS_SAML, 'saml:AuthnContextClassRef'); SAML2_Utils::addString($ac, SAML2_Const::NS_SAML, 'saml:AuthnContextClassRef', $this->authnContext);
$ac->appendChild($accr);
$accr->appendChild($document->createTextNode($this->authnContext));
} }
......
...@@ -162,12 +162,10 @@ class SAML2_AttributeQuery extends SAML2_SubjectQuery { ...@@ -162,12 +162,10 @@ class SAML2_AttributeQuery extends SAML2_SubjectQuery {
$type = NULL; $type = NULL;
} }
$attributeValue = $root->ownerDocument->createElementNS(SAML2_Const::NS_SAML, 'saml:AttributeValue'); $attributeValue = SAML2_Utils::addString($attribute, SAML2_Const::NS_SAML, 'saml:AttributeValue', $value);
$attribute->appendChild($attributeValue);
if ($type !== NULL) { if ($type !== NULL) {
$attributeValue->setAttributeNS(SAML2_Const::NS_XSI, 'xsi:type', $type); $attributeValue->setAttributeNS(SAML2_Const::NS_XSI, 'xsi:type', $type);
} }
$attributeValue->appendChild($root->ownerDocument->createTextNode($value));
} }
} }
......
...@@ -348,9 +348,7 @@ class SAML2_AuthnRequest extends SAML2_Request { ...@@ -348,9 +348,7 @@ class SAML2_AuthnRequest extends SAML2_Request {
$e->setAttribute('Comparison', $rac['Comparison']); $e->setAttribute('Comparison', $rac['Comparison']);
} }
foreach ($rac['AuthnContextClassRef'] as $accr) { foreach ($rac['AuthnContextClassRef'] as $accr) {
$i = $this->document->createElementNS(SAML2_Const::NS_SAML, 'AuthnContextClassRef'); SAML2_Utils::addString($e, SAML2_Const::NS_SAML, 'AuthnContextClassRef', $accr);
$i->appendChild($this->document->createTextNode($accr));
$e->appendChild($i);
} }
} }
......
...@@ -109,9 +109,7 @@ class SAML2_LogoutRequest extends SAML2_Request { ...@@ -109,9 +109,7 @@ class SAML2_LogoutRequest extends SAML2_Request {
SAML2_Utils::addNameId($root, $this->nameId); SAML2_Utils::addNameId($root, $this->nameId);
if ($this->sessionIndex !== NULL) { if ($this->sessionIndex !== NULL) {
$sessionIndex = $this->document->createElementNS(SAML2_Const::NS_SAMLP, 'SessionIndex'); SAML2_Utils::addString($root, SAML2_Const::NS_SAMLP, 'SessionIndex', $this->sessionIndex);
$sessionIndex->appendChild($this->document->createTextNode($this->sessionIndex));
$root->appendChild($sessionIndex);
} }
return $root; return $root;
......
...@@ -357,9 +357,7 @@ abstract class SAML2_Message implements SAML2_SignedElement { ...@@ -357,9 +357,7 @@ abstract class SAML2_Message implements SAML2_SignedElement {
} }
if ($this->issuer !== NULL) { if ($this->issuer !== NULL) {
$issuer = $this->document->createElementNS(SAML2_Const::NS_SAML, 'saml:Issuer'); SAML2_Utils::addString($root, SAML2_Const::NS_SAML, 'saml:Issuer', $this->issuer);
$issuer->appendChild($this->document->createTextNode($this->issuer));
$root->appendChild($issuer);
} }
return $root; return $root;
......
...@@ -181,9 +181,7 @@ abstract class SAML2_StatusResponse extends SAML2_Message { ...@@ -181,9 +181,7 @@ abstract class SAML2_StatusResponse extends SAML2_Message {
} }
if (!is_null($this->status['Message'])) { if (!is_null($this->status['Message'])) {
$statusMessage = $this->document->createElementNS(SAML2_Const::NS_SAMLP, 'StatusMessage'); SAML2_Utils::addString($status, SAML2_Const::NS_SAMLP, 'StatusMessage', $this->status['Message']);
$statusMessage->appendChild($this->document->createTextNode($this->status['Message']));
$status->appendChild($statusMessage);
} }
return $root; return $root;
......
...@@ -175,8 +175,7 @@ class SAML2_Utils { ...@@ -175,8 +175,7 @@ class SAML2_Utils {
public static function addNameId(DOMElement $node, array $nameId) { public static function addNameId(DOMElement $node, array $nameId) {
assert('array_key_exists("Value", $nameId)'); assert('array_key_exists("Value", $nameId)');
$xml = $node->ownerDocument->createElementNS(SAML2_Const::NS_SAML, 'saml:NameID'); $xml = SAML2_Utils::addString($node, SAML2_Const::NS_SAML, 'saml:NameID', $nameId['Value']);
$node->appendChild($xml);
if (array_key_exists('NameQualifier', $nameId) && $nameId['NameQualifier'] !== NULL) { if (array_key_exists('NameQualifier', $nameId) && $nameId['NameQualifier'] !== NULL) {
$xml->setAttribute('NameQualifier', $nameId['NameQualifier']); $xml->setAttribute('NameQualifier', $nameId['NameQualifier']);
...@@ -187,8 +186,6 @@ class SAML2_Utils { ...@@ -187,8 +186,6 @@ class SAML2_Utils {
if (array_key_exists('Format', $nameId) && $nameId['Format'] !== NULL) { if (array_key_exists('Format', $nameId) && $nameId['Format'] !== NULL) {
$xml->setAttribute('Format', $nameId['Format']); $xml->setAttribute('Format', $nameId['Format']);
} }
$xml->appendChild($node->ownerDocument->createTextNode($nameId['Value']));
} }
...@@ -367,4 +364,28 @@ class SAML2_Utils { ...@@ -367,4 +364,28 @@ class SAML2_Utils {
return $ret; return $ret;
} }
/**
* Append string element.
*
* @param DOMElement $parent The parent element we should append the new nodes to.
* @param string $namespace The namespace of the created element.
* @param string $name The name of the created element.
* @param string $value The value of the element.
* @return DOMElement The generated element.
*/
public static function addString(DOMElement $parent, $namespace, $name, $value) {
assert('is_string($namespace)');
assert('is_string($name)');
assert('is_string($value)');
$doc = $parent->ownerDocument;
$n = $doc->createElementNS($namespace, $name);
$n->appendChild($doc->createTextNode($value));
$parent->appendChild($n);
return $n;
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment