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

Commit 58d099d

Browse files
author
Dominik František Bučík
authored
Merge pull request #253 from dBucik/fixes
Fixes
2 parents 7e34cc4 + e0166f6 commit 58d099d

File tree

3 files changed

+35
-41
lines changed

3 files changed

+35
-41
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
}

lib/Auth/Process/PerunUser.php

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,21 @@ public function __construct($config, $reserved)
6060
$this->userIdAttrs = $this->filterConfig->getArray(self::UID_ATTRS, []);
6161
if (empty($this->userIdAttrs)) {
6262
throw new Exception(
63-
self::DEBUG_PREFIX . 'Invalid configuration: no attributes configured for ' . 'extracting UID. Use option \'' . self::UID_ATTRS . '\' to configure list of attributes, ' . 'that should be considered as IDs for a user'
63+
self::DEBUG_PREFIX . 'Invalid configuration: no attributes configured for extracting UID. Use option \'' . self::UID_ATTRS . '\' to configure list of attributes, that should be considered as IDs for a user'
6464
);
6565
}
6666
$this->idpEntityIdAttr = $this->filterConfig->getString(self::IDP_ID_ATTR, null);
6767
if (empty($this->idpEntityIdAttr)) {
6868
throw new Exception(
69-
self::DEBUG_PREFIX . 'Invalid configuration: no attribute containing IDP ' . 'ID has been configured. Use option \'' . self::IDP_ID_ATTR . '\' to configure the name of the ' . 'attribute, that has been previously used in the configuration of filter \'perun:ExtractIdpEntityId\''
69+
self::DEBUG_PREFIX . 'Invalid configuration: no attribute containing IDP ID has been configured. Use option \'' . self::IDP_ID_ATTR . '\' to configure the name of the attribute, that has been previously used in the configuration of filter \'perun:ExtractIdpEntityId\''
7070
);
7171
}
7272
$this->registerUrl = $this->filterConfig->getString(self::REGISTER_URL, null);
7373
$this->callbackParameterName = $this->filterConfig->getString(self::CALLBACK_PARAMETER_NAME, null);
7474
$this->perunRegisterUrl = $this->filterConfig->getString(self::PERUN_REGISTER_URL, null);
7575
if (empty($this->registerUrl) && empty($this->callbackParameterName) && empty($this->perunRegisterUrl)) {
7676
throw new Exception(
77-
self::DEBUG_PREFIX . 'Invalid configuration: no URL where user should register for the ' . 'account has been configured. Use option \'' . self::REGISTER_URL . '\' to configure the URL and ' . 'option \'' . self::CALLBACK_PARAMETER_NAME . '\' to configure name of the callback parameter.
77+
self::DEBUG_PREFIX . 'Invalid configuration: no URL where user should register for the account has been configured. Use option \'' . self::REGISTER_URL . '\' to configure the URL and option \'' . self::CALLBACK_PARAMETER_NAME . '\' to configure name of the callback parameter.
7878
. If you wish to use the Perun registrar, use the option \'' . self::PERUN_REGISTER_URL . '\'.'
7979
);
8080
}
@@ -92,10 +92,10 @@ public function process(&$request)
9292
}
9393
}
9494
if (empty($uids)) {
95-
throw new Exception(self::DEBUG_PREFIX . 'missing at least one of mandatory attributes [' . implode(
96-
', ',
97-
$this->userIdAttrs
98-
) . '] in request.');
95+
$serializedUids = implode(', ', $this->userIdAttrs);
96+
throw new Exception(
97+
self::DEBUG_PREFIX . 'missing at least one of mandatory attributes [' . $serializedUids . '] in request.'
98+
);
9999
}
100100

101101
if (!empty($request[PerunConstants::ATTRIBUTES][$this->idpEntityIdAttr][0])) {
@@ -109,13 +109,10 @@ public function process(&$request)
109109
$user = $this->adapter->getPerunUser($idpEntityId, $uids);
110110

111111
if (!empty($user)) {
112-
Logger::debug(self::DEBUG_PREFIX . 'User identified, setting Perun user into request.');
113112
$this->processUser($request, $user, $uids);
114-
115-
return;
113+
} else {
114+
$this->register($request, $uids);
116115
}
117-
Logger::debug(self::DEBUG_PREFIX . 'User not identified, redirecting to registration.');
118-
$this->register($request, $uids);
119116
}
120117

121118
private function processUser(array &$request, User $user, array $uids): void
@@ -126,9 +123,9 @@ private function processUser(array &$request, User $user, array $uids): void
126123

127124
$request[PerunConstants::PERUN][PerunConstants::USER] = $user;
128125

126+
$logUids = implode(', ', $uids);
129127
Logger::info(
130-
self::DEBUG_PREFIX . 'Perun user with identity/ies: ' . implode(',', $uids)
131-
. ' has been found. Setting user ' . $user->getName() . ' with id: ' . $user->getId() . ' to the request.'
128+
self::DEBUG_PREFIX . 'Perun user with identity/ies: \'' . $logUids . '\' has been found. Setting user ' . $user->getName() . ' with id: ' . $user->getId() . ' to the request.'
132129
);
133130
}
134131

@@ -140,35 +137,34 @@ private function register(array &$request, array $uids): void
140137
self::PARAM_STATE_ID => $stateId,
141138
]);
142139
Logger::debug(self::DEBUG_PREFIX . 'Produced callback URL \'' . $callback . '\'');
140+
$url = '';
141+
$params = [];
143142

144143
if (!empty($this->registerUrl) && !empty($this->callbackParameterName)) {
144+
$url = $this->registerUrl;
145+
$params[$this->callbackParameterName] = $callback;
145146
Logger::debug(
146-
self::DEBUG_PREFIX . 'Redirecting to \'' . $this->registerUrl . ', callback parameter \''
147-
. $this->callbackParameterName . '\' with value \'' . $callback . '\''
147+
self::DEBUG_PREFIX . 'Redirecting to \'' . $this->registerUrl . ', callback parameter \'' . $this->callbackParameterName . '\' set to value \'' . $callback . '\'.'
148148
);
149-
HTTP::redirectTrustedURL($this->registerUrl, [
150-
$this->callbackParameterName => $callback,
151-
]);
152149
} elseif (!empty($this->perunRegisterUrl)) {
153-
$params[PerunConstants::TARGET_NEW] = $callback;
154-
$params[PerunConstants::TARGET_EXISTING] = $callback;
155-
$params[PerunConstants::TARGET_EXTENDED] = $callback;
150+
$perunParams[PerunConstants::TARGET_NEW] = $callback;
151+
$perunParams[PerunConstants::TARGET_EXISTING] = $callback;
152+
$perunParams[PerunConstants::TARGET_EXTENDED] = $callback;
153+
$registrationUrl = HTTP::addURLParameters($this->perunRegisterUrl, $perunParams);
156154

157155
$url = Module::getModuleURL(self::REDIRECT);
158-
$registrationUrl = HTTP::addURLParameters($this->perunRegisterUrl, $params);
156+
$params[self::PARAM_REGISTRATION_URL] = $registrationUrl;
159157
Logger::debug(
160-
self::DEBUG_PREFIX . 'Redirecting to \'' . self::REDIRECT . ', registration URL \''
161-
. $registrationUrl . '\''
158+
self::DEBUG_PREFIX . 'Redirecting to \'' . self::REDIRECT . ', param registration URL \'' . $registrationUrl . '\'.'
162159
);
163-
HTTP::redirectTrustedURL($url, [
164-
self::PARAM_REGISTRATION_URL => $registrationUrl,
165-
]);
166160
} else {
167-
throw new Exception(self::DEBUG_PREFIX . 'No configuration for registration enabled. Cannot proceed');
161+
throw new Exception(self::DEBUG_PREFIX . 'No configuration for registration set. Cannot proceed.');
168162
}
163+
164+
HTTP::redirectTrustedURL($url, $params);
165+
$logUids = implode(', ', $uids);
169166
Logger::info(
170-
self::DEBUG_PREFIX . 'Perun user with identity/ies: ' . implode(',', $uids) .
171-
' has not been found. Redirecting to registration.'
167+
self::DEBUG_PREFIX . 'Perun user with identity/ies: \'' . $logUids . '\' has not been found. User has been redirected to registration.'
172168
);
173169
}
174170
}

0 commit comments

Comments
 (0)