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

Commit fca9739

Browse files
committed
fix: Code checks
1 parent 524c6ed commit fca9739

File tree

9 files changed

+70
-42
lines changed

9 files changed

+70
-42
lines changed

lib/Adapter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ abstract public function getMemberGroups($user, $vo);
8888
* @param User $user perun user
8989
* @param Vo $vo vo we are working with
9090
*
91-
* @return Group[] groups from vo where user is valid.
91+
* @return Group[] groups from vo where user is valid
9292
*/
9393
abstract public function getGroupsWhereMemberIsActive($user, $vo);
9494

@@ -182,7 +182,7 @@ abstract public function getUsersGroupsOnSp($spEntityId, $userId);
182182

183183
/**
184184
* @param Facility $facility entity id of the sp
185-
* @param int $userId
185+
* @param int $userId
186186
*
187187
* @return Group[] from vo which are assigned to all facilities with spEntityId for this userId
188188
*/

lib/AdapterLdap.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ public function setUserExtSourceAttributes($userExtSourceId, $attributes)
464464
public function getUsersGroupsOnSp($spEntityId, $userId)
465465
{
466466
$facility = $this->getFacilityByEntityId($spEntityId);
467+
467468
return self::getUsersGroupsOnFacility($facility, $userId);
468469
}
469470

@@ -510,6 +511,7 @@ public function getUsersGroupsOnFacility($facility, $userId)
510511
)
511512
);
512513
}
514+
513515
return $this->removeDuplicateEntities($resultGroups);
514516
}
515517

lib/AdapterRpc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ public function getFacilityAttribute($facility, $attrName)
383383
public function getUsersGroupsOnSp($spEntityId, $userId)
384384
{
385385
$facility = $this->getFacilityByEntityId($spEntityId);
386+
386387
return self::getUsersGroupsOnFacility($facility, $userId);
387388
}
388389

@@ -739,7 +740,6 @@ private function getAttributes($perunAttrs, $attrNamesMap)
739740

740741
$attribute['name'] = $attrNamesMap[$perunAttrName];
741742
$attributes[$attrNamesMap[$perunAttrName]] = $attribute;
742-
743743
}
744744

745745
return $attributes;

lib/Auth/Process/ForceAup.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,9 @@ private function fillAupsToBeApproved($requestedAups, $aups, $userApprovedAups)
266266
$aupsToBeApproved = [];
267267
foreach ($requestedAups as $requestedAup) {
268268
if (!array_key_exists($requestedAup, $aups)) {
269-
Logger::debug('perun:ForceAup - Requested AUP \'' . $requestedAup . '\' is not in the list of VO AUPS, probably VO does not have AUP');
269+
Logger::debug(
270+
'perun:ForceAup - Requested AUP \'' . $requestedAup . '\' is not in the list of VO AUPS, probably VO does not have AUP'
271+
);
270272
continue;
271273
}
272274
$aupsInJson = $aups[$requestedAup];

lib/Auth/Process/PerunEnsureMember.php

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace SimpleSAML\Module\perun\Auth\Process;
46

57
use SimpleSAML\Auth\ProcessingFilter;
@@ -15,17 +17,17 @@
1517

1618
class PerunEnsureMember extends ProcessingFilter
1719
{
18-
const LOG_PREFIX = 'perun:PerunEnsureMember: ';
20+
public const LOG_PREFIX = 'perun:PerunEnsureMember: ';
1921

20-
const REGISTER_URL = 'registerUrl';
21-
const VO_SHORT_NAME = 'voShortName';
22-
const GROUP_NAME = 'groupName';
23-
const INTERFACE_PROPNAME = 'interface';
24-
const CALLBACK_PARAMETER_NAME = 'callbackParameterName';
25-
const RPC = 'rpc';
22+
public const REGISTER_URL = 'registerUrl';
23+
public const VO_SHORT_NAME = 'voShortName';
24+
public const GROUP_NAME = 'groupName';
25+
public const INTERFACE_PROPNAME = 'interface';
26+
public const CALLBACK_PARAMETER_NAME = 'callbackParameterName';
27+
public const RPC = 'rpc';
2628

27-
const CALLBACK = 'perun/perun_ensure_member_callback.php';
28-
const REDIRECT = 'perun/perun_ensure_member.php';
29+
public const CALLBACK = 'perun/perun_ensure_member_callback.php';
30+
public const REDIRECT = 'perun/perun_ensure_member.php';
2931

3032
public const STAGE = 'perun:PerunEnsureMember';
3133
public const PARAM_STATE_ID = PerunConstants::STATE_ID;
@@ -46,7 +48,7 @@ public function __construct($config, $reserved)
4648
parent::__construct($config, $reserved);
4749
$this->config = $config;
4850
$this->filterConfig = Configuration::loadFromArray($config);
49-
51+
5052
$this->registerUrl = $this->filterConfig->getString(self::REGISTER_URL, '');
5153
if (empty($this->registerUrl)) {
5254
throw new Exception(self::LOG_PREFIX . 'Missing configuration option \'' . self::REGISTER_URL . '\'');
@@ -59,7 +61,9 @@ public function __construct($config, $reserved)
5961

6062
$this->callbackParameterName = $this->filterConfig->getString(self::CALLBACK_PARAMETER_NAME, '');
6163
if (empty($this->callbackParameterName)) {
62-
throw new Exception(self::LOG_PREFIX . 'Missing configuration option \'' . self::CALLBACK_PARAMETER_NAME . '\'');
64+
throw new Exception(
65+
self::LOG_PREFIX . 'Missing configuration option \'' . self::CALLBACK_PARAMETER_NAME . '\''
66+
);
6367
}
6468

6569
$this->groupName = $this->filterConfig->getString(self::GROUP_NAME, '');
@@ -96,6 +100,7 @@ private function handleUser($user, $vo, $request): void
96100

97101
if (Member::VALID === $memberStatus && $isUserInGroup) {
98102
Logger::debug(self::LOG_PREFIX . 'User is allowed to continue');
103+
99104
return;
100105
}
101106

@@ -106,22 +111,32 @@ private function handleUser($user, $vo, $request): void
106111
if (Member::VALID === $memberStatus && $isUserInGroup) {
107112
Logger::debug(self::LOG_PREFIX . 'User is allowed to continue');
108113
} elseif (Member::VALID === $memberStatus && !$isUserInGroup && $groupHasRegistrationForm) {
109-
Logger::debug(self::LOG_PREFIX . 'User is not valid in group ' . $this->groupName . ' - sending to registration');
114+
Logger::debug(
115+
self::LOG_PREFIX . 'User is not valid in group ' . $this->groupName . ' - sending to registration'
116+
);
110117
$this->register($request, $this->groupName);
111118
} elseif (null === $memberStatus && $voHasRegistrationForm && $isUserInGroup) {
112-
Logger::debug(self::LOG_PREFIX . 'User is not member of vo ' . $this->voShortName . ' - sending to registration');
119+
Logger::debug(
120+
self::LOG_PREFIX . 'User is not member of vo ' . $this->voShortName . ' - sending to registration'
121+
);
113122
$this->register($request);
114123
} elseif (null === $memberStatus && $voHasRegistrationForm && !$isUserInGroup && $groupHasRegistrationForm) {
115-
Logger::debug(self::LOG_PREFIX . 'User is not member of vo ' . $this->voShortName . ' - sending to registration');
124+
Logger::debug(
125+
self::LOG_PREFIX . 'User is not member of vo ' . $this->voShortName . ' - sending to registration'
126+
);
116127
$this->register($request, $this->groupName);
117128
} elseif (Member::EXPIRED === $memberStatus && $voHasRegistrationForm && $isUserInGroup) {
118129
Logger::debug(self::LOG_PREFIX . 'User is expired - sending to registration');
119130
$this->register($request);
120131
} elseif (Member::EXPIRED === $memberStatus && $voHasRegistrationForm && !$isUserInGroup && $groupHasRegistrationForm) {
121-
Logger::debug(self::LOG_PREFIX . 'User is expired and is not in group ' . $this->groupName . ' - sending to registration');
132+
Logger::debug(
133+
self::LOG_PREFIX . 'User is expired and is not in group ' . $this->groupName . ' - sending to registration'
134+
);
122135
$this->register($request, $this->groupName);
123136
} else {
124-
Logger::debug(self::LOG_PREFIX . 'User is not valid in vo/group and cannot be sent to the registration - sending to unauthorized');
137+
Logger::debug(
138+
self::LOG_PREFIX . 'User is not valid in vo/group and cannot be sent to the registration - sending to unauthorized'
139+
);
125140
PerunIdentity::unauthorized($request);
126141
}
127142
}

lib/Auth/Process/PerunUserGroups.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,12 @@ public function process(&$request)
4747
}
4848

4949
$spEntityId = $request[PerunConstants::SP_METADATA][PerunConstants::SP_METADATA_ENTITYID] ?? null;
50-
$groups = [];
5150
if (empty($spEntityId)) {
5251
Logger::debug(self::DEBUG_PREFIX . 'No SP EntityID available, user groups will be empty');
53-
throw new Exception(
54-
self::DEBUG_PREFIX . 'Cannot find SP EntityID'
55-
);
56-
} else {
57-
$groups = $this->adapter->getUsersGroupsOnSp($spEntityId, $user->getId());
52+
throw new Exception(self::DEBUG_PREFIX . 'Cannot find SP EntityID');
5853
}
54+
55+
$groups = $this->adapter->getUsersGroupsOnSp($spEntityId, $user->getId());
5956
$request[PerunConstants::PERUN][PerunConstants::USER_GROUPS] = $groups;
6057
}
6158
}

lib/Auth/Process/SpAuthorization.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@ public function process(&$request)
140140
$spEntityId = $request[PerunConstants::SP_METADATA][PerunConstants::SP_METADATA_ENTITYID];
141141

142142
if (empty($request[PerunConstants::PERUN][PerunConstants::USER])) {
143-
Logger::debug(self::DEBUG_PREFIX . 'Request does not contain Perun user. Did you configure ' . PerunUser::STAGE . ' filter before this filter in the processing chain?');
143+
Logger::debug(
144+
self::DEBUG_PREFIX . 'Request does not contain Perun user. Did you configure ' . PerunUser::STAGE . ' filter before this filter in the processing chain?'
145+
);
144146
$this->unauthorized($request);
145147
}
146148
$user = $request[PerunConstants::PERUN][PerunConstants::USER];
@@ -149,6 +151,7 @@ public function process(&$request)
149151
Logger::debug(
150152
self::DEBUG_PREFIX . 'No facility found for SP \'' . $spEntityId . '\', skip processing filter'
151153
);
154+
152155
return;
153156
}
154157
$facilityAttributes = $this->getSPAttributes($facility);
@@ -157,12 +160,14 @@ public function process(&$request)
157160
self::DEBUG_PREFIX . 'Could not fetch SP attributes, user will be redirected to unauthorized for security reasons'
158161
);
159162
$this->unauthorized($request);
163+
160164
return;
161165
}
162166

163167
$checkGroupMembership = $facilityAttributes[self::CHECK_GROUP_MEMBERSHIP];
164168
if (!$checkGroupMembership) {
165169
Logger::info(self::DEBUG_PREFIX . 'Group membership check not requested by the service.');
170+
166171
return;
167172
}
168173

@@ -191,8 +196,11 @@ public function handleUnsatisfiedMembership(
191196
array $facilityAttributes
192197
) {
193198
if (!$this->handleUnsatisfiedMembership) {
194-
Logger::debug(self::DEBUG_PREFIX . 'Handling unsatisfied membership is disabled, redirecting to unauthorized');
199+
Logger::debug(
200+
self::DEBUG_PREFIX . 'Handling unsatisfied membership is disabled, redirecting to unauthorized'
201+
);
195202
$this->unauthorized($request);
203+
196204
return;
197205
}
198206
$allowRegistration = $facilityAttributes[self::ALLOW_REGISTRATION] ?? false;
@@ -217,6 +225,7 @@ public function handleUnsatisfiedMembership(
217225
if (!empty($registrationData)) {
218226
$skipNotification = in_array($spEntityId, $this->skipNotificationSps, true);
219227
$this->register($request, $registrationData, $skipNotification);
228+
220229
return;
221230
}
222231
Logger::debug(
@@ -358,8 +367,12 @@ protected function registerChooseVoAndGroup(array &$request, array $registration
358367
]);
359368
}
360369

361-
private function getRegistrationData($user, Facility $facility, string $spEntityId, array $facilityAttributes): array
362-
{
370+
private function getRegistrationData(
371+
$user,
372+
Facility $facility,
373+
string $spEntityId,
374+
array $facilityAttributes
375+
): array {
363376
if (null === $this->rpcAdapter) {
364377
throw new Exception(self::DEBUG_PREFIX . 'No RPC adapter available, cannot fetch registration data');
365378
}

lib/Disco.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -279,16 +279,11 @@ public function handleRequest()
279279
}
280280
if (!empty($state['aarc_idp_hint'])) {
281281
$hintedIdp = $state['aarc_idp_hint'];
282-
if (! array_key_exists($hintedIdp, $idpList)) {
283-
throw new Exception("Invalid request - IDP is not allowed to be used for this SP");
282+
if (!array_key_exists($hintedIdp, $idpList)) {
283+
throw new Exception('Invalid request - IDP is not allowed to be used for this SP');
284284
}
285285
Logger::info('Redirecting to hinted IdP using AARC_IDP_HINT. Redirecting to: ' . $hintedIdp);
286-
$url = self::buildContinueUrl(
287-
$this->spEntityId,
288-
$this->returnURL,
289-
$this->returnIdParam,
290-
$hintedIdp
291-
);
286+
$url = self::buildContinueUrl($this->spEntityId, $this->returnURL, $this->returnIdParam, $hintedIdp);
292287
HTTP::redirectTrustedURL($url);
293288
}
294289

www/updateUes.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,13 @@ function getAttributesFromPerun($adapter, $attrMap, $userExtSource): array
204204
return $attributesFromPerun;
205205
}
206206

207-
function getAttributesToUpdate($attributesFromPerun, $attrMap, $serializedAttributes, $appendOnlyAttrs, $attributesFromIdP): array
208-
{
207+
function getAttributesToUpdate(
208+
$attributesFromPerun,
209+
$attrMap,
210+
$serializedAttributes,
211+
$appendOnlyAttrs,
212+
$attributesFromIdP
213+
): array {
209214
$attributesToUpdate = [];
210215

211216
foreach ($attributesFromPerun as $attribute) {
@@ -217,13 +222,12 @@ function getAttributesToUpdate($attributesFromPerun, $attrMap, $serializedAttrib
217222
// appendOnly && has value && (complex || serialized)
218223
if (in_array($attrName, $appendOnlyAttrs, true) &&
219224
!empty($attribute[VALUE]) &&
220-
(isComplexType($attribute[TYPE]) || in_array($attrName, $serializedAttributes, true))
225+
(isComplexType($attribute[TYPE]) || in_array($attrName, $serializedAttributes, true))
221226
) {
222227
$attr = in_array($attrName, $serializedAttributes, true) ?
223228
array_merge($attr, explode(';', $attribute[VALUE])) : array_merge($attr, $attribute[VALUE]);
224229
}
225230

226-
227231
if (isSimpleType($attribute[TYPE])) {
228232
$newValue = convertToString($attr);
229233
} elseif (isComplexType($attribute[TYPE])) {

0 commit comments

Comments
 (0)