Skip to content
Snippets Groups Projects
Unverified Commit 2456842a authored by Thijs Kinkhorst's avatar Thijs Kinkhorst Committed by GitHub
Browse files

Merge pull request #868 from ghalse/patch/noconsentattributes-revisited

consentAdmin: Add attributes.exclude option to correspond with the Consent module
parents 77a657e0 8fae78b1
No related branches found
No related tags found
No related merge requests found
......@@ -160,9 +160,15 @@ The following options can be used when configuring the Consent module:
the attributes that should have their value hidden. Default behaviour is that
all attribute values are shown.
`attributes.exclude`
: Allows certain attributes to be excluded from the attribute hash when
`includeValues` is `true` (and as a side effect, to be hidden from display
as `hiddenAttributes` does). Set to an array of the attributes that should
be excluded. Default behaviour is to include all values in the hash.
`showNoConsentAboutService`
: Whether we will show a link to more information about the service from the
no consent page. Defaults to `TRUE`.
no consent page. Defaults to `true`.
External options
----------------
......
......@@ -116,7 +116,16 @@ class sspmod_consent_Auth_Process_Consent extends SimpleSAML_Auth_ProcessingFilt
$this->_hiddenAttributes = $config['hiddenAttributes'];
}
if (array_key_exists('noconsentattributes', $config)) {
if (array_key_exists('attributes.exclude', $config)) {
if (!is_array($config['attributes.exclude'])) {
throw new SimpleSAML_Error_Exception(
'Consent: attributes.exclude must be an array. '.
var_export($config['attributes.exclude'], true).' given.'
);
}
$this->_noconsentattributes = $config['attributes.exclude'];
} elseif (array_key_exists('noconsentattributes', $config)) {
SimpleSAML\Logger::warning("The 'noconsentattributes' option has been deprecated in favour of 'attributes.exclude'.");
if (!is_array($config['noconsentattributes'])) {
throw new SimpleSAML_Error_Exception(
'Consent: noconsentattributes must be an array. '.
......
......@@ -6,23 +6,26 @@
* @package SimpleSAMLphp
*/
$config = array(
/*
* Configuration for the database connection.
*/
'consentadmin' => array(
'consent:Database',
'dsn' => 'mysql:host=DBHOST;dbname=DBNAME',
'username' => 'USERNAME',
'password' => 'PASSWORD',
),
// Hash attributes including values or not
'attributes.hash' => TRUE,
/*
* Configuration for the database connection.
*/
'consentadmin' => array(
'consent:Database',
'dsn' => 'mysql:host=DBHOST;dbname=DBNAME',
'username' => 'USERNAME',
'password' => 'PASSWORD',
),
// Where to direct the user after logout
// REMEMBER to prefix with http:// otherwise the relaystate is only appended
// Hash attributes including values or not
'attributes.hash' => true,
// If you set attributes.exclude in the consent module, this must match
// 'attributes.exclude' => array(),
// Where to direct the user after logout
// REMEMBER to prefix with http:// otherwise the relaystate is only appended
// to saml2 logout URL
'returnURL' => 'http://www.wayf.dk',
'returnURL' => 'http://www.wayf.dk',
// Shows description of the services if set to true (defaults to true)
'showDescription' => true,
......
......@@ -44,7 +44,9 @@ Setting optional parameters
In order to make the consentAdmin module work together with the consent
module correctly, you need to set the configuration 'attributes.hash'
according to the value of 'includeValues' configuration in the consent
module.
module. Likewise, if you've used the 'attributes.exclude' configuration
option in the consent module, you should also set the 'attributes.exclude'
configuration option here to match.
You should also set the 'returnURL' configuration in order to pass on your
users when the press the 'Logout' link.
......
......@@ -22,7 +22,8 @@ function driveProcessingChain(
$sp_entityid,
$attributes,
$userid,
$hashAttributes = false
$hashAttributes = false,
$excludeAttributes = array()
) {
/*
......@@ -54,6 +55,12 @@ function driveProcessingChain(
$pc->processStatePassive($authProcState);
$attributes = $authProcState['Attributes'];
// Remove attributes that do not require consent/should be excluded
foreach ($attributes as $attrkey => $attrval) {
if (in_array($attrkey, $excludeAttributes)) {
unset($attributes[$attrkey]);
}
}
/*
* Generate identifiers and hashes
......@@ -86,6 +93,8 @@ if (array_key_exists('logout', $_REQUEST)) {
$hashAttributes = $cA_config->getValue('attributes.hash');
$excludeAttributes = $cA_config->getValue('attributes.exclude', array());
// Check if valid local session exists
$as->requireAuth();
......@@ -163,7 +172,7 @@ if ($action !== null && $sp_entityid !== null) {
// Run AuthProc filters
list($targeted_id, $attribute_hash, $attributes_new) = driveProcessingChain($idp_metadata, $source, $sp_metadata,
$sp_entityid, $attributes, $userid, $hashAttributes);
$sp_entityid, $attributes, $userid, $hashAttributes, $excludeAttributes);
// Add a consent (or update if attributes have changed and old consent for SP and IdP exists)
if ($action == 'true') {
......@@ -219,7 +228,7 @@ foreach ($all_sp_metadata as $sp_entityid => $sp_values) {
// Run attribute filters
list($targeted_id, $attribute_hash, $attributes_new) = driveProcessingChain($idp_metadata, $source, $sp_metadata,
$sp_entityid, $attributes, $userid, $hashAttributes);
$sp_entityid, $attributes, $userid, $hashAttributes, $excludeAttributes);
// Check if consent exists
if (array_key_exists($targeted_id, $user_consent)) {
......
......@@ -179,4 +179,39 @@ class ConsentTest extends TestCase
"Hash is not the same when the order of the attributs changes and the values are not included"
);
}
public function testConstructorSetsInstancePrivateVars()
{
$reflection = new \ReflectionClass('\sspmod_consent_Auth_Process_Consent');
foreach (array(
'_includeValues', '_checked', '_focus', '_hiddenAttributes', '_noconsentattributes', '_showNoConsentAboutService'
) as $v) {
$instanceVars[$v] = $reflection->getProperty($v);
$instanceVars[$v]->setAccessible(true);
}
/* these just need to be different to the default values */
$config = array(
'includeValues' => true,
'checked' => true,
'focus' => 'yes',
'hiddenAttributes' => array('attribute1', 'attribute2'),
'attributes.exclude' => array('attribute1', 'attribute2'),
'showNoConsentAboutService' => false,
);
$testcase = $reflection->newInstance($config, null);
$this->assertEquals($instanceVars['_includeValues']->getValue($testcase), $config['includeValues']);
$this->assertEquals($instanceVars['_checked']->getValue($testcase), $config['checked']);
$this->assertEquals($instanceVars['_focus']->getValue($testcase), $config['focus']);
$this->assertEquals($instanceVars['_hiddenAttributes']->getValue($testcase), $config['hiddenAttributes']);
$this->assertEquals($instanceVars['_noconsentattributes']->getValue($testcase), $config['attributes.exclude']);
$this->assertEquals($instanceVars['_showNoConsentAboutService']->getValue($testcase), $config['showNoConsentAboutService']);
$deprecated = $reflection->newInstance(array('noconsentattributes' => $config['attributes.exclude'],), null);
$this->assertEquals($instanceVars['_noconsentattributes']->getValue($deprecated), $config['attributes.exclude']);
}
}
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