diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php index 168e8648f5f95e262133e79dac70c310c132224e..9d9667e730c164a1edb7267d96e351aa9d7309eb 100644 --- a/lib/SimpleSAML/Utilities.php +++ b/lib/SimpleSAML/Utilities.php @@ -1742,6 +1742,28 @@ class SimpleSAML_Utilities { } } + + /** + * Do a POST redirect to a page. + * + * This function never returns. + * + * @param string $destination The destination URL. + * @param array $post An array of name-value pairs which will be posted. + */ + public static function postRedirect($destination, $post) { + assert('is_string($destination)'); + assert('is_array($post)'); + + $config = SimpleSAML_Configuration::getInstance(); + + $p = new SimpleSAML_XHTML_Template($config, 'post.php'); + $p->data['destination'] = $destination; + $p->data['post'] = $post; + $p->show(); + exit(0); + } + } ?> \ No newline at end of file diff --git a/templates/post.php b/templates/post.php index 9512b0f745a182f298a65b5bb237e9b0a4aae69c..d3378955693c86f889d4ab3c0058c6205bc167b7 100644 --- a/templates/post.php +++ b/templates/post.php @@ -3,7 +3,7 @@ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> - <title>SAML 2.0 POST</title> + <title>POST data</title> </head> <body onload="document.forms[0].submit()"> @@ -12,11 +12,53 @@ </noscript> <form method="post" action="<?php echo htmlspecialchars($this->data['destination']); ?>"> - <input type="hidden" name="SAMLResponse" value="<?php echo htmlspecialchars($this->data['response']); ?>" /> - <input type="hidden" name="<?php echo htmlspecialchars($this->data['RelayStateName']); ?>" value="<?php echo htmlspecialchars($this->data['RelayState']); ?>" /> - +<?php +if (array_key_exists('post', $this->data)) { + $post = $this->data['post']; +} else { + /* For backwards compatibility. */ + assert('array_key_exists("response", $this->data)'); + assert('array_key_exists("RelayStateName", $this->data)'); + assert('array_key_exists("RelayState", $this->data)'); + + $post = array( + 'SAMLResponse' => $this->data['response'], + $this->data['RelayStateName'] => $this->data['RelayState'], + ); +} + +/** + * Write out one or more INPUT elements for the given name-value pair. + * + * If the value is a string, this function will write a single INPUT element. + * If the value is an array, it will write multiple INPUT elements to + * recreate the array. + * + * @param string $name The name of the element. + * @param string|array $value The value of the element. + */ +function printItem($name, $value) { + assert('is_string($name)'); + assert('is_string($value) || is_array($value)'); + + if (is_string($value)) { + echo '<input type="hidden" name="' . htmlspecialchars($name) . '" value="' . htmlspecialchars($value) . '" />'; + return; + } + + /* This is an array... */ + foreach ($value as $index => $item) { + printItem($name . '[' . var_export($index, TRUE) . ']', $item); + } +} + +foreach ($post as $name => $value) { + printItem($name, $value); +} +?> + <noscript> - <input type="submit" value="Submit the response to the service" /> + <input type="submit" value="Submit" /> </noscript> </form>