ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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.

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

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 98 of file AttributeAlter.php.

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

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