Skip to content

Commit

Permalink
add aa tester page
Browse files Browse the repository at this point in the history
  • Loading branch information
szabogyula committed Dec 16, 2020
1 parent 4a571a7 commit 35e5c79
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
7 changes: 6 additions & 1 deletion hooks/hook_frontpage.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ function aa_hook_frontpage(&$links)
assert('is_array($links)');
assert('array_key_exists("links", $links)');

$links['config'][] = array(
'href' => SimpleSAML_Module::getModuleURL('aa/test.php'),
'text' => 'Attribute Authority test page',
);

$links['federation'][] = array(
'href' => SimpleSAML_Module::getModuleURL('aa/metadata.php?output=xhtml'),
'text' => '{aa:aa:text}',
);
);
}
89 changes: 89 additions & 0 deletions templates/status.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{% set pagetitle = 'AttributeAuthority tester'|trans %}
{% extends 'base.twig' %}

{% block content %}
<h2>{{ pagetitle }}</h2>

<form class="pure-form pure-form-aligned" action="test.php" method="POST">
<fieldset>
<div class="pure-control-group">
<label for="aligned-name">sp</label>
<select name="sp" id="sp">
{% for entityid, entitydata in sps %}
<option value="{{ entityid }}">{{ entityid }}</option>
{% endfor %}
</select>
</div>
<legend>Key attribute</legend>
<div class="pure-control-group">
<label for="aligned-name">name</label>
<input type="text" name="keyattributename" value="urn:oid:1.3.6.1.4.1.5923.1.1.1.6"/>
<label for="aligned-name">value</label>
<input type="text" name="keyattributevalue"/>
</div>
<div class="pure-controls">
<button type="submit" class="pure-button pure-button-primary">Test</button>
</div>
</fieldset>
</form>

{% set items = attributes %}
{% embed '_table.twig' -%}
{% block namecol -%}
{% set translated = name|trans %}
<td class="attrname">{% if translated != name %} {{ translated }} <br>{% endif %} <samp>{{ name }}</samp>
</td>
{% endblock %}

{% block value -%}
{{ value }}
{% endblock %}
{%- endembed %}

<h4>configauthproc</h4>
<table id="authproc_table" class="attributes pure-table pure-table-striped pure-table-attributes"
summary="authproc overview">

{% for name, value in configauthproc %}
<tr class="{{ cycle(['odd', 'even'], loop.index0) }}">
{% block namecol -%}
<td class="attrname">{{ name }}</td>
{%- endblock %}
<td class="attrvalue">
{% block value %}
{{ value.class }}
{% endblock %}
</td>
</tr>
{% endfor %}
</table><br>

{% set items = processedattributes %}
{% embed '_table.twig' -%}
{% block namecol -%}
{% set translated = name|trans %}
<td class="attrname">{% if translated != name %} {{ translated }} <br>{% endif %} <samp>{{ name }}</samp>
</td>
{% endblock %}

{% block value -%}
{{ value }}
{% endblock %}
{%- endembed %}


{% if debug %}
<h4>debug</h4>
<code>
{{ debug }}
</code>
{% endif %}

{% if exception %}
<h4>exception</h4>
<pre>
{{ exception }}
</pre>
{% endif %}

{% endblock %}
61 changes: 61 additions & 0 deletions www/test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
/**
*
* @author [email protected]
* @author [email protected]
* @package
*/

require_once('_include.php');

SimpleSAML\Utils\Auth::requireAdmin();
SimpleSAML\Logger::info('SAML2.0 - AA Server: access testpage');

$t = new SimpleSAML\XHTML\Template($config, 'aa:status.php');
$t->getTwig()->enableDebug();
$t->getTwig()->addExtension(new Twig\Extension\DebugExtension());

$metadata = SimpleSAML\Metadata\MetaDataStorageHandler::getMetadataHandler();

$aaEntityId = $metadata->getMetaDataCurrentEntityID('attributeauthority-hosted');
$aaMetadata = $metadata->getMetadataConfig($aaEntityId, 'attributeauthority-hosted');

$config = \SimpleSAML\Configuration::getInstance();
$configauthproc = $config->getArray('authproc.aa', null);
$t->data['configauthproc'] = $configauthproc;

$spMetadatas = $metadata->getList('saml20-sp-remote');
$t->data['sps'] = $spMetadatas;

$attributes = [];

try {
if ($_POST['keyattributename'] && $_POST['keyattributevalue']) {
$attributes[$_POST['keyattributename']] = [0 => $_POST['keyattributevalue']];
}
$t->data['attributes'] = $attributes;

if ($_POST['sp']) {
$spEntityId = $_POST['sp'];
$spMetadataArray = $metadata->getMetaData($spEntityId, 'saml20-sp-remote');
$pc = new \SimpleSAML\Auth\ProcessingChain($aaMetadata->toArray(), $spMetadataArray, 'aa');
$authProcState = [
'Attributes' => $attributes,
'Destination' => $spMetadataArray,
'Source' => $aaMetadata->toArray(),
];
$pc->processStatePassive($authProcState);
$processedattributes = $authProcState['Attributes'];
$t->data['processedattributes'] = $processedattributes;
}

} catch (Exception $exception) {
$t->data['exception'] = $exception->getMessage();
$t->send();
}

if (!empty($debug)) {
$t->data['debug'] = var_export($debug, true);
}

$t->send();

0 comments on commit 35e5c79

Please sign in to comment.