Skip to content
Snippets Groups Projects
Commit 1c7de28b authored by Jaime Pérez Crespo's avatar Jaime Pérez Crespo Committed by GitHub
Browse files

Merge pull request #551 from doedje/feature/AttrCopy-array

feature: AttributeCopy can take array for an attribute
parents 985c2ded aa4078ce
No related branches found
No related tags found
No related merge requests found
`core:AttributeCopy` `core:AttributeCopy`
=================== ===================
Filter that renames attributes. Filter that copies attributes.
Examples Examples
-------- --------
Copy a single attribute (user's uid will be copied to the user's username): Copy a single attribute (user's `uid` will be copied to the user's `username`):
'authproc' => array( 'authproc' => array(
50 => array( 50 => array(
...@@ -16,3 +16,11 @@ Copy a single attribute (user's uid will be copied to the user's username): ...@@ -16,3 +16,11 @@ Copy a single attribute (user's uid will be copied to the user's username):
), ),
), ),
Copy a single attribute to more then one attribute (user's `uid` will be copied to the user's `username` and to `urn:mace:dir:attribute-def:uid`)
'authproc' => array(
50 => array(
'class' => 'core:AttributeCopy',
'uid' => array('username', 'urn:mace:dir:attribute-def:uid'),
),
),
...@@ -40,7 +40,7 @@ class sspmod_core_Auth_Process_AttributeCopy extends SimpleSAML_Auth_ProcessingF ...@@ -40,7 +40,7 @@ class sspmod_core_Auth_Process_AttributeCopy extends SimpleSAML_Auth_ProcessingF
throw new Exception('Invalid source attribute name: ' . var_export($source, TRUE)); throw new Exception('Invalid source attribute name: ' . var_export($source, TRUE));
} }
if(!is_string($destination)) { if(!is_string($destination) && !is_array($destination)) {
throw new Exception('Invalid destination attribute name: ' . var_export($destination, TRUE)); throw new Exception('Invalid destination attribute name: ' . var_export($destination, TRUE));
} }
...@@ -62,7 +62,13 @@ class sspmod_core_Auth_Process_AttributeCopy extends SimpleSAML_Auth_ProcessingF ...@@ -62,7 +62,13 @@ class sspmod_core_Auth_Process_AttributeCopy extends SimpleSAML_Auth_ProcessingF
foreach($attributes as $name => $values) { foreach($attributes as $name => $values) {
if (array_key_exists($name,$this->map)){ if (array_key_exists($name,$this->map)){
$attributes[$this->map[$name]] = $values; if (!is_array($this->map[$name])) {
$attributes[$this->map[$name]] = $values;
} else {
foreach ($this->map[$name] as $to_map) {
$attributes[$to_map] = $values;
}
}
} }
} }
......
...@@ -38,6 +38,26 @@ class Test_Core_Auth_Process_AttributeCopy extends PHPUnit_Framework_TestCase ...@@ -38,6 +38,26 @@ class Test_Core_Auth_Process_AttributeCopy extends PHPUnit_Framework_TestCase
$this->assertEquals($attributes['testnew'], array('AAP')); $this->assertEquals($attributes['testnew'], array('AAP'));
} }
/**
* Test the most basic functionality.
*/
public function testArray()
{
$config = array(
'test' => array('new1','new2'),
);
$request = array(
'Attributes' => array('test' => array('AAP')),
);
$result = self::processFilter($config, $request);
$attributes = $result['Attributes'];
$this->assertArrayHasKey('test', $attributes);
$this->assertArrayHasKey('new1', $attributes);
$this->assertArrayHasKey('new2', $attributes);
$this->assertEquals($attributes['new1'], array('AAP'));
$this->assertEquals($attributes['new2'], array('AAP'));
}
/** /**
* Test that existing attributes are left unmodified. * Test that existing attributes are left unmodified.
*/ */
...@@ -128,7 +148,7 @@ class Test_Core_Auth_Process_AttributeCopy extends PHPUnit_Framework_TestCase ...@@ -128,7 +148,7 @@ class Test_Core_Auth_Process_AttributeCopy extends PHPUnit_Framework_TestCase
public function testWrongAttributeValue() public function testWrongAttributeValue()
{ {
$config = array( $config = array(
'test' => array('test2'), 'test' => 100,
); );
$request = array( $request = array(
'Attributes' => array( 'Attributes' => array(
......
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