ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
sspmod_core_Auth_Process_AttributeAlter Class Reference
+ Inheritance diagram for sspmod_core_Auth_Process_AttributeAlter:
+ Collaboration diagram for sspmod_core_Auth_Process_AttributeAlter:

Public Member Functions

 __construct ($config, $reserved)
 Initialize this filter. More...
 
 process (&$request)
 Apply the filter to modify attributes. More...
 
- Public Member Functions inherited from SimpleSAML_Auth_ProcessingFilter
 __construct (&$config, $reserved)
 Constructor for a processing filter. More...
 
 process (&$request)
 Process a request. More...
 

Private Attributes

 $replace = false
 Should the pattern found be replaced? More...
 
 $remove = false
 Should the value found be removed? More...
 
 $pattern = ''
 Pattern to search for. More...
 
 $replacement = false
 String to replace the pattern found with. More...
 
 $subject = ''
 Attribute to search in. More...
 
 $target = ''
 Attribute to place the result in. More...
 

Additional Inherited Members

- Data Fields inherited from SimpleSAML_Auth_ProcessingFilter
 $priority = 50
 Priority of this filter. More...
 

Detailed Description

Definition at line 10 of file AttributeAlter.php.

Constructor & Destructor Documentation

◆ __construct()

sspmod_core_Auth_Process_AttributeAlter::__construct (   $config,
  $reserved 
)

Initialize this filter.

Parameters
array$configConfiguration information about this filter.
mixed$reservedFor future use.
Exceptions
SimpleSAML_Error_ExceptionIn case of invalid configuration.

Definition at line 49 of file AttributeAlter.php.

References $config, and $name.

50  {
51  parent::__construct($config, $reserved);
52 
53  assert(is_array($config));
54 
55  // parse filter configuration
56  foreach ($config as $name => $value) {
57  if (is_int($name)) {
58  // check if this is an option
59  if ($value === '%replace') {
60  $this->replace = true;
61  } elseif ($value === '%remove') {
62  $this->remove = true;
63  } else {
64  throw new SimpleSAML_Error_Exception('Unknown flag : ' . var_export($value, true));
65  }
66  continue;
67  } elseif ($name === 'pattern') {
68  // Set pattern
69  $this->pattern = $value;
70  } elseif ($name === 'replacement') {
71  // Set replacement
72  $this->replacement = $value;
73  } elseif ($name === 'subject') {
74  // Set subject
75  $this->subject = $value;
76  } elseif ($name === 'target') {
77  // Set target
78  $this->target = $value;
79  }
80  }
81  }
$config
Definition: bootstrap.php:15

Member Function Documentation

◆ process()

sspmod_core_Auth_Process_AttributeAlter::process ( $request)

Apply the filter to modify attributes.

Modify existing attributes with the configured values.

Parameters
array&$requestThe current request.
Exceptions
SimpleSAML_Error_ExceptionIn case of invalid configuration.

Definition at line 91 of file AttributeAlter.php.

References $attributes, $replacement, $request, $subject, and $target.

91  {
92  assert(is_array($request));
93  assert(array_key_exists('Attributes', $request));
94 
95  // get attributes from request
96  $attributes =& $request['Attributes'];
97 
98  // check that all required params are set in config
99  if (empty($this->pattern) || empty($this->subject)) {
100  throw new SimpleSAML_Error_Exception("Not all params set in config.");
101  }
102 
103  if (!$this->replace && !$this->remove && $this->replacement === false) {
104  throw new SimpleSAML_Error_Exception("'replacement' must be set if neither '%replace' nor ".
105  "'%remove' are set.");
106  }
107 
108  if (!$this->replace && $this->replacement === null) {
109  throw new SimpleSAML_Error_Exception("'%replace' must be set if 'replacement' is null.");
110  }
111 
112  if ($this->replace && $this->remove) {
113  throw new SimpleSAML_Error_Exception("'%replace' and '%remove' cannot be used together.");
114  }
115 
116  if (empty($this->target)) {
117  // use subject as target if target is not set
118  $this->target = $this->subject;
119  }
120 
121  if ($this->subject !== $this->target && $this->remove) {
122  throw new SimpleSAML_Error_Exception("Cannot use '%remove' when 'target' is different than 'subject'.");
123  }
124 
125  if (!array_key_exists($this->subject, $attributes)) {
126  // if no such subject, stop gracefully
127  return;
128  }
129 
130  if ($this->replace) { // replace the whole value
131  foreach ($attributes[$this->subject] as &$value) {
132  $matches = array();
133  if (preg_match($this->pattern, $value, $matches) > 0) {
134  $new_value = $matches[0];
135 
136  if ($this->replacement !== FALSE) {
137  $new_value = $this->replacement;
138  }
139 
140  if ($this->subject === $this->target) {
141  $value = $new_value;
142  } else {
143  $attributes[$this->target] = array($new_value);
144  }
145  }
146  }
147  } elseif ($this->remove) { // remove the whole value
148  $removedAttrs = array();
149  foreach ($attributes[$this->subject] as $value) {
150  $matches = array();
151  if (preg_match($this->pattern, $value, $matches) > 0) {
152  $removedAttrs[] = $value;
153  }
154  }
155  $attributes[$this->target] = array_diff($attributes[$this->subject], $removedAttrs);
156 
157  if (empty($attributes[$this->target])) {
158  unset($attributes[$this->target]);
159  }
160  } else { // replace only the part that matches
161  if ($this->subject === $this->target) {
162  $attributes[$this->target] = preg_replace(
163  $this->pattern, $this->replacement,
164  $attributes[$this->subject]
165  );
166  } else {
167  $attributes[$this->target] = array_diff(
168  preg_replace(
169  $this->pattern,
170  $this->replacement,
171  $attributes[$this->subject]
172  ),
173  $attributes[$this->subject]
174  );
175  }
176  }
177  }
$target
Attribute to place the result in.
foreach($paths as $path) $request
Definition: asyncclient.php:32
if(array_key_exists('yes', $_REQUEST)) $attributes
Definition: getconsent.php:85
$replacement
String to replace the pattern found with.

Field Documentation

◆ $pattern

sspmod_core_Auth_Process_AttributeAlter::$pattern = ''
private

Pattern to search for.

Definition at line 25 of file AttributeAlter.php.

◆ $remove

sspmod_core_Auth_Process_AttributeAlter::$remove = false
private

Should the value found be removed?

Definition at line 20 of file AttributeAlter.php.

◆ $replace

sspmod_core_Auth_Process_AttributeAlter::$replace = false
private

Should the pattern found be replaced?

Definition at line 15 of file AttributeAlter.php.

◆ $replacement

sspmod_core_Auth_Process_AttributeAlter::$replacement = false
private

String to replace the pattern found with.

Definition at line 30 of file AttributeAlter.php.

Referenced by process().

◆ $subject

sspmod_core_Auth_Process_AttributeAlter::$subject = ''
private

Attribute to search in.

Definition at line 35 of file AttributeAlter.php.

Referenced by process().

◆ $target

sspmod_core_Auth_Process_AttributeAlter::$target = ''
private

Attribute to place the result in.

Definition at line 40 of file AttributeAlter.php.

Referenced by process().


The documentation for this class was generated from the following file: