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

Utilities: Add generic post redirect function.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1546 44740490-163a-0410-bde0-09ae8108e29a
parent d5395774
No related branches found
No related tags found
No related merge requests found
......@@ -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
......@@ -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>
......
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