Skip to content
This repository was archived by the owner on Sep 19, 2022. It is now read-only.

Commit 60d2ffb

Browse files
author
Dominik Frantisek Bucik
committed
fix: 🐛 Fix reading configurati novalues in ExtractRequestAttrib
1 parent 7e34cc4 commit 60d2ffb

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

config-templates/processFilterConfigurations-example.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ Example how to enable filter AttributeMap:
166166
Filter is intended to extract an attribute specified by set of keys forming the chain of keys in the `$request` variable into the configured destination attribute.
167167

168168
Configuration options:
169-
* `attr_name`: specifies attribute name, into which the extracted value will be stored
169+
* `destination_attr_name`: specifies attribute name, into which the extracted value will be stored
170170
* `request_keys`: string, which contains a semicolon (`;`) separated chain of keys that are examined in the state. Numeric keys are automatically treated as array indexes. For instance, value `'saml:AuthenticatingAuthority;0'` will be treated as code `$request['saml:AuthenticatingAuthority'][0]`. In case of this value being empty, exception is thrown. Otherwise, extracted value is stored into the configured destination attribute.
171171
* `fail_on_nonexisting_keys`: `true` or `false`, specifies if in case of missing key in the request variable the filter should terminate with an exception or not
172172
* `default_value`: array, which will be set as default value, if the configured keys did not lead to value
@@ -175,10 +175,10 @@ Configuration options:
175175
// EXTRACT AUTHENTICATING ENTITY INTO authenticating_idp attribute
176176
1 => [
177177
'class' => 'perun:ExtractRequestAttribute',
178-
'attr_name' => 'authenticating_idp',
178+
'destination_attr_name' => 'authenticating_idp',
179179
'request_keys' => 'saml:AuthenticatingAuthority;0',
180180
'fail_on_nonexisting_keys' => 'true',
181-
'default_value' => null,
181+
'default_value' => [],
182182
],
183183
```
184184

lib/Auth/Process/ExtractRequestAttribute.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class ExtractRequestAttribute extends ProcessingFilter
2424
public const DEFAULT_VALUE = 'default_value';
2525

2626
public const KEYS_SEPARATOR = ';';
27-
public const FAILURE_VALUE = '%$FAILURE_VALUE$%';
27+
public const FAILURE_VALUE = ['%$FAILURE_VALUE$%'];
2828

2929
private $destinationAttrName;
3030
private $requestKeys;
@@ -38,7 +38,7 @@ public function __construct($config, $reserved)
3838
$this->filterConfig = Configuration::loadFromArray($config);
3939

4040
$this->destinationAttrName = $this->filterConfig->getString(self::DESTINATION_ATTRIBUTE_NAME, null);
41-
if (empty($this->requestKeys)) {
41+
if (empty($this->destinationAttrName)) {
4242
throw new Exception(
4343
self::DEBUG_PREFIX . 'missing mandatory configuration for option \'' . self::DESTINATION_ATTRIBUTE_NAME . '\''
4444
);
@@ -75,9 +75,7 @@ public function process(&$request)
7575
}
7676
if (!array_key_exists($key, $value)) {
7777
Logger::warning(
78-
self::DEBUG_PREFIX . 'Cannot find key \'' .
79-
$key . '\' in the supposed path towards the value. Did you configure the right path of keys ' .
80-
'to extract it?'
78+
self::DEBUG_PREFIX . 'Cannot find key \'' . $key . '\' in the supposed path towards the value. Did you configure the right path of keys to extract it?'
8179
);
8280
if ($this->failOnNonExistingKey) {
8381
throw new Exception(self::DEBUG_PREFIX . 'Specified chain of keys does not exist');
@@ -99,9 +97,9 @@ public function process(&$request)
9997
$value = [$value];
10098
}
10199
$request[PerunConstants::ATTRIBUTES][$this->destinationAttrName] = $value;
100+
$logValue = implode(',', $value);
102101
Logger::debug(
103-
self::DEBUG_PREFIX . 'Value \'' . implode(',', $value)
104-
. '\' has been extracted and set to attribute ' . $this->destinationAttrName
102+
self::DEBUG_PREFIX . 'Value \'' . $logValue . '\' has been extracted and set to attribute ' . $this->destinationAttrName
105103
);
106104
}
107105
}

0 commit comments

Comments
 (0)