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

Commit 30eb2bb

Browse files
Merge pull request #103 from vyskocilpavel/entitlement_getconfig
Changes in getting configuration in PerunEntitlement.php
2 parents 278f7fc + 849d83a commit 30eb2bb

File tree

2 files changed

+24
-34
lines changed

2 files changed

+24
-34
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file.
55
#### Added
66
- Added facility capabilities to PerunEntitlement
77

8+
#### Changed
9+
- Use object `Configuration` for getting base module configuration
10+
811
#### Fixed
912
- Fixed the width of showed tagged idps in case the count of idps is equal to (x * 3) + 1
1013

lib/Auth/Process/PerunEntitlement.php

Lines changed: 21 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -34,52 +34,39 @@ class PerunEntitlement extends ProcessingFilter
3434
private $entitlementPrefix;
3535
private $entitlementAuthority;
3636
private $groupNameAARC;
37-
private $interface;
3837
private $adapter;
3938

4039
public function __construct($config, $reserved)
4140
{
4241
parent::__construct($config, $reserved);
43-
$conf = Configuration::getConfig(self::CONFIG_FILE_NAME);
42+
$modulePerunConfiguration = Configuration::getConfig(self::CONFIG_FILE_NAME);
4443
assert('is_array($config)');
4544

46-
if (!isset($config[self::EDU_PERSON_ENTITLEMENT])) {
47-
throw new Exception(
48-
'perun:PerunEntitlement: missing mandatory configuration option ' .
49-
self::EDU_PERSON_ENTITLEMENT . '.'
50-
);
51-
}
5245
$configuration = Configuration::loadFromArray($config);
5346

54-
$this->eduPersonEntitlement = $config[self::EDU_PERSON_ENTITLEMENT];
55-
47+
$this->eduPersonEntitlement = $configuration->getString(self::EDU_PERSON_ENTITLEMENT);
5648
$this->releaseForwardedEntitlement = $configuration->getBoolean(self::RELEASE_FORWARDED_ENTITLEMENT, true);
49+
$this->forwardedEduPersonEntitlement = $configuration->getString(
50+
self::FORWARDED_EDU_PERSON_ENTITLEMENT,
51+
$this->releaseForwardedEntitlement ? Configuration::REQUIRED_OPTION : ''
52+
);
5753

58-
if (!isset($config[self::FORWARDED_EDU_PERSON_ENTITLEMENT])) {
59-
throw new Exception(
60-
'perun:PerunEntitlement: missing mandatory configuration option ' .
61-
self::FORWARDED_EDU_PERSON_ENTITLEMENT . '.'
62-
);
63-
}
64-
$this->forwardedEduPersonEntitlement = $config[self::FORWARDED_EDU_PERSON_ENTITLEMENT];
65-
66-
$this->entitlementPrefix = $conf->getString(self::ENTITLEMENTPREFIX_ATTR, '');
67-
$this->entitlementAuthority = $conf->getString(self::ENTITLEMENTAUTHORITY_ATTR, '');
68-
$this->groupNameAARC = $conf->getBoolean(self::GROUPNAMEAARC_ATTR, false);
69-
70-
if ($this->groupNameAARC && (empty($this->entitlementAuthority) || empty($this->entitlementPrefix))) {
71-
throw new Exception(
72-
'perun:PerunEntitlement: \'groupNameAARC\' has been set, \'entitlementAuthority\' ' .
73-
'and \'entitlementPrefix\' options must be set as well'
74-
);
75-
}
76-
77-
if (!isset($config[self::INTERFACE_PROPNAME])) {
78-
$config[self::INTERFACE_PROPNAME] = Adapter::RPC;
79-
}
54+
$this->groupNameAARC = $modulePerunConfiguration->getBoolean(self::GROUPNAMEAARC_ATTR, false);
55+
$this->entitlementPrefix = $modulePerunConfiguration->getString(
56+
self::ENTITLEMENTPREFIX_ATTR,
57+
$this->groupNameAARC ? Configuration::REQUIRED_OPTION : ''
58+
);
59+
$this->entitlementAuthority = $modulePerunConfiguration->getString(
60+
self::ENTITLEMENTAUTHORITY_ATTR,
61+
$this->groupNameAARC ? Configuration::REQUIRED_OPTION : ''
62+
);
8063

81-
$this->interface = (string)$config[self::INTERFACE_PROPNAME];
82-
$this->adapter = Adapter::getInstance($this->interface);
64+
$interface = $configuration->getValueValidate(
65+
self::INTERFACE_PROPNAME,
66+
[Adapter::RPC, Adapter::LDAP],
67+
Adapter::RPC
68+
);
69+
$this->adapter = Adapter::getInstance($interface);
8370
}
8471

8572
public function process(&$request)

0 commit comments

Comments
 (0)