Skip to content
Snippets Groups Projects
Commit 1bfe2504 authored by Andreas Åkre Solberg's avatar Andreas Åkre Solberg
Browse files

Support attribute presentation hook at example pages. (Used in Feide for...

Support attribute presentation hook at example pages. (Used in Feide for orgunit presentation) (Contribution: thomas graff)

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1143 44740490-163a-0410-bde0-09ae8108e29a
parent 803cd3c5
No related branches found
No related tags found
No related merge requests found
......@@ -8,61 +8,95 @@ if(array_key_exists('header', $this->data)) {
$this->includeAtTemplateBase('includes/header.php');
?>
<h2><?php if (isset($this->data['header'])) { echo($this->data['header']); } else { echo($this->t('{status:some_error_occured}')); } ?></h2>
<p><?php echo($this->t('{status:intro}')); ?></p>
<h2><?php if (isset($this->data['header'])) { echo($this->data['header']); } else { echo($this->t('{status:some_error_occured}')); } ?></h2>
<p><?php echo($this->t('{status:intro}')); ?></p>
<p><?php echo($this->t('{status:validfor}', array('%SECONDS%' => $this->data['remaining']))); ?></p>
<?php
if(isset($this->data['sessionsize'])) {
echo('<p>' . $this->t('{status:sessionsize}', array('%SIZE%' => $this->data['sessionsize'])) . '</p>');
<p><?php echo($this->t('{status:validfor}', array('%SECONDS%' => $this->data['remaining']))); ?></p>
<?php
if(isset($this->data['sessionsize'])) {
echo('<p>' . $this->t('{status:sessionsize}', array('%SIZE%' => $this->data['sessionsize'])) . '</p>');
}
?>
<h2><?php echo($this->t('{status:attributes_header}')); ?></h2>
<?php
// consent style listng start
$attributes = $this->data['attributes'];
function present_list($attr) {
if (is_array($attr) && count($attr) > 1) {
$str = '<ul><li>' . join('</li><li>', $attr) . '</li></ul>';
return $str;
} else {
return htmlspecialchars($attr[0]);
}
?>
}
function present_assoc($attr) {
if (is_array($attr)) {
$str = '<dl>';
foreach ($attr AS $key => $value) {
$str .= "\n" . '<dt>' . htmlspecialchars($key) . '</dt><dd>' . present_list($value) . '</dd>';
}
$str .= '</dl>';
return $str;
} else {
return htmlspecialchars($attr);
}
}
function present_attributes($t, $attributes, $nameParent) {
$alternate = array('odd', 'even'); $i = 0;
<h2><?php echo($this->t('{status:attributes_header}')); ?></h2>
$parentStr = (strlen($nameParent) > 0)? strtolower($nameParent) . '_': '';
$str = (strlen($nameParent) > 0)? '<table class="attributes">': '<table id="table_with_attributes" class="attributes">';
foreach ($attributes as $name => $value) {
<table width="100%" class="attributes">
<?php
$nameraw = $name;
$nameTag = '{attributes:attribute_' . $parentStr . str_replace(":", "_", strtolower($name) ) . '}';
if ($t->getTag($nameTag) !== NULL) {
$name = $t->t($nameTag);
}
$attributes = $this->data['attributes'];
foreach ($attributes AS $name => $value) {
$txtname = '<code style="color: blue">' . $name . '</code>';
if ($this->getTag('attribute_' . htmlspecialchars(strtolower($name))) !== NULL) {
$txtname = $this->t('attribute_' . htmlspecialchars(strtolower($name))) . '<br /><code style="color: blue">' . $name . '</code>';
if (preg_match('/^child_/', $nameraw)) {
$parentName = preg_replace('/^child_/', '', $nameraw);
foreach($value AS $child) {
$str .= '<tr class="odd"><td colspan="2" style="padding: 2em">' . present_attributes($t, $child, $parentName) . '</td></tr>';
}
} else {
if (sizeof($value) > 1) {
echo '<tr><td>' . $txtname . '</td><td><ul>' . "\n";
foreach ($value AS $v) {
if (in_array($name, array('jpegPhoto'))) {
echo '<li><img src="data:image/jpeg;base64,' . htmlspecialchars($v) . '" /></li>' . "\n";
$str .= '<tr class="' . $alternate[($i++ % 2)] . '"><td class="attrname">' . htmlspecialchars($name) . '</td><td class="attrvalue"><ul>';
foreach ($value AS $listitem) {
if ($nameraw === 'jpegPhoto') {
$str .= '<li><img src="data:image/jpeg;base64,' . $listitem . '" /></li>';
} else {
echo '<li>' . htmlspecialchars($v) . '</li>' . "\n";
$str .= '<li>' . present_assoc($listitem) . '</li>';
}
}
echo '</ul></td></tr>';
} else {
if (in_array($name, array('jpegPhoto'))) {
echo '<tr><td>' . $txtname . '</td><td><img src="data:image/jpeg;base64,' . htmlspecialchars($value[0]) . '" /></td></tr>' . "\n";
$str .= '</ul></td></tr>';
} elseif(isset($value[0])) {
$str .= '<tr class="' . $alternate[($i++ % 2)] . '"><td class="attrname">' . htmlspecialchars($name) . '</td>';
if ($nameraw === 'jpegPhoto') {
$str .= '<td class="attrvalue"><img src="data:image/jpeg;base64,' . htmlspecialchars($value[0]) . '" /></td></tr>';
} else {
echo '<tr><td>' . $txtname . '</td><td>' . htmlspecialchars($value[0]) . '</td></tr>' . "\n";
$str .= '<td class="attrvalue">' . htmlspecialchars($value[0]) . '</td></tr>';
}
}
}
?>
</table>
$str .= "\n";
}
$str .= '</table>';
return $str;
}
echo(present_attributes($this, $attributes, ''));
// consent style listing end
<?php
if (isset($this->data['logout'])) {
echo('<h2>' . $this->t('{status:logout}') . '</h2>');
echo('<p>' . $this->data['logout'] . '</p>');
......
......@@ -47,7 +47,14 @@ if (!$session->isValid('saml2') ) {
);
}
/* Prepare attributes for presentation
* and call a hook function for organizing the attribute array
*/
$attributes = $session->getAttributes();
$para = array(
'attributes' => &$attributes
);
SimpleSAML_Module::callHooks('attributepresentation', $para);
/*
* The attributes variable now contains all the attributes. So this variable is basicly all you need to perform integration in
......
......@@ -6,6 +6,17 @@
*/
require_once('../_include.php');
/*
* Explisit instruct consent page to send no-cache header to browsers
* to make sure user attribute information is not store on client disk.
*
* In an vanilla apache-php installation is the php variables set to:
* session.cache_limiter = nocache
* so this is just to make sure.
*/
session_cache_limiter('nocache');
/* Load simpleSAMLphp, configuration and metadata */
$config = SimpleSAML_Configuration::getInstance();
$session = SimpleSAML_Session::getInstance();
......@@ -29,17 +40,38 @@ $session = SimpleSAML_Session::getInstance();
* authenticated, and therefore passes the if sentence below, and moves on to
* retrieving attributes from the session.
*/
if (!isset($session) || !$session->isValid('shib13') ) {
if (!$session->isValid('shib13') ) {
SimpleSAML_Utilities::redirect(
'/' . $config->getBaseURL() . 'shib13/sp/initSSO.php',
array('RelayState' => SimpleSAML_Utilities::selfURL())
);
}
$t = new SimpleSAML_XHTML_Template($config, 'status.php');
/* Prepare attributes for presentation
* and call a hook function for organizing the attribute array
*/
$attributes = $session->getAttributes();
$para = array(
'attributes' => &$attributes
);
SimpleSAML_Module::callHooks('attributepresentation', $para);
/*
* The attributes variable now contains all the attributes. So this variable is basicly all you need to perform integration in
* your PHP application.
*
* To debug the content of the attributes variable, do something like:
*
* print_r($attributes);
*
*/
$t = new SimpleSAML_XHTML_Template($config, 'status.php', 'attributes');
$t->data['header'] = '{status:header_shib}';
$t->data['remaining'] = $session->remainingTime();
$t->data['sessionsize'] = $session->getSize();
$t->data['attributes'] = $attributes;
$t->data['attributes'] = $session->getAttributes();
$t->data['logout'] = null;
$et->data['icon'] = 'bino.png';
......
......@@ -265,5 +265,35 @@ div.preferredidp {
}
/* Attribute presentation in example page */
table.attributes {
width: 100%;
margin: 0px;
border: 0px;
border-collapse: collapse;
}
table.attributes td.attrname {
text-align: right;
}
table.attributes tr.even td {
background: #eee;
}
table.attributes tr td {
border-bottom: 1px solid #bbb;
border-left: 0px;
border-right: 0px;
background: #fff;
padding-top: 5px;
padding-left: 1em;
padding-right: 1em;
vertical-align: top;
}
table#table_with_attributes tr:last-child td {
border-bottom: none;
}
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