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

core: Add ScopeAttribute filter.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@2158 44740490-163a-0410-bde0-09ae8108e29a
parent f6a428f1
No related branches found
No related tags found
No related merge requests found
`core:ScopeAttribute`
=====================
A filter which combines two attributes into a scoped attribute.
Parameters
----------
`scopeAttribute`
: The attribute that contains the scope.
: If the attribute contains a '@', we will take the scope from the part following the '@'.
Otherwise, we will use the entire value.
: If the attribute is multi-valued, we will add all the scopes to the target.
`sourceAttribute`
: The attribute that contains the values we shall add the scope to.
: This attribute can be multi-valued, in which case we will add all the values.
`targetAttribute`
: The attribute we shall add the scoped attributes to.
: If the attribute already exists, the new values will be merged into the existing attribute.
Example
-------
Add eduPersonScopedAffiliation based on eduPersonAffiliation and eduPersonPrincipalName.
10 => array(
'class' => 'core:ScopeAttribute',
'scopeAttribute' => 'eduPersonPrincipalName',
'sourceAttribute' => 'eduPersonAffiliation',
'targetAttribute' => 'eduPersonScopedAffiliation',
),
<?php
/**
* Add a scoped variant of an attribute.
*
* @package simpleSAMLphp
* @version $Id$
*/
class sspmod_core_Auth_Process_ScopeAttribute extends SimpleSAML_Auth_ProcessingFilter {
/**
* The attribute we extract the scope from.
*
* @var string
*/
private $scopeAttribute;
/**
* The attribute we want to add scope to.
*
* @var string
*/
private $sourceAttribute;
/**
* The attribute we want to add the scoped attributes to.
*
* @var string
*/
private $targetAttribute;
/**
* Initialize this filter, parse configuration
*
* @param array $config Configuration information about this filter.
* @param mixed $reserved For future use.
*/
public function __construct($config, $reserved) {
parent::__construct($config, $reserved);
assert('is_array($config)');
$config = SimpleSAML_Configuration::loadFromArray($config, 'ScopedAttributes');
$this->scopeAttribute = $config->getString('scopeAttribute');
$this->sourceAttribute = $config->getString('sourceAttribute');
$this->targetAttribute = $config->getString('targetAttribute');
}
/**
* Apply filter to rename attributes.
*
* @param array &$request The current request
*/
public function process(&$request) {
assert('is_array($request)');
assert('array_key_exists("Attributes", $request)');
$attributes =& $request['Attributes'];
if (!isset($attributes[$this->scopeAttribute])) {
return;
}
if (!isset($attributes[$this->sourceAttribute])) {
return;
}
if (!isset($attributes[$this->targetAttribute])) {
$attributes[$this->targetAttribute] = array();
}
foreach ($attributes[$this->scopeAttribute] as $scope) {
if (strpos($scope, '@') !== FALSE) {
$scope = explode('@', $scope, 2);
$scope = $scope[1];
}
foreach ($attributes[$this->sourceAttribute] as $value) {
$value = $value . '@' . $scope;
if (in_array($value, $attributes[$this->targetAttribute], TRUE)) {
/* Already present. */
continue;
}
$attributes[$this->targetAttribute][] = $value;
}
}
}
}
\ No newline at end of file
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