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

Commit 13ca45e

Browse files
committed
feat: SpAuthorization - adds handle_unsatisfied_membership option
1 parent 760b6bd commit 13ca45e

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
lines changed

config-templates/processFilterConfigurations-example.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ Configuration options:
297297
* `vo_short_names_attr`: mapping to the attribute containing shortnames of the VOs for which the service has resources (gives access to the groups).
298298
* `registration_link_attr`: mapping to the attribute containing custom service registration link. Filter adds the callback URL, to which to redirect user after the registration, as query string in form of 'callback=URL'.
299299
* `allow_registration_attr`: mapping to the attribute containing flag, if registration in case of denied access is enabled
300+
* `handle_unsatisfied_membership`: whether handle unsatisfied membership
300301

301302
```php
302303
25 => [
@@ -307,6 +308,7 @@ Configuration options:
307308
'vo_short_names_attr' => 'vo_short_names',
308309
'registration_link_attr' => 'registration_link',
309310
'allow_registration_attr' => 'allow_registration',
311+
'handle_unsatisfied_membership' => true,
310312
],
311313
```
312314

lib/Auth/Process/SpAuthorization.php

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use SimpleSAML\Module\perun\model\Group;
1616
use SimpleSAML\Module\perun\model\Member;
1717
use SimpleSAML\Module\perun\model\User;
18-
use SimpleSAML\Module\perun\model\Vo;
1918
use SimpleSAML\Module\perun\PerunConstants;
2019
use SimpleSAML\Utils\HTTP;
2120

@@ -60,6 +59,7 @@ class SpAuthorization extends ProcessingFilter
6059
public const REGISTRAR_URL = 'registrar_url';
6160
public const CHECK_GROUP_MEMBERSHIP_ATTR = 'check_group_membership_attr';
6261
public const VO_SHORT_NAMES_ATTR = 'vo_short_names_attr';
62+
public const HANDLE_UNSATISFIED_MEMBERSHIP = 'handle_unsatisfied_membership';
6363
public const REGISTRATION_LINK_ATTR = 'registration_link_attr';
6464
public const ALLOW_REGISTRATION_ATTR = 'allow_registration_attr';
6565

@@ -71,12 +71,13 @@ class SpAuthorization extends ProcessingFilter
7171

7272
private $adapter;
7373
private $rpcAdapter;
74-
private $registrarUrl;
7574
private $checkGroupMembershipAttr;
7675
private $voShortNamesAttr;
7776
private $allowRegistrationAttr;
7877
private $registrationLinkAttr;
7978
private $skipNotificationSps;
79+
private $handleUnsatisfiedMembership;
80+
private $registrarUrl;
8081
private $config;
8182
private $filterConfig;
8283

@@ -89,21 +90,6 @@ public function __construct($config, $reserved)
8990
$interface = $this->filterConfig->getString(self::INTERFACE, Adapter::RPC);
9091
$this->adapter = Adapter::getInstance($interface);
9192

92-
try {
93-
$this->rpcAdapter = Adapter::getInstance(Adapter::RPC);
94-
} catch (Exception $ex) {
95-
Logger::warning(self::DEBUG_PREFIX . 'Could not create RPC adapter. Registrations will not work');
96-
Logger::debug($ex);
97-
$this->rpcAdapter = null;
98-
}
99-
100-
$this->registrarUrl = $this->filterConfig->getString(self::REGISTRAR_URL, null);
101-
if (empty($this->registrarUrl)) {
102-
throw new Exception(
103-
self::DEBUG_PREFIX . 'Invalid configuration: no URL with location of Perun registrar ' . 'has been configured. Use option \'' . self::REGISTRAR_URL . '\' to configure the location of Perun' . 'registration component.'
104-
);
105-
}
106-
10793
$this->checkGroupMembershipAttr = $this->filterConfig->getString(self::CHECK_GROUP_MEMBERSHIP_ATTR, null);
10894
if (empty($this->checkGroupMembershipAttr)) {
10995
throw new Exception(
@@ -118,9 +104,26 @@ public function __construct($config, $reserved)
118104
);
119105
}
120106

107+
$this->registrarUrl = $this->filterConfig->getString(self::REGISTRAR_URL, null);
121108
$this->allowRegistrationAttr = $this->filterConfig->getString(self::ALLOW_REGISTRATION_ATTR, null);
122109
$this->registrationLinkAttr = $this->filterConfig->getString(self::REGISTRATION_LINK_ATTR, null);
123110
$this->skipNotificationSps = $this->filterConfig->getArray(self::SKIP_NOTIFICATION_SPS, []);
111+
112+
$this->handleUnsatisfiedMembership = $this->filterConfig->getBoolean(self::HANDLE_UNSATISFIED_MEMBERSHIP, true);
113+
if ($this->handleUnsatisfiedMembership) {
114+
if (empty($this->registrationLinkAttr) && empty($this->registrarUrl)) {
115+
throw new Exception(
116+
self::DEBUG_PREFIX . 'Invalid configuration: filter should handle unsatisfied membership via registration, but neither registrarUrl nor registrationLinkAttr have been configured. Use option \'' . self::REGISTRAR_URL . '\' to configure the registrar location or/and option \'' . self::REGISTRATION_LINK_ATTR . '\' to configure attribute for Service defined registration link.'
117+
);
118+
}
119+
try {
120+
$this->rpcAdapter = Adapter::getInstance(Adapter::RPC);
121+
} catch (Exception $ex) {
122+
Logger::warning(self::DEBUG_PREFIX . 'Could not create RPC adapter. Registrations will not work.');
123+
Logger::debug($ex);
124+
$this->rpcAdapter = null;
125+
}
126+
}
124127
}
125128

126129
public function process(&$request)
@@ -188,6 +191,11 @@ public function handleUnsatisfiedMembership(
188191
Facility $facility,
189192
array $facilityAttributes
190193
) {
194+
if (!$this->handleUnsatisfiedMembership) {
195+
Logger::debug(self::DEBUG_PREFIX . 'Handling unsatisfied membership is disabled, redirecting to unauthorized');
196+
$this->unauthorized($request);
197+
return;
198+
}
191199
$allowRegistration = $facilityAttributes[self::ALLOW_REGISTRATION] ?? false;
192200
if ($allowRegistration) {
193201
$registrationLink = $facilityAttributes[self::REGISTRATION_LINK] ?? null;

0 commit comments

Comments
 (0)