ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ScopeFromAttribute.php
Go to the documentation of this file.
1 <?php
2 
32 
39  public function __construct($config, $reserved) {
40  parent::__construct($config, $reserved);
41  assert(is_array($config));
42 
44  $this->targetAttribute = $config->getString('targetAttribute');
45  $this->sourceAttribute = $config->getString('sourceAttribute');
46  } // end constructor
47 
48 
54  public function process(&$request) {
55  assert(is_array($request));
56  assert(array_key_exists('Attributes', $request));
57 
58  $attributes =& $request['Attributes'];
59 
60  if (!isset($attributes[$this->sourceAttribute])) {
61  return;
62  }
63 
64  // will not overwrite existing attribute
65  if (isset($attributes[$this->targetAttribute])) {
66  return;
67  }
68 
69  $sourceAttrVal = $attributes[$this->sourceAttribute][0];
70 
71  /* the last position of an @ is usually the beginning of the scope
72  * string */
73  $scopeIndex = strrpos($sourceAttrVal, '@');
74 
75  if ($scopeIndex !== FALSE) {
77  $scope = substr($sourceAttrVal, $scopeIndex+1);
79  SimpleSAML\Logger::debug('ScopeFromAttribute: Inserted new attribute ' .
80  $this->targetAttribute . ', with scope ' .
81  $scope);
82  } else {
83  SimpleSAML\Logger::warning('ScopeFromAttribute: The configured source attribute ' .
84  $this->sourceAttribute .
85  ' does not have a scope. Did not add attribute ' .
86  $this->targetAttribute . '.');
87  }
88  } /* end process */
89 }
$config
Definition: bootstrap.php:15
foreach($paths as $path) $request
Definition: asyncclient.php:32
static debug($string)
Definition: Logger.php:211
__construct($config, $reserved)
Initialize this filter, parse configuration.
Retrieve a scope from a source attribute and add it as a virtual target attribute.
static warning($string)
Definition: Logger.php:177
if(array_key_exists('yes', $_REQUEST)) $attributes
Definition: getconsent.php:85
static loadFromArray($config, $location='[ARRAY]', $instance=null)
Loads a configuration from the given array.