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

Commit e0166f6

Browse files
author
Dominik Frantisek Bucik
committed
fix: 🐛 Small fix in redirects in the PerunUser filter
1 parent 60d2ffb commit e0166f6

File tree

1 file changed

+27
-31
lines changed

1 file changed

+27
-31
lines changed

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)