ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
AttributeValueMap.php
Go to the documentation of this file.
1<?php
2
4
12{
13
18
23
27 private $values = array();
28
32 private $keep = false;
33
37 private $replace = false;
38
46 public function __construct($config, $reserved)
47 {
48 parent::__construct($config, $reserved);
49
50 assert(is_array($config));
51
52 // parse configuration
53 foreach ($config as $name => $value) {
54 if (is_int($name)) {
55 // check if this is an option
56 if ($value === '%replace') {
57 $this->replace = true;
58 } elseif ($value === '%keep') {
59 $this->keep = true;
60 } else {
61 // unknown configuration option, log it and ignore the error
63 "AttributeValueMap: unknown configuration flag '".var_export($value, true)."'"
64 );
65 }
66 continue;
67 }
68
69 // set the target attribute
70 if ($name === 'targetattribute') {
71 $this->targetattribute = $value;
72 }
73
74 // set the source attribute
75 if ($name === 'sourceattribute') {
76 $this->sourceattribute = $value;
77 }
78
79 // set the values
80 if ($name === 'values') {
81 $this->values = $value;
82 }
83 }
84
85 // now validate it
86 if (!is_string($this->sourceattribute)) {
87 throw new \SimpleSAML_Error_Exception("AttributeValueMap: 'sourceattribute' configuration option not set.");
88 }
89 if (!is_string($this->targetattribute)) {
90 throw new \SimpleSAML_Error_Exception("AttributeValueMap: 'targetattribute' configuration option not set.");
91 }
92 if (!is_array($this->values)) {
93 throw new \SimpleSAML_Error_Exception("AttributeValueMap: 'values' configuration option is not an array.");
94 }
95 }
96
97
103 public function process(&$request)
104 {
105 \SimpleSAML\Logger::debug('Processing the AttributeValueMap filter.');
106
107 assert(is_array($request));
108 assert(array_key_exists('Attributes', $request));
109 $attributes =& $request['Attributes'];
110
111 if (!array_key_exists($this->sourceattribute, $attributes)) {
112 // the source attribute does not exist, nothing to do here
113 return;
114 }
115
117 $targetvalues = array();
118
119 if (is_array($sourceattribute)) {
120 foreach ($this->values as $value => $values) {
121 if (!is_array($values)) {
122 $values = array($values);
123 }
124 if (count(array_intersect($values, $sourceattribute)) > 0) {
125 \SimpleSAML\Logger::debug("AttributeValueMap: intersect match for '$value'");
126 $targetvalues[] = $value;
127 }
128 }
129 }
130
131 if (count($targetvalues) > 0) {
132 if ($this->replace || !array_key_exists($this->targetattribute, $attributes)) {
133 $attributes[$this->targetattribute] = $targetvalues;
134 } else {
135 $attributes[$this->targetattribute] = array_unique(array_merge(
136 $attributes[$this->targetattribute],
137 $targetvalues
138 ));
139 }
140 }
141
142 if (!$this->keep) {
143 // no need to keep the source attribute
144 unset($attributes[$this->sourceattribute]);
145 }
146 }
147}
foreach($paths as $path) $request
Definition: asyncclient.php:32
An exception for terminatinating execution or to throw for unit testing.
static warning($string)
Definition: Logger.php:177
static debug($string)
Definition: Logger.php:211
$replace
Whether $target attribute values should be replaced by new values or not.
$sourceattribute
The name of the attribute we should create values from.
__construct($config, $reserved)
Initialize the filter.
$keep
Whether $sourceattribute should be kept or not.
$targetattribute
The name of the attribute we should assign values to (ie: the target attribute).
$values
The required $sourceattribute values and target affiliations.
if(array_key_exists('yes', $_REQUEST)) $attributes
Definition: getconsent.php:85
$config
Definition: bootstrap.php:15