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

SimpleSAML_XML_Shib13_AuthnResponse: Various cleanups.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1699 44740490-163a-0410-bde0-09ae8108e29a
parent 373a6850
No related branches found
No related tags found
No related merge requests found
...@@ -19,17 +19,29 @@ class SimpleSAML_XML_Shib13_AuthnResponse { ...@@ -19,17 +19,29 @@ class SimpleSAML_XML_Shib13_AuthnResponse {
const SHIB_ASSERT_NS = 'urn:oasis:names:tc:SAML:1.0:assertion'; const SHIB_ASSERT_NS = 'urn:oasis:names:tc:SAML:1.0:assertion';
private $message = null; /**
* The DOMDocument which represents this message.
*
* @var DOMDocument
*/
private $dom; private $dom;
/**
* The relaystate which is associated with this response.
*
* @var string|NULL
*/
private $relayState = null; private $relayState = null;
public function setXML($xml) { public function setXML($xml) {
$this->message = $xml; assert('is_string($xml)');
}
public function getXML() { $this->dom = new DOMDocument();
return $this->message; $ok = $this->dom->loadXML(str_replace ("\r", "", $xml));
if (!$ok) {
throw new Exception('Unable to parse AuthnResponse XML.');
}
} }
public function setRelayState($relayState) { public function setRelayState($relayState) {
...@@ -40,36 +52,11 @@ class SimpleSAML_XML_Shib13_AuthnResponse { ...@@ -40,36 +52,11 @@ class SimpleSAML_XML_Shib13_AuthnResponse {
return $this->relayState; return $this->relayState;
} }
public function getDOM() {
if (isset($this->message) ) {
if (isset($this->dom)) {
return $this->dom;
}
$token = new DOMDocument();
$token->loadXML(str_replace ("\r", "", $this->message));
if (empty($token)) {
throw new Exception("Unable to load token");
}
$this->dom = $token;
return $this->dom;
}
return null;
}
function __construct() {
}
public function validate() { public function validate() {
assert('$this->dom instanceof DOMDocument');
$dom = $this->getDOM();
/* Validate the signature. */ /* Validate the signature. */
$this->validator = new SimpleSAML_XML_Validator($dom, array('ResponseID', 'AssertionID')); $this->validator = new SimpleSAML_XML_Validator($this->dom, array('ResponseID', 'AssertionID'));
// Get the issuer of the response. // Get the issuer of the response.
$issuer = $this->getIssuer(); $issuer = $this->getIssuer();
...@@ -127,40 +114,35 @@ class SimpleSAML_XML_Shib13_AuthnResponse { ...@@ -127,40 +114,35 @@ class SimpleSAML_XML_Shib13_AuthnResponse {
*/ */
private function doXPathQuery($query, $node = NULL) { private function doXPathQuery($query, $node = NULL) {
assert('is_string($query)'); assert('is_string($query)');
assert('$this->dom instanceof DOMDocument');
$dom = $this->getDOM();
assert('$dom instanceof DOMDocument');
if($node === NULL) { if($node === NULL) {
$node = $dom->documentElement; $node = $this->dom->documentElement;
} }
assert('$node instanceof DOMNode'); assert('$node instanceof DOMNode');
$xPath = new DOMXpath($dom); $xPath = new DOMXpath($this->dom);
$xPath->registerNamespace('shibp', self::SHIB_PROTOCOL_NS); $xPath->registerNamespace('shibp', self::SHIB_PROTOCOL_NS);
$xPath->registerNamespace('shib', self::SHIB_ASSERT_NS); $xPath->registerNamespace('shib', self::SHIB_ASSERT_NS);
return $xPath->query($query, $node); return $xPath->query($query, $node);
} }
/* This function is only included because it is in the base class. Will be removed in the future. */ /**
public function createSession() { throw new Exception('Removed');} * Retrieve the session index of this response.
*
//TODO * @return string|NULL The session index of this response.
*/
function getSessionIndex() { function getSessionIndex() {
$token = $this->getDOM(); assert('$this->dom instanceof DOMDocument');
if ($token instanceof DOMDocument) {
$xPath = new DOMXpath($token); $query = '/shibp:Response/shib:Assertion/shib:AuthnStatement';
$xPath->registerNamespace('mysamlp', self::SHIB_PROTOCOL_NS); $nodelist = $this->doXPathQuery($query);
$xPath->registerNamespace('mysaml', self::SHIB_ASSERT_NS); if ($node = $nodelist->item(0)) {
return $node->getAttribute('SessionIndex');
$query = '/mysamlp:Response/mysaml:Assertion/mysaml:AuthnStatement';
$nodelist = $xPath->query($query);
if ($node = $nodelist->item(0)) {
return $node->getAttribute('SessionIndex');
}
} }
return NULL; return NULL;
} }
...@@ -171,7 +153,7 @@ class SimpleSAML_XML_Shib13_AuthnResponse { ...@@ -171,7 +153,7 @@ class SimpleSAML_XML_Shib13_AuthnResponse {
$md = $metadata->getMetadata($this->getIssuer(), 'shib13-idp-remote'); $md = $metadata->getMetadata($this->getIssuer(), 'shib13-idp-remote');
$base64 = isset($md['base64attributes']) ? $md['base64attributes'] : false; $base64 = isset($md['base64attributes']) ? $md['base64attributes'] : false;
if (! ($this->getDOM() instanceof DOMDocument) ) { if (! ($this->dom instanceof DOMDocument) ) {
return array(); return array();
} }
...@@ -236,14 +218,9 @@ class SimpleSAML_XML_Shib13_AuthnResponse { ...@@ -236,14 +218,9 @@ class SimpleSAML_XML_Shib13_AuthnResponse {
public function getIssuer() { public function getIssuer() {
$token = $this->getDOM();
$xPath = new DOMXpath($token);
$xPath->registerNamespace('mysamlp', self::SHIB_PROTOCOL_NS);
$xPath->registerNamespace('mysaml', self::SHIB_ASSERT_NS);
$query = '/mysamlp:Response/mysaml:Assertion/@Issuer'; $query = '/shibp:Response/shib:Assertion/@Issuer';
$nodelist = $xPath->query($query); $nodelist = $this->doXPathQuery($query);
if ($attr = $nodelist->item(0)) { if ($attr = $nodelist->item(0)) {
return $attr->value; return $attr->value;
...@@ -252,26 +229,20 @@ class SimpleSAML_XML_Shib13_AuthnResponse { ...@@ -252,26 +229,20 @@ class SimpleSAML_XML_Shib13_AuthnResponse {
} }
} }
public function getNameID() { public function getNameID() {
$token = $this->getDOM();
$nameID = array(); $nameID = array();
if ($token instanceof DOMDocument) {
$xPath = new DOMXpath($token); $query = '/shibp:Response/shib:Assertion/shib:AuthenticationStatement/shib:Subject/shib:NameIdentifier';
$xPath->registerNamespace('mysamlp', self::SHIB_PROTOCOL_NS); $nodelist = $this->doXPathQuery($query);
$xPath->registerNamespace('mysaml', self::SHIB_ASSERT_NS);
if ($node = $nodelist->item(0)) {
$query = '/mysamlp:Response/mysaml:Assertion/mysaml:AuthenticationStatement/mysaml:Subject/mysaml:NameIdentifier'; $nameID["Value"] = $node->nodeValue;
$nodelist = $xPath->query($query); $nameID["Format"] = $node->getAttribute('Format');
if ($node = $nodelist->item(0)) {
$nameID["Value"] = $node->nodeValue;
$nameID["Format"] = $node->getAttribute('Format');
//$nameID["NameQualifier"] = $node->getAttribute('NameQualifier');
}
} }
return $nameID;
return $nameID;
} }
......
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