diff --git a/composer.json b/composer.json index 1f440c4e..569d6a7f 100644 --- a/composer.json +++ b/composer.json @@ -61,7 +61,7 @@ "web-token/jwt-core": "^2.2" }, "require-dev": { - "symplify/easy-coding-standard": "^10.0" + "symplify/easy-coding-standard": "^10.2" }, "suggest": { "cesnet/simplesamlphp-module-privacyidea": "included privacyIDEA template is for this module" diff --git a/composer.lock b/composer.lock index 4fb1bb87..074bf2a4 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "e1ec5f5b24b9930d7e93504e07402ef5", + "content-hash": "0db0a97b6db7c617395634162f48d5b6", "packages": [ { "name": "brick/math", @@ -5905,20 +5905,20 @@ "packages-dev": [ { "name": "symplify/easy-coding-standard", - "version": "10.2.2", + "version": "10.2.7", "source": { "type": "git", "url": "https://github.com/symplify/easy-coding-standard.git", - "reference": "d847795500b929f68ed115357658122d64017f77" + "reference": "e34a105876b0640e70c584d75adaf9c0b03cf0f3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symplify/easy-coding-standard/zipball/d847795500b929f68ed115357658122d64017f77", - "reference": "d847795500b929f68ed115357658122d64017f77", + "url": "https://api.github.com/repos/symplify/easy-coding-standard/zipball/e34a105876b0640e70c584d75adaf9c0b03cf0f3", + "reference": "e34a105876b0640e70c584d75adaf9c0b03cf0f3", "shasum": "" }, "require": { - "php": ">=7.1" + "php": ">=7.2" }, "conflict": { "friendsofphp/php-cs-fixer": "<3.0", @@ -5944,7 +5944,7 @@ ], "description": "Prefixed scoped version of ECS package", "support": { - "source": "https://github.com/symplify/easy-coding-standard/tree/10.2.2" + "source": "https://github.com/symplify/easy-coding-standard/tree/10.2.7" }, "funding": [ { @@ -5956,7 +5956,7 @@ "type": "github" } ], - "time": "2022-04-17T10:41:19+00:00" + "time": "2022-05-21T11:14:40+00:00" } ], "aliases": [], @@ -5979,5 +5979,5 @@ "platform-overrides": { "php": "7.4" }, - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.2.0" } diff --git a/ecs.php b/ecs.php index 26ad8797..fb4efc59 100644 --- a/ecs.php +++ b/ecs.php @@ -2,16 +2,13 @@ declare(strict_types=1); -use PhpCsFixer\Fixer\ArrayNotation\ArraySyntaxFixer; use PhpCsFixer\Fixer\FunctionNotation\FunctionTypehintSpaceFixer; use PhpCsFixer\Fixer\Operator\NotOperatorWithSuccessorSpaceFixer; -use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; -use Symplify\EasyCodingStandard\ValueObject\Option; +use Symplify\EasyCodingStandard\Config\ECSConfig; use Symplify\EasyCodingStandard\ValueObject\Set\SetList; -return static function (ContainerConfigurator $containerConfigurator): void { - $parameters = $containerConfigurator->parameters(); - $parameters->set(Option::PATHS, [ +return static function (ECSConfig $ecsConfig): void { + $ecsConfig->paths([ __DIR__ . '/ecs.php', __DIR__ . '/config-templates', __DIR__ . '/hooks', @@ -20,28 +17,21 @@ __DIR__ . '/themes', __DIR__ . '/www', ]); - $parameters->set(Option::PARALLEL, true); - $parameters->set(Option::SKIP, [NotOperatorWithSuccessorSpaceFixer::class, FunctionTypehintSpaceFixer::class]); - $containerConfigurator->import(SetList::PHP_CS_FIXER); - $containerConfigurator->import(SetList::CLEAN_CODE); - $containerConfigurator->import(SetList::SYMPLIFY); - $containerConfigurator->import(SetList::ARRAY); - $containerConfigurator->import(SetList::COMMON); - $containerConfigurator->import(SetList::COMMENTS); - $containerConfigurator->import(SetList::CONTROL_STRUCTURES); - $containerConfigurator->import(SetList::DOCBLOCK); - $containerConfigurator->import(SetList::NAMESPACES); - $containerConfigurator->import(SetList::PHPUNIT); - $containerConfigurator->import(SetList::SPACES); - $containerConfigurator->import(SetList::STRICT); - $containerConfigurator->import(SetList::SYMFONY); - $containerConfigurator->import(SetList::PSR_12); + $ecsConfig->sets([ + SetList::CLEAN_CODE, + SetList::SYMPLIFY, + SetList::ARRAY, + SetList::COMMON, + SetList::COMMENTS, + SetList::CONTROL_STRUCTURES, + SetList::DOCBLOCK, + SetList::NAMESPACES, + SetList::PHPUNIT, + SetList::SPACES, + SetList::STRICT, + SetList::PSR_12, + ]); - $services = $containerConfigurator->services(); - $services->set(ArraySyntaxFixer::class) - ->call('configure', [[ - 'syntax' => 'short', - ]]) - ; + $ecsConfig->skip([NotOperatorWithSuccessorSpaceFixer::class, FunctionTypehintSpaceFixer::class]); }; diff --git a/hooks/hook_cron.php b/hooks/hook_cron.php index 9fd69ff1..aef86cb4 100644 --- a/hooks/hook_cron.php +++ b/hooks/hook_cron.php @@ -12,7 +12,7 @@ */ function perun_hook_cron(&$croninfo) { - if ('hourly' !== $croninfo['tag']) { + if ($croninfo['tag'] !== 'hourly') { Logger::debug('cron [perun]: Skipping cron in cron tag [' . $croninfo['tag'] . '] '); return; diff --git a/lib/Adapter.php b/lib/Adapter.php index 3c854d73..fd6b957e 100644 --- a/lib/Adapter.php +++ b/lib/Adapter.php @@ -37,10 +37,10 @@ public function getConnector() */ public static function getInstance($interface) { - if (self::RPC === $interface) { + if ($interface === self::RPC) { return new AdapterRpc(); } - if (self::LDAP === $interface) { + if ($interface === self::LDAP) { return new AdapterLdap(); } throw new Exception('Unknown perun interface. Hint: try ' . self::RPC . ' or ' . self::LDAP); diff --git a/lib/AdapterLdap.php b/lib/AdapterLdap.php index 488ff4b6..4ab93f78 100644 --- a/lib/AdapterLdap.php +++ b/lib/AdapterLdap.php @@ -67,7 +67,7 @@ class AdapterLdap extends Adapter public function __construct($configFileName = null) { - if (null === $configFileName) { + if ($configFileName === null) { $configFileName = self::DEFAULT_CONFIG_FILE_NAME; } @@ -248,7 +248,7 @@ public function getGroupByName($vo, $name) '(&(objectClass=perunGroup)(perunUniqueGroupName=' . $name . '))', ['perunGroupId', 'cn', 'perunUniqueGroupName', 'perunVoId', 'uuid', 'description'] ); - if (null === $group) { + if ($group === null) { throw new Exception('Group with name: $name in VO: ' . $vo->getName() . ' does not exists in Perun LDAP.'); } @@ -269,7 +269,7 @@ public function getVoByShortName($voShortName) '(&(objectClass=perunVo)(o=' . $voShortName . '))', ['perunVoId', 'o', 'description'] ); - if (null === $vo) { + if ($vo === null) { throw new Exception('Vo with name: ' . $voShortName . ' does not exists in Perun LDAP.'); } @@ -284,7 +284,7 @@ public function getVoById($id) ['o', 'description'] ); - if (null === $vo) { + if ($vo === null) { throw new Exception('Vo with id: ' . $id . ' does not exists in Perun LDAP.'); } @@ -480,7 +480,7 @@ public function getUsersGroupsOnFacility($spEntityId, $userId) public function getUsersGroupsOnSp($facility, $userId) { - if (null === $facility) { + if ($facility === null) { return []; } $id = $facility->getId(); @@ -492,7 +492,7 @@ public function getUsersGroupsOnSp($facility, $userId) ); Logger::debug('Resources - ' . json_encode($resources)); - if (null === $resources) { + if ($resources === null) { throw new Exception('Service with ID: ' . $id . ' hasn\'t assigned any resource.'); } $resourcesString = '(|'; @@ -551,20 +551,20 @@ public function isUserInVo($user, $voShortName) } $vo = $this->getVoByShortName($voShortName); - if (null === $vo) { + if ($vo === null) { Logger::debug('isUserInVo - No VO found, returning false'); return false; } - return Member::VALID === $this->getMemberStatusByUserAndVo($user, $vo); + return $this->getMemberStatusByUserAndVo($user, $vo) === Member::VALID; } public function getResourceCapabilities($entityId, $userGroups) { $facility = $this->getFacilityByEntityId($entityId); - if (null === $facility) { + if ($facility === null) { return []; } @@ -620,7 +620,7 @@ public function getFacilityCapabilities($entityId) private function mapUser($user) { - if (null === $user) { + if ($user === null) { return null; } if (isset($user['displayName'][0])) { @@ -637,19 +637,19 @@ private function mapUser($user) private function resolveAttrValue($attrsNameTypeMap, $attrsFromLdap, $attr) { if (!array_key_exists($attr, $attrsFromLdap)) { - if (self::TYPE_BOOL === $attrsNameTypeMap[$attr][self::TYPE]) { + if ($attrsNameTypeMap[$attr][self::TYPE] === self::TYPE_BOOL) { return false; } - if (self::TYPE_MAP === $attrsNameTypeMap[$attr][self::TYPE] - || self::TYPE_DICTIONARY === $attrsNameTypeMap[$attr][self::TYPE] + if ($attrsNameTypeMap[$attr][self::TYPE] === self::TYPE_MAP + || $attrsNameTypeMap[$attr][self::TYPE] === self::TYPE_DICTIONARY ) { return []; } } else { - if (self::TYPE_MAP === $attrsNameTypeMap[$attr][self::TYPE]) { + if ($attrsNameTypeMap[$attr][self::TYPE] === self::TYPE_MAP) { return $attrsFromLdap[$attr]; } - if (self::TYPE_DICTIONARY === $attrsNameTypeMap[$attr][self::TYPE]) { + if ($attrsNameTypeMap[$attr][self::TYPE] === self::TYPE_DICTIONARY) { return $this->convertToMap($attrsFromLdap[$attr]); } diff --git a/lib/AdapterRpc.php b/lib/AdapterRpc.php index b418e60c..f590aa13 100644 --- a/lib/AdapterRpc.php +++ b/lib/AdapterRpc.php @@ -54,7 +54,7 @@ class AdapterRpc extends Adapter public function __construct($configFileName = null) { - if (null === $configFileName) { + if ($configFileName === null) { $configFileName = self::DEFAULT_CONFIG_FILE_NAME; } @@ -98,10 +98,10 @@ public function getPerunUser($idpEntityId, $uids) return new User($user['id'], $name); } catch (PerunException $e) { - if ('UserExtSourceNotExistsException' === $e->getName()) { + if ($e->getName() === 'UserExtSourceNotExistsException') { continue; } - if ('ExtSourceNotExistsException' === $e->getName()) { + if ($e->getName() === 'ExtSourceNotExistsException') { // Because use of original/source entityID as extSourceName continue; } @@ -205,7 +205,7 @@ public function getSpGroups(string $spEntityId): array { $facility = $this->getFacilityByEntityId($spEntityId); - if (null === $facility) { + if ($facility === null) { return []; } @@ -394,7 +394,7 @@ public function getUsersGroupsOnFacility($spEntityId, $userId) public function getUsersGroupsOnSp($facility, $userId) { - if (null === $facility) { + if ($facility === null) { return []; } @@ -412,7 +412,7 @@ public function getUsersGroupsOnSp($facility, $userId) foreach ($usersGroupsOnFacility as $usersGroupOnFacility) { if (isset($usersGroupOnFacility['attributes'][0]['friendlyName']) && - 'voShortName' === $usersGroupOnFacility['attributes'][0]['friendlyName']) { + $usersGroupOnFacility['attributes'][0]['friendlyName'] === 'voShortName') { $uniqueName = $usersGroupOnFacility['attributes'][0]['value'] . ':' . $usersGroupOnFacility['name']; array_push($groups, new Group( @@ -503,7 +503,7 @@ public function getMemberByUser($user, $vo) 'user' => $user->getId(), 'vo' => $vo->getId(), ]); - if (null === $member) { + if ($member === null) { throw new Exception( 'Member for User with name ' . $user->getName() . ' and Vo with shortName ' . $vo->getShortName() . 'does not exist in Perun!' ); @@ -522,13 +522,13 @@ public function isUserInVo($user, $voShortName) } $vo = $this->getVoByShortName($voShortName); - if (null === $vo) { + if ($vo === null) { Logger::debug('isUserInVo - No VO found, returning false'); return false; } - return Member::VALID === $this->getMemberStatusByUserAndVo($user, $vo); + return $this->getMemberStatusByUserAndVo($user, $vo) === Member::VALID; } /** @@ -653,7 +653,7 @@ public function getResourceCapabilities($entityId, $userGroups) { $facility = $this->getFacilityByEntityId($entityId); - if (null === $facility) { + if ($facility === null) { return []; } @@ -677,7 +677,7 @@ public function getResourceCapabilities($entityId, $userGroups) 'attributeName' => 'urn:perun:resource:attribute-def:def:capabilities', ])['value']; - if (null === $resourceCapabilities) { + if ($resourceCapabilities === null) { continue; } @@ -698,7 +698,7 @@ public function getFacilityCapabilities($entityId) { $facility = $this->getFacilityByEntityId($entityId); - if (null === $facility) { + if ($facility === null) { return []; } diff --git a/lib/AttributeUtils.php b/lib/AttributeUtils.php index 5049334d..374329da 100644 --- a/lib/AttributeUtils.php +++ b/lib/AttributeUtils.php @@ -127,7 +127,7 @@ private static function getConfig() Logger::warning('perun:AttributeUtils: missing or invalid perun_attributes.php config file'); } - if (null === $perunAttributesConfig) { + if ($perunAttributesConfig === null) { throw new Exception('perun:AttributeUtils: missing or invalid perun_attributes.php config file'); } diff --git a/lib/Auth/Process/AttributeMap.php b/lib/Auth/Process/AttributeMap.php index b276b76a..e68e1a9b 100644 --- a/lib/Auth/Process/AttributeMap.php +++ b/lib/Auth/Process/AttributeMap.php @@ -13,16 +13,23 @@ class AttributeMap extends \SimpleSAML\Auth\ProcessingFilter { public const MAP_ATTR_NAME = 'attrMapAttr'; + public const KEEP_SOURCE_ATTRIBUTES = 'keepSourceAttributes'; + public const ENTITY_ID = 'entityid'; + public const INTERFACE_PROPNAME = 'interface'; public const CLASS_PREFIX = 'perun:AttributeMap: '; + public const ATTRIBUTES = 'Attributes'; private $mapAttrName; + private $keepSourceAttributes; + private $entityId; + private $adapter; public function __construct($config, $reserved) @@ -45,7 +52,7 @@ public function __construct($config, $reserved) public function process(&$request) { - if (null === $this->entityId) { + if ($this->entityId === null) { $this->entityId = EntitlementUtils::getSpEntityId($request); } elseif (is_callable($this->entityId)) { $this->entityId = call_user_func($this->entityId, $request); @@ -55,7 +62,7 @@ public function process(&$request) $facility = $this->adapter->getFacilityByEntityId($this->entityId); - if (null === $facility) { + if ($facility === null) { Logger::info( self::CLASS_PREFIX . 'Facility with entityid ' . $this->entityId . ' not found. Skipping the filter' ); diff --git a/lib/Auth/Process/DropUserAttributes.php b/lib/Auth/Process/DropUserAttributes.php index b3113d37..6aa14c50 100644 --- a/lib/Auth/Process/DropUserAttributes.php +++ b/lib/Auth/Process/DropUserAttributes.php @@ -15,11 +15,13 @@ class DropUserAttributes extends ProcessingFilter { public const STAGE = 'perun:DropUserAttributes'; + public const DEBUG_PREFIX = self::STAGE . ' - '; public const ATTRIBUTE_NAMES = 'attribute_names'; private $attributeNames; + private $filterConfig; public function __construct($config, $reserved) diff --git a/lib/Auth/Process/EnsureVoMember.php b/lib/Auth/Process/EnsureVoMember.php index ebc8b749..080d6ce8 100644 --- a/lib/Auth/Process/EnsureVoMember.php +++ b/lib/Auth/Process/EnsureVoMember.php @@ -44,7 +44,7 @@ public function __construct($config, $reserved) parent::__construct($config, $reserved); $config = Configuration::loadFromArray($config); - if (null === $config) { + if ($config === null) { throw new Exception( 'perun:EnsureVoMember: Property \'' . self::ENSURE_VO_MEMBER . '\' is missing or invalid!' ); @@ -89,7 +89,7 @@ public function process(&$request) $facility = $this->adapter->getFacilityByEntityId($spEntityId); - if (null === $facility) { + if ($facility === null) { Logger::debug('perun:EnsureVoMember: skip execution - no facility provided'); return; @@ -101,7 +101,7 @@ public function process(&$request) ); $triggerAttrValue = $attrValues[$this->triggerAttr]; - if (null === $triggerAttrValue || false === $triggerAttrValue) { + if ($triggerAttrValue === null || $triggerAttrValue === false) { Logger::debug( 'perun:EnsureVoMember: skip execution - attribute ' . self::TRIGGER_ATTR . ' is null or false' ); diff --git a/lib/Auth/Process/ExtractRequestAttribute.php b/lib/Auth/Process/ExtractRequestAttribute.php index a0fdb645..8d7a9032 100644 --- a/lib/Auth/Process/ExtractRequestAttribute.php +++ b/lib/Auth/Process/ExtractRequestAttribute.php @@ -16,20 +16,29 @@ class ExtractRequestAttribute extends ProcessingFilter { public const STAGE = 'perun:ExtractRequestAttribute'; + public const DEBUG_PREFIX = self::STAGE . ' - '; public const DESTINATION_ATTRIBUTE_NAME = 'destination_attribute_name'; + public const REQUEST_KEYS = 'request_keys'; + public const FAIL_ON_NON_EXISTING_KEY = 'fail_on_not_existing_key'; + public const DEFAULT_VALUE = 'default_value'; public const KEYS_SEPARATOR = ';'; + public const FAILURE_VALUE = ['%$FAILURE_VALUE$%']; private $destinationAttrName; + private $requestKeys; + private $failOnNonExistingKey; + private $defaultValue; + private $filterConfig; public function __construct($config, $reserved) @@ -56,7 +65,7 @@ public function __construct($config, $reserved) $this->defaultValue = $this->filterConfig->getArray(self::DEFAULT_VALUE, self::FAILURE_VALUE); if ( !$this->failOnNonExistingKey - && self::FAILURE_VALUE === $this->defaultValue + && $this->defaultValue === self::FAILURE_VALUE ) { throw new Exception( self::DEBUG_PREFIX . 'invalid configuration, fail on missing key is disabled, but no default value ' . 'for the attribute has been set' @@ -86,7 +95,7 @@ public function process(&$request) $value = $value[$key]; } - if (self::FAILURE_VALUE === $value) { + if ($value === self::FAILURE_VALUE) { throw new Exception(self::DEBUG_PREFIX . 'Value cannot be extracted'); } diff --git a/lib/Auth/Process/ForceAup.php b/lib/Auth/Process/ForceAup.php index 6237fe1a..10fb3320 100644 --- a/lib/Auth/Process/ForceAup.php +++ b/lib/Auth/Process/ForceAup.php @@ -73,7 +73,7 @@ public function __construct($config, $reserved) $configuration = Configuration::loadFromArray($config); $this->perunAupsAttr = $configuration->getString(self::PERUN_AUPS_ATTR, null); $this->perunVoAupAttr = $configuration->getString(self::PERUN_VO_AUP_ATTR, null); - if (null === $this->perunAupsAttr && null === $this->perunVoAupAttr) { + if ($this->perunAupsAttr === null && $this->perunVoAupAttr === null) { throw new Exception( 'perun:ForceAup: missing at least one of mandatory configuration options \'' . self::PERUN_AUPS_ATTR . '\' or \'' . self::PERUN_VO_AUP_ATTR . '\'.' ); @@ -94,7 +94,7 @@ public function process(&$request) { assert(is_array($request)); - if (null === $this->entityId) { + if ($this->entityId === null) { $this->entityId = EntitlementUtils::getSpEntityId($request); } elseif (is_callable($this->entityId)) { $this->entityId = call_user_func($this->entityId, $request); @@ -120,7 +120,7 @@ public function process(&$request) try { $facility = $this->adapter->getFacilityByEntityId($this->entityId); - if (null === $facility) { + if ($facility === null) { return; } @@ -160,7 +160,7 @@ public function process(&$request) [$this->perunUserAupAttr] )[$this->perunUserAupAttr]; - if (null === $userAups) { + if ($userAups === null) { $userAups = []; } @@ -225,7 +225,7 @@ public function getVoAups($voShortNames) $vos = []; foreach ($voShortNames as $voShortName) { $vo = $this->adapter->getVoByShortName($voShortName); - if (null !== $vo) { + if ($vo !== null) { array_push($vos, $vo); } } @@ -233,7 +233,7 @@ public function getVoAups($voShortNames) $voAups = []; foreach ($vos as $vo) { $aups = $this->adapter->getVoAttributesValues($vo, [$this->perunVoAupAttr])[$this->perunVoAupAttr]; - if (null !== $aups) { + if ($aups !== null) { $voAups[$vo->getShortName()] = $aups; } } @@ -244,7 +244,7 @@ public function getVoAups($voShortNames) private function getPerunAups() { $perunAupsAttr = []; - if (null !== $this->perunAupsAttr) { + if ($this->perunAupsAttr !== null) { $perunAupsAttr = $this->adapter->getEntitylessAttribute($this->perunAupsAttr); } @@ -287,14 +287,14 @@ private function fillAupsToBeApproved($requestedAups, $aups, $userApprovedAups) } $decodedAups = json_decode($aupsInJson); $latestAup = $this->getLatestAup($decodedAups); - if (null === $latestAup) { + if ($latestAup === null) { continue; } if (!empty($userApprovedAups[$requestedAup])) { $userAupsList = json_decode($userApprovedAups[$requestedAup]); $userLatestAup = $this->getLatestAup($userAupsList); - if (null !== $userLatestAup) { + if ($userLatestAup !== null) { $latestDate = self::parseDateTime($latestAup->date); $userLatestDate = self::parseDateTime($userLatestAup->date); if ($userLatestDate >= $latestDate) { @@ -339,11 +339,11 @@ private function mergeAupsToBeApproved(array $perunAupsToBeApproved, array $voAu */ private function parseDateTime(string $date, DateTime $default = null): DateTime { - if (null === $default) { + if ($default === null) { $default = DateTime::createFromFormat(self::DATETIME_FORMAT, '1970-01-01'); } $result = DateTime::createFromFormat(self::DATETIME_FORMAT, $date); - if (false === $result) { + if ($result === false) { $result = $default; } diff --git a/lib/Auth/Process/GenerateIdPAttributes.php b/lib/Auth/Process/GenerateIdPAttributes.php index 8d17ebb8..da9784ad 100644 --- a/lib/Auth/Process/GenerateIdPAttributes.php +++ b/lib/Auth/Process/GenerateIdPAttributes.php @@ -18,16 +18,21 @@ class GenerateIdPAttributes extends ProcessingFilter { public const STAGE = 'perun:GenerateIdPAttributes'; + public const DEBUG_PREFIX = self::STAGE . ' - '; public const ATTRIBUTE_MAP = 'attribute_map'; + public const IDP_IDENTIFIER_ATTRIBUTE = 'idp_identifier_attribute'; public const SAML_SP_IDP = 'saml:sp:IdP'; + public const SAML20_IDP_REMOTE = 'saml20-idp-remote'; private $attributeMap; + private $idpIdentifierAttribute; + private $filterConfig; public function __construct($config, $reserved) diff --git a/lib/Auth/Process/PerunAttributes.php b/lib/Auth/Process/PerunAttributes.php index 1f9faa5c..9db695cd 100644 --- a/lib/Auth/Process/PerunAttributes.php +++ b/lib/Auth/Process/PerunAttributes.php @@ -75,9 +75,9 @@ public function process(&$request) } $attributes = []; - if (self::MODE_FULL === $this->mode) { + if ($this->mode === self::MODE_FULL) { $attributes = array_keys($this->attrMap); - } elseif (self::MODE_PARTIAL === $this->mode) { + } elseif ($this->mode === self::MODE_PARTIAL) { // Check if attribute has some value foreach ($this->attrMap as $attrName => $attrValue) { if (empty($attrValue)) { @@ -133,7 +133,7 @@ private function processAttributes(User $user, array $attributes): array $sspAttr = $this->attrMap[$attrName]; // convert $attrValue into array - if (null === $attrValue) { + if ($attrValue === null) { $value = []; } elseif (is_string($attrValue) || is_numeric($attrValue)) { $value = [$attrValue]; diff --git a/lib/Auth/Process/PerunAup.php b/lib/Auth/Process/PerunAup.php index 840ed6ea..37898f83 100644 --- a/lib/Auth/Process/PerunAup.php +++ b/lib/Auth/Process/PerunAup.php @@ -20,29 +20,45 @@ class PerunAup extends ProcessingFilter { public const STAGE = 'perun:PerunAup'; + public const DEBUG_PREFIX = self::STAGE . ' - '; public const CALLBACK = 'perun/perun_aup_callback.php'; + public const REDIRECT = 'perun/perun_aup.php'; + public const TEMPLATE = 'perun:perun-aup-tpl.php'; public const PARAM_STATE_ID = PerunConstants::STATE_ID; + public const PARAM_APPROVAL_URL = 'approvalUrl'; public const INTERFACE = 'interface'; + public const AUP_ATTR = 'attribute'; + public const AUP_VALUE = 'value'; + public const APPROVAL_URL = 'approval_url'; + public const CALLBACK_PARAMETER_NAME = 'callback_parameter_name'; + public const PERUN_APPROVAL_URL = 'perun_approval_url'; private $adapter; + private $aupAttr; + private $aupValue; + private $approvalUrl; + private $callbackParameterName; + private $perunApprovalUrl; + private $config; + private $filterConfig; public function __construct($config, $reserved) diff --git a/lib/Auth/Process/PerunEnsureMember.php b/lib/Auth/Process/PerunEnsureMember.php index 93c04d28..e2926cff 100644 --- a/lib/Auth/Process/PerunEnsureMember.php +++ b/lib/Auth/Process/PerunEnsureMember.php @@ -20,27 +20,43 @@ class PerunEnsureMember extends ProcessingFilter public const LOG_PREFIX = 'perun:PerunEnsureMember: '; public const REGISTER_URL = 'registerUrl'; + public const VO_SHORT_NAME = 'voShortName'; + public const GROUP_NAME = 'groupName'; + public const INTERFACE_PROPNAME = 'interface'; + public const CALLBACK_PARAMETER_NAME = 'callbackParameterName'; + public const RPC = 'rpc'; public const CALLBACK = 'perun/perun_ensure_member_callback.php'; + public const REDIRECT = 'perun/perun_ensure_member.php'; public const STAGE = 'perun:PerunEnsureMember'; + public const PARAM_STATE_ID = PerunConstants::STATE_ID; + public const PARAM_REGISTRATION_URL = 'registrationUrl'; + public const TEMPLATE = 'perun:perun-ensure-member-tpl.php'; private $config; + private $filterConfig; + private $registerUrl; + private $voShortName; + private $groupName; + private $callbackParameterName; + private $adapter; + private $rpcAdapter; public function __construct($config, $reserved) @@ -85,7 +101,7 @@ public function process(&$request) } $vo = $this->adapter->getVoByShortName($this->voShortName); - if (null === $vo) { + if ($vo === null) { throw new Exception(self::LOG_PREFIX . 'VO with voShortName \'' . self::VO_SHORT_NAME . '\' not found.'); } @@ -98,7 +114,7 @@ private function handleUser($user, $vo, $request): void $isUserInGroup = empty($this->groupName) || $this->isUserInGroup($this->groupName, $user, $vo); $memberStatus = $this->adapter->getMemberStatusByUserAndVo($user, $vo); - if (Member::VALID === $memberStatus && $isUserInGroup) { + if ($memberStatus === Member::VALID && $isUserInGroup) { Logger::debug(self::LOG_PREFIX . 'User is allowed to continue'); return; @@ -108,27 +124,27 @@ private function handleUser($user, $vo, $request): void $voHasRegistrationForm = $this->rpcAdapter->hasRegistrationForm($vo->getId(), PerunConstants::VO); $groupHasRegistrationForm = !empty($this->groupName) && $this->groupHasRegistrationForm($vo, $this->groupName); - if (Member::VALID === $memberStatus && $isUserInGroup) { + if ($memberStatus === Member::VALID && $isUserInGroup) { Logger::debug(self::LOG_PREFIX . 'User is allowed to continue'); - } elseif (Member::VALID === $memberStatus && !$isUserInGroup && $groupHasRegistrationForm) { + } elseif ($memberStatus === Member::VALID && !$isUserInGroup && $groupHasRegistrationForm) { Logger::debug( self::LOG_PREFIX . 'User is not valid in group ' . $this->groupName . ' - sending to registration' ); $this->register($request, $this->groupName); - } elseif (null === $memberStatus && $voHasRegistrationForm && $isUserInGroup) { + } elseif ($memberStatus === null && $voHasRegistrationForm && $isUserInGroup) { Logger::debug( self::LOG_PREFIX . 'User is not member of vo ' . $this->voShortName . ' - sending to registration' ); $this->register($request); - } elseif (null === $memberStatus && $voHasRegistrationForm && !$isUserInGroup && $groupHasRegistrationForm) { + } elseif ($memberStatus === null && $voHasRegistrationForm && !$isUserInGroup && $groupHasRegistrationForm) { Logger::debug( self::LOG_PREFIX . 'User is not member of vo ' . $this->voShortName . ' - sending to registration' ); $this->register($request, $this->groupName); - } elseif (Member::EXPIRED === $memberStatus && $voHasRegistrationForm && $isUserInGroup) { + } elseif ($memberStatus === Member::EXPIRED && $voHasRegistrationForm && $isUserInGroup) { Logger::debug(self::LOG_PREFIX . 'User is expired - sending to registration'); $this->register($request); - } elseif (Member::EXPIRED === $memberStatus && $voHasRegistrationForm && !$isUserInGroup && $groupHasRegistrationForm) { + } elseif ($memberStatus === Member::EXPIRED && $voHasRegistrationForm && !$isUserInGroup && $groupHasRegistrationForm) { Logger::debug( self::LOG_PREFIX . 'User is expired and is not in group ' . $this->groupName . ' - sending to registration' ); @@ -162,7 +178,7 @@ private function groupHasRegistrationForm($vo, $groupName): bool $group = null; } - if (null !== $group) { + if ($group !== null) { return $this->rpcAdapter->hasRegistrationForm($group->getId(), PerunConstants::GROUP); } @@ -183,7 +199,7 @@ private function register(array &$request, $groupName = null): void if (!empty($this->callbackParameterName)) { $registrationUrl = $this->registerUrl . '?vo=' . $this->voShortName; - if (null !== $groupName) { + if ($groupName !== null) { $registrationUrl .= '&group=' . $groupName; } diff --git a/lib/Auth/Process/PerunEntitlement.php b/lib/Auth/Process/PerunEntitlement.php index 4c3cbc9c..170b9faa 100644 --- a/lib/Auth/Process/PerunEntitlement.php +++ b/lib/Auth/Process/PerunEntitlement.php @@ -94,7 +94,7 @@ public function process(&$request) $capabilities = []; $forwardedEduPersonEntitlement = []; - if (null === $this->entityId) { + if ($this->entityId === null) { $this->entityId = EntitlementUtils::getSpEntityId($request); } elseif (is_callable($this->entityId)) { $this->entityId = call_user_func($this->entityId, $request); diff --git a/lib/Auth/Process/PerunEntitlementExtended.php b/lib/Auth/Process/PerunEntitlementExtended.php index fb5c17cb..95e6a589 100644 --- a/lib/Auth/Process/PerunEntitlementExtended.php +++ b/lib/Auth/Process/PerunEntitlementExtended.php @@ -94,7 +94,7 @@ public function process(&$request) $capabilities = []; $forwardedEduPersonEntitlement = []; - if (null === $this->entityId) { + if ($this->entityId === null) { $this->entityId = EntitlementUtils::getSpEntityId($request); } elseif (is_callable($this->entityId)) { $this->entityId = call_user_func($this->entityId, $request); diff --git a/lib/Auth/Process/PerunIdentity.php b/lib/Auth/Process/PerunIdentity.php index c4c91c5e..fdef08ad 100644 --- a/lib/Auth/Process/PerunIdentity.php +++ b/lib/Auth/Process/PerunIdentity.php @@ -153,41 +153,41 @@ public function __construct($config, $reserved) $this->mode = $config->getValueValidate(self::MODE, self::MODES, self::MODE_FULL); - if (null === $this->uidsAttr) { + if ($this->uidsAttr === null) { throw new Exception('perun:PerunIdentity: missing mandatory config option \'' . self::UIDS_ATTR . '\'.'); } - if (self::MODE_FULL === $this->mode && empty($this->registerUrlBase)) { + if ($this->mode === self::MODE_FULL && empty($this->registerUrlBase)) { throw new Exception( 'perun:PerunIdentity: missing mandatory config option \'' . self::REGISTER_URL_BASE . '\'.' ); } - if (self::MODE_FULL === $this->mode && empty($this->defaultRegisterUrl)) { + if ($this->mode === self::MODE_FULL && empty($this->defaultRegisterUrl)) { throw new Exception('perun:PerunIdentity: missing mandatory config option \'' . self::REGISTER_URL . '\'.'); } - if (self::MODE_FULL === $this->mode && empty($this->voShortName)) { + if ($this->mode === self::MODE_FULL && empty($this->voShortName)) { throw new Exception('perun:PerunIdentity: missing mandatory config option \'' . self::VO_SHORTNAME . '\'.'); } - if (self::MODE_FULL === $this->mode && empty($this->facilityCheckGroupMembershipAttr)) { + if ($this->mode === self::MODE_FULL && empty($this->facilityCheckGroupMembershipAttr)) { throw new Exception( 'perun:PerunIdentity: missing mandatory config option \'' . self::PERUN_FACILITY_CHECK_GROUP_MEMBERSHIP_ATTR . '\'.' ); } - if (self::MODE_FULL === $this->mode && empty($this->facilityDynamicRegistrationAttr)) { + if ($this->mode === self::MODE_FULL && empty($this->facilityDynamicRegistrationAttr)) { throw new Exception( 'perun:PerunIdentity: missing mandatory config option \'' . self::PERUN_FACILITY_DYNAMIC_REGISTRATION_ATTR . '\'.' ); } - if (self::MODE_FULL === $this->mode && empty($this->facilityVoShortNamesAttr)) { + if ($this->mode === self::MODE_FULL && empty($this->facilityVoShortNamesAttr)) { throw new Exception( 'perun:PerunIdentity: missing mandatory config option \'' . self::PERUN_FACILITY_VO_SHORT_NAMES_ATTR . '\'.' ); } - if (self::MODE_FULL === $this->mode && empty($this->facilityRegisterUrlAttr)) { + if ($this->mode === self::MODE_FULL && empty($this->facilityRegisterUrlAttr)) { throw new Exception( 'perun:PerunIdentity: missing mandatory config option \'' . self::PERUN_FACILITY_REGISTER_URL_ATTR . '\'.' ); } - if (self::MODE_FULL === $this->mode && empty($this->facilityAllowRegistrationToGroupsAttr)) { + if ($this->mode === self::MODE_FULL && empty($this->facilityAllowRegistrationToGroupsAttr)) { throw new Exception( "perun:PerunIdentity: missing mandatory config option '" . self::PERUN_FACILITY_ALLOW_REGISTRATION_TO_GROUPS . "'." ); @@ -195,7 +195,7 @@ public function __construct($config, $reserved) $this->useAdditionalIdentifiersLookup = $config->getBoolean(self::USE_ADDITIONAL_IDENTIFIERS_LOOKUP, false); $this->additionalIdentifiersAttribute = $config->getString(self::ADDITIONAL_IDENTIFIERS_ATTRIBUTE, null); - if ($this->useAdditionalIdentifiersLookup && null === $this->additionalIdentifiersAttribute) { + if ($this->useAdditionalIdentifiersLookup && $this->additionalIdentifiersAttribute === null) { throw new Exception( 'perun:PerunIdentity: Invalid configuration: no attribute configured for extracting additional identifiers. Use option \'' . self::ADDITIONAL_IDENTIFIERS_ATTRIBUTE . '\' to configure the name of the attribute, that should be considered as additional identifiers of the user.' ); @@ -248,7 +248,7 @@ public function process(&$request) $groups = []; $user = $this->adapter->getPerunUser($idpEntityId, $uids); - if ($this->useAdditionalIdentifiersLookup && null === $user) { + if ($this->useAdditionalIdentifiersLookup && $user === null) { $additionalIdentifiers = $request[PerunConstants::ATTRIBUTES][$this->additionalIdentifiersAttribute] ?? null; if (empty($additionalIdentifiers)) { throw new Exception( @@ -258,7 +258,7 @@ public function process(&$request) $user = $this->adapter->getPerunUserByAdditionalIdentifiers($idpEntityId, $additionalIdentifiers); } - if (self::MODE_FULL === $this->mode) { + if ($this->mode === self::MODE_FULL) { $this->getSPAttributes($this->spEntityId); $this->checkMemberStateDefaultVo($request, $user, $uids); @@ -293,7 +293,7 @@ public function process(&$request) ' has been found and SP has sufficient rights to get info about him. ' . 'User ' . $user->getName() . ' with id: ' . $user->getId() . ' is being set to request' ); - } elseif (self::MODE_USERONLY === $this->mode) { + } elseif ($this->mode === self::MODE_USERONLY) { if (isset($user)) { Logger::info( 'Perun user with identity/ies: ' . implode(',', $uids) . @@ -326,11 +326,11 @@ public function process(&$request) */ public function register($request, $vosForRegistration, $registerUrL = null, $dynamicRegistration = null) { - if (null === $registerUrL) { + if ($registerUrL === null) { $registerUrL = $this->registerUrl; } - if (null === $dynamicRegistration) { + if ($dynamicRegistration === null) { $dynamicRegistration = $this->dynamicRegistration; } @@ -407,9 +407,9 @@ public static function unauthorized($request) protected function registerDirectly($request, $callback, $registerUrL, $vo = null, $group = null) { $params = []; - if (null !== $vo) { + if ($vo !== null) { $params['vo'] = $vo->getShortName(); - if (null !== $group) { + if ($group !== null) { $params['group'] = $group->getName(); } } @@ -485,7 +485,7 @@ protected function getSPAttributes($spEntityID) try { $facility = $this->adapter->getFacilityByEntityId($spEntityID); - if (null === $facility) { + if ($facility === null) { return; } @@ -508,7 +508,7 @@ protected function getSPAttributes($spEntityID) $this->registerUrl = $facilityAttrValues[(string) $this->facilityRegisterUrlAttr]; } - if (null === $this->registerUrl) { + if ($this->registerUrl === null) { $this->registerUrl = $this->defaultRegisterUrl; } @@ -531,18 +531,18 @@ protected function checkMemberStateDefaultVo($request, $user, $uids) $status = null; try { $vo = $this->adapter->getVoByShortName($this->voShortName); - if (null !== $user) { + if ($user !== null) { $status = $this->adapter->getMemberStatusByUserAndVo($user, $vo); } } catch (\Exception $ex) { throw new Exception('perun:PerunIdentity: ' . $ex); } - if (null === $vo) { + if ($vo === null) { throw new Exception('perun:PerunIdentity: Vo with short name ' . $this->voShortName . ' does not exist.'); } - if ($this->adapter instanceof AdapterLdap && Member::INVALID === $status) { + if ($this->adapter instanceof AdapterLdap && $status === Member::INVALID) { try { $status = $this->rpcAdapter->getMemberStatusByUserAndVo($user, $vo); } catch (\Exception $ex) { @@ -554,13 +554,13 @@ protected function checkMemberStateDefaultVo($request, $user, $uids) } } - if (null === $user || null === $status || Member::EXPIRED === $status) { - if (null === $user) { + if ($user === null || $status === null || $status === Member::EXPIRED) { + if ($user === null) { Logger::info( 'Perun user with identity/ies: ' . implode(',', $uids) . ' ' . 'has NOT been found. He is being redirected to register.' ); - } elseif (null === $status) { + } elseif ($status === null) { Logger::info( 'Perun user with identity/ies: ' . implode(',', $uids) . ' ' . 'is NOT member in vo with short name ' . $this->voShortName . @@ -573,7 +573,7 @@ protected function checkMemberStateDefaultVo($request, $user, $uids) ); } $this->register($request, [$vo], $this->defaultRegisterUrl, false); - } elseif (!(Member::VALID === $status)) { + } elseif (!($status === Member::VALID)) { Logger::warning( 'Member status for perun user with identity/ies: ' . implode(',', $uids) . ' ' . 'was INVALID/SUSPENDED/DISABLED. ' @@ -610,8 +610,8 @@ protected function getVosForRegistration($user) } foreach ($members as $member) { - if (Member::VALID === $member->getStatus() || - Member::EXPIRED === $member->getStatus()) { + if ($member->getStatus() === Member::VALID || + $member->getStatus() === Member::EXPIRED) { array_push($vosIdForRegistration, $member->getVoId()); } } diff --git a/lib/Auth/Process/PerunUser.php b/lib/Auth/Process/PerunUser.php index fd728eaf..d14fb8b9 100644 --- a/lib/Auth/Process/PerunUser.php +++ b/lib/Auth/Process/PerunUser.php @@ -23,33 +23,53 @@ class PerunUser extends ProcessingFilter { public const STAGE = 'perun:PerunUser'; + public const DEBUG_PREFIX = self::STAGE . ' - '; public const CALLBACK = 'perun/perun_user_callback.php'; + public const REDIRECT = 'perun/perun_user.php'; + public const TEMPLATE = 'perun:perun-user-tpl.php'; public const PARAM_REGISTRATION_URL = 'registrationUrl'; + public const PARAM_STATE_ID = PerunConstants::STATE_ID; public const INTERFACE = 'interface'; + public const UID_ATTRS = 'uid_attrs'; + public const IDP_ID_ATTR = 'idp_id_attr'; + public const REGISTER_URL = 'register_url'; + public const CALLBACK_PARAMETER_NAME = 'callback_parameter_name'; + public const PERUN_REGISTER_URL = 'perun_register_url'; + public const USE_ADDITIONAL_IDENTIFIERS_LOOKUP = 'use_additional_identifiers_lookup'; + public const ADDITIONAL_IDENTIFIERS_ATTRIBUTE = 'additional_identifiers_attribute'; private $adapter; + private $idpEntityIdAttr; + private $userIdAttrs; + private $registerUrl; + private $callbackParameterName; + private $perunRegisterUrl; + private $useAdditionalIdentifiersLookup; + private $additionalIdentifiersAttribute; + private $config; + private $filterConfig; public function __construct($config, $reserved) @@ -90,7 +110,7 @@ public function __construct($config, $reserved) self::ADDITIONAL_IDENTIFIERS_ATTRIBUTE, null ); - if ($this->useAdditionalIdentifiersLookup && null === $this->additionalIdentifiersAttribute) { + if ($this->useAdditionalIdentifiersLookup && $this->additionalIdentifiersAttribute === null) { throw new Exception( self::DEBUG_PREFIX . 'Invalid configuration: no attribute configured for extracting additional identifiers. Use option \'' . self::ADDITIONAL_IDENTIFIERS_ATTRIBUTE . '\' to configure the name of the attribute, that should be considered as additional identifiers of the user.' ); @@ -124,7 +144,7 @@ public function process(&$request) } $user = $this->adapter->getPerunUser($idpEntityId, $uids); - if ($this->useAdditionalIdentifiersLookup && null === $user) { + if ($this->useAdditionalIdentifiersLookup && $user === null) { $additionalIdentifiers = $request[PerunConstants::ATTRIBUTES][$this->additionalIdentifiersAttribute] ?? null; if (empty($additionalIdentifiers)) { throw new Exception( diff --git a/lib/Auth/Process/PerunUserGroups.php b/lib/Auth/Process/PerunUserGroups.php index 9ffa0bed..efbc9440 100644 --- a/lib/Auth/Process/PerunUserGroups.php +++ b/lib/Auth/Process/PerunUserGroups.php @@ -19,6 +19,7 @@ class PerunUserGroups extends ProcessingFilter { public const STAGE = 'perun:PerunUserGroups'; + public const DEBUG_PREFIX = self::STAGE . ' - '; public const INTERFACE = 'interface'; diff --git a/lib/Auth/Process/ProcessTargetedID.php b/lib/Auth/Process/ProcessTargetedID.php index a3e985b4..4fcc0bac 100644 --- a/lib/Auth/Process/ProcessTargetedID.php +++ b/lib/Auth/Process/ProcessTargetedID.php @@ -53,7 +53,7 @@ public function process(&$request) } // Do not continue if we have user id with scope - if (false !== strpos($uid, '@')) { + if (strpos($uid, '@') !== false) { return; } diff --git a/lib/Auth/Process/ProxyFilter.php b/lib/Auth/Process/ProxyFilter.php index 613c000d..413c0fb2 100644 --- a/lib/Auth/Process/ProxyFilter.php +++ b/lib/Auth/Process/ProxyFilter.php @@ -72,7 +72,7 @@ public function process(&$request) { assert(is_array($request)); - $default = self::MODE_BLACKLIST === $this->mode; + $default = $this->mode === self::MODE_BLACKLIST; $shouldRun = $this->shouldRunForSP($request['Destination']['entityid'], $default); if ($shouldRun === $default) { $shouldRun = $this->shouldRunForAttribute($request['Attributes'], $default); @@ -80,7 +80,7 @@ public function process(&$request) if ($shouldRun) { $this->processState($request); - } elseif (self::MODE_WHITELIST === $this->mode) { + } elseif ($this->mode === self::MODE_WHITELIST) { Logger::info( sprintf( 'perun.ProxyFilter: Not running filter %s for SP %s', @@ -179,7 +179,7 @@ private static function parseFilterList($filterSrc) * * @param array $config array with the authentication processing filter configuration * @param int $priority The priority of the current filter, (not included in the filter - * definition.) + * definition.) * * @return ProcessingFilter the parsed filter */ diff --git a/lib/Auth/Process/QualifyNameID.php b/lib/Auth/Process/QualifyNameID.php index 7347ab36..9d6aa812 100644 --- a/lib/Auth/Process/QualifyNameID.php +++ b/lib/Auth/Process/QualifyNameID.php @@ -17,20 +17,29 @@ class QualifyNameID extends ProcessingFilter { public const STAGE = 'perun:QualifyNameID'; + public const DEBUG_PREFIX = self::STAGE . ' - '; public const NAME_ID_CLASS = 'SAML2\XML\saml\NameID'; public const NAME_ID_ATTRIBUTE = 'name_id_attribute'; + public const NAME_QUALIFIER = 'name_qualifier'; + public const NAME_QUALIFIER_ATTRIBUTE = 'name_qualifier_attribute'; + public const SP_NAME_QUALIFIER = 'sp_name_qualifier'; + public const SP_NAME_QUALIFIER_ATTRIBUTE = 'sp_name_qualifier_attribute'; private $targetedIdAttribute; + private $nameQualifier; + private $nameQualifierAttribute; + private $spNameQualifier; + private $spNameQualifierAttribute; public function __construct($config, $reserved) @@ -69,7 +78,7 @@ public function process(&$request) if (!empty($request[PerunConstants::ATTRIBUTES][$this->targetedIdAttribute])) { $attributeValue = &$request[PerunConstants::ATTRIBUTES][$this->targetedIdAttribute][0]; - if (self::NAME_ID_CLASS === get_class($attributeValue)) { + if (get_class($attributeValue) === self::NAME_ID_CLASS) { $nameQualifier = $request[PerunConstants::ATTRIBUTES][$this->nameQualifierAttribute][0] ?? $this->nameQualifier; if (empty($nameQualifier)) { throw new Exception(self::DEBUG_PREFIX . 'NameQualifier is not available'); diff --git a/lib/Auth/Process/SpAuthorization.php b/lib/Auth/Process/SpAuthorization.php index 34abe2ea..08bf4f3a 100644 --- a/lib/Auth/Process/SpAuthorization.php +++ b/lib/Auth/Process/SpAuthorization.php @@ -37,48 +37,79 @@ class SpAuthorization extends ProcessingFilter { public const STAGE = 'perun:SpAuthorization'; + public const DEBUG_PREFIX = self::STAGE . ' - '; public const CALLBACK = 'perun/sp_authorization_callback.php'; + public const REDIRECT_NOTIFY = 'perun/sp_authorization_notify.php'; + public const TEMPLATE_NOTIFY = 'perun:sp-authorization-notify-tpl.php'; + public const REDIRECT_SELECT = 'perun/sp_authorization_select.php'; + public const TEMPLATE_SELECT = 'perun:sp-authorization-select-tpl.php'; + public const REDIRECT_403 = 'perun/sp_authorization_403.php'; + public const TEMPLATE_403 = 'perun:sp-authorization-403-tpl.php'; public const REDIRECT_PARAMS = 'redirect_params'; public const PARAM_STATE_ID = PerunConstants::STATE_ID; + public const PARAM_SP_METADATA = PerunConstants::SP_METADATA; + public const PARAM_REGISTRATION_URL = 'registrationUrl'; + public const PARAM_REGISTRATION_DATA = 'registrationData'; + public const PARAM_CALLBACK = 'callback'; public const INTERFACE = 'interface'; + public const REGISTRAR_URL = 'registrar_url'; + public const CHECK_GROUP_MEMBERSHIP_ATTR = 'check_group_membership_attr'; + public const VO_SHORT_NAMES_ATTR = 'vo_short_names_attr'; + public const HANDLE_UNSATISFIED_MEMBERSHIP = 'handle_unsatisfied_membership'; + public const REGISTRATION_LINK_ATTR = 'registration_link_attr'; + public const ALLOW_REGISTRATION_ATTR = 'allow_registration_attr'; public const SKIP_NOTIFICATION_SPS = 'skip_notification_sps'; + public const CHECK_GROUP_MEMBERSHIP = 'check_group_membership'; + public const VO_SHORT_NAMES = 'vo_short_names'; + public const ALLOW_REGISTRATION = 'allow_registration'; + public const REGISTRATION_LINK = 'registration_link'; private $adapter; + private $rpcAdapter; + private $checkGroupMembershipAttr; + private $voShortNamesAttr; + private $allowRegistrationAttr; + private $registrationLinkAttr; + private $skipNotificationSps; + private $handleUnsatisfiedMembership; + private $registrarUrl; + private $config; + private $filterConfig; public function __construct($config, $reserved) @@ -147,7 +178,7 @@ public function process(&$request) } $user = $request[PerunConstants::PERUN][PerunConstants::USER]; $facility = $this->adapter->getFacilityByEntityId($spEntityId); - if (null === $facility) { + if ($facility === null) { Logger::debug( self::DEBUG_PREFIX . 'No facility found for SP \'' . $spEntityId . '\', skip processing filter' ); @@ -249,7 +280,7 @@ public function handleUnsatisfiedMembership( public function register(array $request, array $registrationData, bool $skipNotification) { - $singleRegistration = 1 === count($registrationData); + $singleRegistration = count($registrationData) === 1; if ($singleRegistration) { Logger::debug( self::DEBUG_PREFIX . 'Registration possible to only single VO and GROUP, ' @@ -323,7 +354,7 @@ protected function registerDirectly(array &$request, Group $group, bool $skipNot $nameParts = explode(':', $group->getUniqueName(), 2); $params[PerunConstants::VO] = $nameParts[0]; - if (!empty($group) && PerunConstants::GROUP_MEMBERS !== $nameParts[1]) { + if (!empty($group) && $nameParts[1] !== PerunConstants::GROUP_MEMBERS) { $params[PerunConstants::GROUP] = $nameParts[1]; } $params[PerunConstants::TARGET_NEW] = $callback; @@ -373,7 +404,7 @@ private function getRegistrationData( string $spEntityId, array $facilityAttributes ): array { - if (null === $this->rpcAdapter) { + if ($this->rpcAdapter === null) { throw new Exception(self::DEBUG_PREFIX . 'No RPC adapter available, cannot fetch registration data'); } $voShortNames = $facilityAttributes[self::VO_SHORT_NAMES]; @@ -402,14 +433,14 @@ private function getRegistrationVoShortNames(User $user, array $voShortNames): a continue; } $member = $this->rpcAdapter->getMemberByUser($user, $vo); - if (Member::VALID === $member->getStatus()) { + if ($member->getStatus() === Member::VALID) { // VALID HERE, CAN REGISTER INTO GROUPS $activeMemberVos[] = $voShortName; Logger::debug( self::DEBUG_PREFIX . 'User is valid in VO with short name \'' . $voShortName . '\', groups of this VO will be included in registration list.' ); - } elseif (Member::EXPIRED === $member->getStatus()) { + } elseif ($member->getStatus() === Member::EXPIRED) { // EXPIRED HERE, LETS CHECK IF IT HAS REG. FORM SO MEMBERSHIP CAN BE EXTENDED Logger::debug( self::DEBUG_PREFIX . 'User is expired in the VO with short name \'' . $voShortName @@ -463,7 +494,7 @@ private function getRegistrationGroups(Facility $facility, array $voShortNames): continue; } - if (PerunConstants::GROUP_MEMBERS === $groupName) { + if ($groupName === PerunConstants::GROUP_MEMBERS) { // this is covered by the VO, which has got the reg. form instead of this group Logger::debug( self::DEBUG_PREFIX . 'Group \'' . $group->getUniqueName() . '\' added to the registration list.' diff --git a/lib/Auth/Process/StringifyTargetedID.php b/lib/Auth/Process/StringifyTargetedID.php index 28f9df02..fa21cd25 100644 --- a/lib/Auth/Process/StringifyTargetedID.php +++ b/lib/Auth/Process/StringifyTargetedID.php @@ -55,7 +55,7 @@ public function process(&$request) */ private function stringify(NameID $attributeValue) { - if (is_object($attributeValue) && 'SAML2\XML\saml\NameID' === get_class($attributeValue)) { + if (is_object($attributeValue) && get_class($attributeValue) === 'SAML2\XML\saml\NameID') { return $attributeValue->getNameQualifier() . '!' . $attributeValue->getSPNameQualifier() . '!' . $attributeValue->getValue(); } diff --git a/lib/Auth/Process/WarningTestSP.php b/lib/Auth/Process/WarningTestSP.php index 4a62e176..cd1f1688 100644 --- a/lib/Auth/Process/WarningTestSP.php +++ b/lib/Auth/Process/WarningTestSP.php @@ -39,7 +39,7 @@ public function __construct($config, $reserved) public function process(&$request) { - if (isset($request['SPMetadata']['test.sp']) && true === $request['SPMetadata']['test.sp']) { + if (isset($request['SPMetadata']['test.sp']) && $request['SPMetadata']['test.sp'] === true) { $id = State::saveState($request, 'perun:warningTestSP'); $url = Module::getModuleURL('perun/warning_test_sp_page.php'); HTTP::redirectTrustedURL($url, [ diff --git a/lib/Consent.php b/lib/Consent.php index 8a190c1a..12269bd4 100644 --- a/lib/Consent.php +++ b/lib/Consent.php @@ -73,7 +73,7 @@ public static function perunPresentAttributes($t, $attributes, $nameParent, $lab public static function presentAttributesPhotoOrValue($nameraw, $listitem) { - if ('jpegPhoto' === $nameraw) { + if ($nameraw === 'jpegPhoto') { return 'User photo'; } diff --git a/lib/Disco.php b/lib/Disco.php index 59fc83d0..81eaf898 100644 --- a/lib/Disco.php +++ b/lib/Disco.php @@ -197,7 +197,7 @@ public function __construct(array $metadataSets, $instance) $this->authId = $id; $state = State::loadState($id, self::SAML_SP_SSO, true); - if (null !== $state) { + if ($state !== null) { if (isset($state[self::SAML_REQUESTED_AUTHN_CONTEXT][self::AUTHN_CONTEXT_CLASS_REF])) { $this->originalAuthnContextClassRef = $state[self::SAML_REQUESTED_AUTHN_CONTEXT][self::AUTHN_CONTEXT_CLASS_REF]; @@ -236,14 +236,14 @@ public function handleRequest() // no choice possible. Show discovery service page $idpList = $this->getIdPList(); if (isset($this->originalsp[self::METADATA_ADD_INSTITUTION_APP]) - && true === $this->originalsp[self::METADATA_ADD_INSTITUTION_APP] + && $this->originalsp[self::METADATA_ADD_INSTITUTION_APP] === true ) { $idpList = $this->filterAddInstitutionList($idpList); } else { $idpList = $this->filterList($idpList); } - if (1 === sizeof($idpList)) { + if (sizeof($idpList) === 1) { $idp = array_keys($idpList)[0]; $url = self::buildContinueUrl($this->spEntityId, $this->returnURL, $this->returnIdParam, $idp); Logger::info('perun.Disco: Only one Idp left. Redirecting automatically. IdP: ' . $idp); @@ -255,12 +255,12 @@ public function handleRequest() // IF IS SET AUTHN CONTEXT CLASS REF, REDIRECT USER TO THE IDP if (isset($this->originalAuthnContextClassRef)) { - if (null !== $this->originalAuthnContextClassRef) { + if ($this->originalAuthnContextClassRef !== null) { // Check authnContextClassRef and select IdP directly if the correct value is set foreach ($this->originalAuthnContextClassRef as $value) { // VERIFY THE PREFIX IS CORRECT AND WE CAN PERFORM THE REDIRECT $acrStartSubstr = substr($value, 0, strlen(self::URN_CESNET_PROXYIDP_IDPENTITYID)); - if (self::URN_CESNET_PROXYIDP_IDPENTITYID === $acrStartSubstr) { + if ($acrStartSubstr === self::URN_CESNET_PROXYIDP_IDPENTITYID) { $idpEntityId = substr($value, strlen(self::URN_CESNET_PROXYIDP_IDPENTITYID), strlen($value)); if ($idpEntityId === $this->proxyIdpEntityId) { continue; @@ -477,7 +477,7 @@ public static function showTaggedEntry(DiscoTemplate $t, array $metadata, string public static function getOr($id = null): string { $or = ''; - if (null !== $id) { + if ($id !== null) { $or .= '
' . PHP_EOL; } else { $or .= '
' . PHP_EOL; @@ -502,7 +502,7 @@ public static function showTaggedIdPs(DiscoTemplate $t, Configuration $blockConf array_push($idps, $allIdps[$entityId]); } $idpCount = count($idps); - if (0 === $idpCount) { + if ($idpCount === 0) { return $html; } $html .= '
' . PHP_EOL; @@ -514,7 +514,7 @@ public static function showTaggedIdPs(DiscoTemplate $t, Configuration $blockConf $class = 'col-xs-12 col-md-6 col-lg-4'; for ($i = 0; $i < $fullRows; ++$i) { for ($j = 0; $j < 3; ++$j) { - if (0 === $remainingIdps && $counter === ($idpCount - 1)) { + if ($remainingIdps === 0 && $counter === ($idpCount - 1)) { $class .= ' col-md-offset-3 col-lg-offset-0'; } $html .= self::showTaggedEntry($t, $idps[array_keys($idps)[$counter++]], $class); @@ -561,7 +561,7 @@ public static function showInlineSearch( $isAddInstitutionApp = $t->isAddInstitutionApp(); $addInstitutionUrl = ''; $addInstitutionEmail = ''; - if (null !== $addInstitution) { + if ($addInstitution !== null) { $addInstitutionUrl = $addInstitution->getString(self::ADD_INSTITUTION_URL, ''); $addInstitutionEmail = $addInstitution->getString(self::ADD_INSTITUTION_EMAIL, ''); } @@ -603,17 +603,17 @@ public static function showInlineSearch( $result .= '
' . PHP_EOL; // NO ENTRIES BLOCK $result .= '
' . PHP_EOL; - if ($disableWhitelisting && null !== $addInstitutionEmail) { + if ($disableWhitelisting && $addInstitutionEmail !== null) { $result .= ' ' . $t->t('{perun:disco:cannot_find_institution_disabled_whitelisting}') . ' ' . $addInstitutionEmail . '' . PHP_EOL; - } elseif ($isAddInstitutionApp && null !== $addInstitutionEmail) { + } elseif ($isAddInstitutionApp && $addInstitutionEmail !== null) { $result .= ' ' . $t->t('{perun:disco:add_institution_no_entries_contact_us}') . ' ' . $addInstitutionEmail . '' . PHP_EOL; } else { $result .= ' ' . $t->t('{perun:disco:institution_search_no_entries_header}'); - if (null !== $addInstitutionUrl) { + if ($addInstitutionUrl !== null) { $result .= '

' . PHP_EOL; $result .= ' ' . ' ' . @@ -743,14 +743,14 @@ protected static function whitelisting(array $list, array $whitelist): array $unset = false; } } - if (isset($idp[self::IDP_COCO]) and true === $idp[self::IDP_COCO]) { + if (isset($idp[self::IDP_COCO]) and $idp[self::IDP_COCO] === true) { $unset = false; } - if (isset($idp[self::IDP_RAS]) and true === $idp[self::IDP_RAS]) { + if (isset($idp[self::IDP_RAS]) and $idp[self::IDP_RAS] === true) { $unset = false; } - if (true === $unset) { + if ($unset === true) { unset($list[$entityId]); } } @@ -798,26 +798,26 @@ protected static function showRemainingTaggedEntries( bool $hasFullRows ): string { $html = ''; - if (0 === $remainingIdps) { + if ($remainingIdps === 0) { return $html; } if ($hasFullRows > 0) { - if (2 === $remainingIdps) { + if ($remainingIdps === 2) { $class = 'col-xs-12 col-md-6 col-lg-4 col-lg-offset-2'; $html .= self::showTaggedEntry($t, $idps[array_keys($idps)[$counter++]], $class); $class = 'col-xs-12 col-md-6 col-lg-4 col-lg-offset-0 col-md-offset-3'; $html .= self::showTaggedEntry($t, $idps[array_keys($idps)[$counter]], $class); - } elseif (1 === $remainingIdps) { + } elseif ($remainingIdps === 1) { $class = 'col-xs-12 col-md-6 col-lg-4 col-lg-offset-4'; $html .= self::showTaggedEntry($t, $idps[array_keys($idps)[$counter]], $class); $html .= '
' . PHP_EOL; } - } elseif (2 === $remainingIdps) { + } elseif ($remainingIdps === 2) { $class = 'col-xs-12 col-md-6'; $html .= self::showTaggedEntry($t, $idps[array_keys($idps)[$counter++]], $class); $html .= self::showTaggedEntry($t, $idps[array_keys($idps)[$counter]], $class); - } elseif (1 === $remainingIdps) { + } elseif ($remainingIdps === 1) { $class = 'col-lg-12'; $html .= self::showTaggedEntry($t, $idps[array_keys($idps)[$counter]], $class); } @@ -931,7 +931,7 @@ private static function constructSearchData($idpMetadata): string private static function substrInArray($needle, array $haystack) { foreach ($haystack as $item) { - if (false !== strpos($item, $needle)) { + if (strpos($item, $needle) !== false) { return $item; } } @@ -945,7 +945,7 @@ private function fillSpName($t) $this->adapter = Adapter::getInstance($this->wayfConfiguration->getString(self::INTERFACE, self::RPC)); try { - if (null !== $clientIdWithPrefix) { + if ($clientIdWithPrefix !== null) { $this->fillSpNameForOidc($t, $clientIdWithPrefix); } else { $this->fillSpNameForSaml($t); @@ -958,20 +958,20 @@ private function fillSpName($t) private function fillSpNameForOidc($t, $clientIdWithPrefix) { - if (null === $clientIdWithPrefix) { + if ($clientIdWithPrefix === null) { return; } $parts = explode(':', $clientIdWithPrefix); $clientId = end($parts); $clientIdAttr = $this->wayfConfiguration->getString(self::CLIENT_ID_ATTR, null); - if (null === $clientIdAttr) { + if ($clientIdAttr === null) { $facility = $this->adapter->getFacilityByClientId($clientId); } else { $facility = $this->adapter->getFacilityByClientId($clientId, $clientIdAttr); } - if (null !== $facility) { + if ($facility !== null) { $spNameAttrName = $this->wayfConfiguration->getString( self::SERVICE_NAME_ATTR, self::SERVICE_NAME_DEFAULT_ATTR_NAME @@ -989,13 +989,13 @@ private function fillSpNameForSaml($t) if (!empty($this->originalsp[self::SP_ENTITY_ID])) { $entityId = $this->originalsp[self::SP_ENTITY_ID]; $entityIdAttr = $this->wayfConfiguration->getString(self::ENTITY_ID_ATTR, null); - if (null === $entityIdAttr) { + if ($entityIdAttr === null) { $facility = $this->adapter->getFacilityByEntityId($entityId); } else { $facility = $this->adapter->getFacilityByEntityId($entityId, $entityIdAttr); } - if (null === $facility) { + if ($facility === null) { return; } @@ -1024,7 +1024,7 @@ private function getSpIdentifier() { $clientIdWithPrefix = self::substrInArray(self::CLIENT_ID_PREFIX, $this->originalAuthnContextClassRef); - if (null !== $clientIdWithPrefix) { + if ($clientIdWithPrefix !== null) { $parts = explode(':', $clientIdWithPrefix); return end($parts); // clientId diff --git a/lib/Exception.php b/lib/Exception.php index fa054a63..141e9bbf 100644 --- a/lib/Exception.php +++ b/lib/Exception.php @@ -26,11 +26,11 @@ class Exception extends \SimpleSAML\Error\Exception */ public function __construct($id, $name, $message) { - if (null === $name && null === $message) { + if ($name === null && $message === null) { parent::__construct('Perun error: ' . $id); - } elseif (null === $name) { + } elseif ($name === null) { parent::__construct('Perun error: ' . $id . ' - ' . $message); - } elseif (null === $message) { + } elseif ($message === null) { parent::__construct('Perun error: ' . $id . ' - ' . $name); } else { parent::__construct('Perun error: ' . $id . ' - ' . $name . ' - ' . $message); diff --git a/lib/IdpListsService.php b/lib/IdpListsService.php index ede200d5..0919dd71 100644 --- a/lib/IdpListsService.php +++ b/lib/IdpListsService.php @@ -35,10 +35,10 @@ public static function getInstance() { $configuration = Configuration::getConfig(self::CONFIG_FILE_NAME); $idpListServiceType = $configuration->getString(self::PROPNAME_IDP_LIST_SERVICE_TYPE, self::CSV); - if (self::CSV === $idpListServiceType) { + if ($idpListServiceType === self::CSV) { return new IdpListsServiceCsv(); } - if (self::DB === $idpListServiceType) { + if ($idpListServiceType === self::DB) { return new IdpListsServiceDB(); } throw new Exception('Unknown idpListService type. Hint: try ' . self::CSV . ' or ' . self::DB); diff --git a/lib/IdpListsServiceCsv.php b/lib/IdpListsServiceCsv.php index 371311bb..4187e94c 100644 --- a/lib/IdpListsServiceCsv.php +++ b/lib/IdpListsServiceCsv.php @@ -104,7 +104,7 @@ public function getGreylistEntityIds() */ public function listToArray($listName, $all) { - if ('whitelist' === $listName) { + if ($listName === 'whitelist') { $list = $this->whitelistFile; } else { $list = $this->greylistFile; diff --git a/lib/LdapConnector.php b/lib/LdapConnector.php index 2227ca0c..c070b8ef 100644 --- a/lib/LdapConnector.php +++ b/lib/LdapConnector.php @@ -96,20 +96,20 @@ public function searchForEntities($base, $filter, $attrNames = null) protected function search($base, $filter, $attributes = null) { $conn = ldap_connect($this->hostname); - if (false === $conn) { + if ($conn === false) { throw new Exception('Unable to connect to the Perun LDAP, ' . $this->hostname); } ldap_set_option($conn, LDAP_OPT_PROTOCOL_VERSION, 3); // Enable TLS, if needed - if ($this->enableTLS && false === stripos($this->hostname, 'ldaps:')) { + if ($this->enableTLS && stripos($this->hostname, 'ldaps:') === false) { if (!@ldap_start_tls($conn)) { throw new Exception('Unable to force TLS on Perun LDAP'); } } - if (false === ldap_bind($conn, $this->user, $this->password)) { + if (ldap_bind($conn, $this->user, $this->password) === false) { throw new Exception('Unable to bind user to the Perun LDAP, ' . $this->hostname); } @@ -123,7 +123,7 @@ protected function search($base, $filter, $attributes = null) $responseTime = round(($endTime - $startTime) * 1000, 3); // no such entity - if (2 === ldap_errno($conn)) { + if (ldap_errno($conn) === 2) { return []; } diff --git a/lib/ListOfSps.php b/lib/ListOfSps.php index 28052a72..d5ac3da8 100644 --- a/lib/ListOfSps.php +++ b/lib/ListOfSps.php @@ -45,7 +45,7 @@ public static function printServiceName($name, $loginURL = null) public static function printAttributeValue($type, $value) { - if (empty($value) && 'java.lang.Boolean' !== $type) { + if (empty($value) && $type !== 'java.lang.Boolean') { return "―"; } @@ -63,7 +63,7 @@ public static function printAttributeValue($type, $value) $string = htmlspecialchars($value); break; case 'java.lang.Boolean': - if (null !== $value && $value) { + if ($value !== null && $value) { $string = '✔'; } else { $string = '✕'; diff --git a/lib/MetadataFromPerun.php b/lib/MetadataFromPerun.php index 7825b7f1..6cb39005 100644 --- a/lib/MetadataFromPerun.php +++ b/lib/MetadataFromPerun.php @@ -58,8 +58,8 @@ public function getMetadata($facility) $metadata = []; foreach ($this->attributesDefinitions as $perunAttrName => $metadataAttrName) { $attribute = $facility[self::FACILITY_ATTRIBUTES][$perunAttrName]; - if (null !== $attribute['value']) { - if (null !== $attribute['value']) { + if ($attribute['value'] !== null) { + if ($attribute['value'] !== null) { $target = &$metadata; $keys = explode('>', $metadataAttrName); while (count($keys) > 1) { @@ -85,7 +85,7 @@ public function getMetadata($facility) } $metadata = array_filter($metadata, function ($value) { - return null !== $value; + return $value !== null; }); return [ diff --git a/lib/MetadataToPerun.php b/lib/MetadataToPerun.php index 26002791..569d21bb 100644 --- a/lib/MetadataToPerun.php +++ b/lib/MetadataToPerun.php @@ -107,7 +107,7 @@ public function metadataToFacility(array $metadata) if (!empty($attrs)) { $newAttrs = $transformer['instance']->transform($attrs); $facility = array_merge($facility, $newAttrs); - if (!isset($facility[self::ENTITY_ID]) || null === $facility[self::ENTITY_ID]) { + if (!isset($facility[self::ENTITY_ID]) || $facility[self::ENTITY_ID] === null) { return null; } } @@ -145,7 +145,7 @@ public function getFacilitiesFromFlatfile(string $directory = null) $config = [ 'type' => 'flatfile', ]; - if (null !== $directory) { + if ($directory !== null) { $config['directory'] = $directory; } @@ -206,15 +206,15 @@ public function createFacilityWithAttributes(array $info) if (isset($this->perunAttributes[$perunName])) { $internalName = $this->perunAttributes[$perunName]; $value = $info[$internalName] ?? null; - if (null !== $value) { - if (!is_array($value) && 'List' === substr($attribute['type'], -4)) { + if ($value !== null) { + if (!is_array($value) && substr($attribute['type'], -4) === 'List') { $value = [$value]; } $attributes[$i]['value'] = $value; } } elseif ($perunName === $this->masterProxyIdentifierAttr) { $attributes[$i]['value'] = $this->proxyIdentifier; - } elseif ('' !== $this->isSamlFacilityAttr && $perunName === $this->isSamlFacilityAttr) { + } elseif ($this->isSamlFacilityAttr !== '' && $perunName === $this->isSamlFacilityAttr) { $attributes[$i]['value'] = true; } if ($perunName === $this->proxyIdentifiersAttr) { @@ -245,7 +245,7 @@ private function addArrayAttributes($metadata, &$facility) $indexes = is_array($metadataAttribute) ? $metadataAttribute : [$metadataAttribute]; foreach ($indexes as $index) { $t = self::getNestedAttribute($metadata, explode('.', $index)); - if (null !== $t) { + if ($t !== null) { $facility[$perunAttribute] = $t; } } @@ -259,19 +259,19 @@ private function addXmlAttributes($metadata, &$facility) foreach ($this->xmlAttributes as $perunAttribute => $xpath) { if (is_string($xpath)) { $result = $xml->xpath($xpath); - $result = false !== $result && count($result) > 0 ? $result[0] : false; - } elseif (1 !== count($xpath)) { + $result = $result !== false && count($result) > 0 ? $result[0] : false; + } elseif (count($xpath) !== 1) { throw new \Exception('xpath array should have exactly 1 item'); } else { $index = key($xpath); $xpathSelector = $xpath[$index]; $result = $xml->xpath($xpathSelector); - if (false !== $result && count($result) > 0) { + if ($result !== false && count($result) > 0) { if (is_string($index)) { $indexes = array_map(function ($el) use ($index) { $i = $el->xpath($index); - return false !== $i && count($i) > 0 ? ((string) $i[0]) : false; + return $i !== false && count($i) > 0 ? ((string) $i[0]) : false; }, $result); if (in_array(false, $indexes, true) || count($indexes) !== count($result)) { throw new \Exception('Did not find corresponding number of keys using xpath ' . $index); @@ -286,7 +286,7 @@ private function addXmlAttributes($metadata, &$facility) } } - if (false !== $result) { + if ($result !== false) { $facility[$perunAttribute] = $result; } } diff --git a/lib/NagiosStatusConnector.php b/lib/NagiosStatusConnector.php index 955202e4..1c44e308 100644 --- a/lib/NagiosStatusConnector.php +++ b/lib/NagiosStatusConnector.php @@ -34,7 +34,7 @@ public function __construct() $config = $this->configuration->getConfigItem(self::STATUS_NAGIOS, null); - if (null === $config) { + if ($config === null) { throw new Exception('Property \'' . self::STATUS_NAGIOS . '\' is missing or invalid!'); } diff --git a/lib/RpcConnector.php b/lib/RpcConnector.php index 21b621c9..539874ad 100644 --- a/lib/RpcConnector.php +++ b/lib/RpcConnector.php @@ -75,7 +75,7 @@ public function get($manager, $method, $params = []) Logger::debug('perun.RPC: GET call ' . $uri . ' with params: ' . $paramsQuery . ', response : ' . $json . ' in: ' . $responseTime . 's.'); - if (false === $json) { + if ($json === false) { throw new Exception( 'Cant\'t get response from Perun. Call: ' . $uri . ', Params: ' . $paramsQuery . ', Response: ' . $json ); @@ -83,7 +83,7 @@ public function get($manager, $method, $params = []) $result = json_decode($json, true); - if (JSON_ERROR_NONE !== json_last_error()) { + if (json_last_error() !== JSON_ERROR_NONE) { throw new Exception( 'Cant\'t decode response from Perun. Call: ' . $uri . ', Params: ' . $paramsQuery . ', Response: ' . $json ); @@ -129,7 +129,7 @@ public function post($manager, $method, $params = []) Logger::debug('perun.RPC: POST call ' . $uri . ' with params: ' . $paramsJson . ', response : ' . $json . ' in: ' . $responseTime . 's.'); - if (false === $json) { + if ($json === false) { throw new Exception( 'Can\'t get response from Perun. Call: ' . $uri . ', Params: ' . $paramsJson . ', Response: ' . $json ); @@ -137,7 +137,7 @@ public function post($manager, $method, $params = []) $result = json_decode($json, true); - if (JSON_ERROR_NONE !== json_last_error()) { + if (json_last_error() !== JSON_ERROR_NONE) { throw new Exception( 'Cant\'t decode response from Perun. Call: ' . $uri . ', Params: ' . $paramsJson . ', Response: ' . $json ); diff --git a/lib/StatusConnector.php b/lib/StatusConnector.php index 7c1dd0cc..31a431ed 100644 --- a/lib/StatusConnector.php +++ b/lib/StatusConnector.php @@ -36,7 +36,7 @@ public static function getInstance() { $configuration = Configuration::getConfig(self::CONFIG_FILE_NAME); $statusType = $configuration->getString(self::STATUS_TYPE, 'NAGIOS'); - if (self::NAGIOS === $statusType) { + if ($statusType === self::NAGIOS) { return new NagiosStatusConnector(); } throw new Exception( @@ -63,10 +63,10 @@ public static function getBadgeByStatus($status) { $statusAsInt = intval($status); - if (self::OK === $statusAsInt) { + if ($statusAsInt === self::OK) { return 'OK'; } - if (self::WARNING === $statusAsInt) { + if ($statusAsInt === self::WARNING) { return 'WARNING'; } diff --git a/lib/databaseCommand/DatabaseConfig.php b/lib/databaseCommand/DatabaseConfig.php index 371e2ae0..4944711b 100644 --- a/lib/databaseCommand/DatabaseConfig.php +++ b/lib/databaseCommand/DatabaseConfig.php @@ -41,7 +41,7 @@ private function __construct() public static function getInstance() { - if (null === self::$instance) { + if (self::$instance === null) { self::$instance = new self(); } diff --git a/lib/databaseCommand/IdpListsServiceDbCmd.php b/lib/databaseCommand/IdpListsServiceDbCmd.php index cf919da3..e3240ee2 100644 --- a/lib/databaseCommand/IdpListsServiceDbCmd.php +++ b/lib/databaseCommand/IdpListsServiceDbCmd.php @@ -37,9 +37,9 @@ public function getAllIdps($tableName) $greyListTableName = $this->config->getGreyListTableName(); $table = null; - if (self::WHITELIST === $tableName) { + if ($tableName === self::WHITELIST) { $table = $whiteListTableName; - } elseif (self::GREYLIST === $tableName) { + } elseif ($tableName === self::GREYLIST) { $table = $greyListTableName; } @@ -64,9 +64,9 @@ public function getAllEntityIds($tableName) $greyListTableName = $this->config->getGreyListTableName(); $table = null; - if (self::WHITELIST === $tableName) { + if ($tableName === self::WHITELIST) { $table = $whiteListTableName; - } elseif (self::GREYLIST === $tableName) { + } elseif ($tableName === self::GREYLIST) { $table = $greyListTableName; } @@ -91,9 +91,9 @@ public function insertToList($tableName, $entityId, $reason) $greyListTableName = $this->config->getGreyListTableName(); $table = null; - if (self::WHITELIST === $tableName) { + if ($tableName === self::WHITELIST) { $table = $whiteListTableName; - } elseif (self::GREYLIST === $tableName) { + } elseif ($tableName === self::GREYLIST) { $table = $greyListTableName; } @@ -123,9 +123,9 @@ public function deleteFromList($tableName, $entityId) $greyListTableName = $this->config->getGreyListTableName(); $table = null; - if (self::WHITELIST === $tableName) { + if ($tableName === self::WHITELIST) { $table = $whiteListTableName; - } elseif (self::GREYLIST === $tableName) { + } elseif ($tableName === self::GREYLIST) { $table = $greyListTableName; } diff --git a/lib/model/WarningConfigurationConfig.php b/lib/model/WarningConfigurationConfig.php index cf2ec4c1..5822a051 100644 --- a/lib/model/WarningConfigurationConfig.php +++ b/lib/model/WarningConfigurationConfig.php @@ -21,7 +21,7 @@ public function getWarningAttributes(): WarningConfiguration { $conf = self::getSourceOfWarningAttributes(); - if (null !== $conf) { + if ($conf !== null) { $this->enabled = $conf->getBoolean(WarningConfiguration::ENABLED, false); } diff --git a/lib/model/WarningConfigurationFile.php b/lib/model/WarningConfigurationFile.php index 3468817e..2be1c370 100644 --- a/lib/model/WarningConfigurationFile.php +++ b/lib/model/WarningConfigurationFile.php @@ -46,7 +46,7 @@ public function getWarningAttributes(): WarningConfiguration { $conf = self::getSourceOfWarningAttributes(); - if (null !== $conf) { + if ($conf !== null) { $this->enabled = $conf->getBoolean(WarningConfiguration::ENABLED, false); } diff --git a/lib/model/WarningConfigurationUrl.php b/lib/model/WarningConfigurationUrl.php index 72046aba..090084b3 100644 --- a/lib/model/WarningConfigurationUrl.php +++ b/lib/model/WarningConfigurationUrl.php @@ -46,7 +46,7 @@ public function getWarningAttributes(): WarningConfiguration { $conf = self::getSourceOfWarningAttributes(); - if (null !== $conf) { + if ($conf !== null) { $this->enabled = $conf->getBoolean(WarningConfiguration::ENABLED, false); } diff --git a/lib/transformers/AttributeAlter.php b/lib/transformers/AttributeAlter.php index 4056734a..6499683a 100644 --- a/lib/transformers/AttributeAlter.php +++ b/lib/transformers/AttributeAlter.php @@ -77,7 +77,7 @@ public function singleDescription(string $description) $description ); } - if ('/^/' === $this->config->getString('pattern')) { + if ($this->config->getString('pattern') === '/^/') { return sprintf('prepend %s to (%s)', $this->config->getString('replacement'), $description); } diff --git a/lib/transformers/EndpointIndexMap.php b/lib/transformers/EndpointIndexMap.php index 48b6853e..4c6608d3 100644 --- a/lib/transformers/EndpointIndexMap.php +++ b/lib/transformers/EndpointIndexMap.php @@ -33,7 +33,7 @@ public function __construct(\SimpleSAML\Configuration $config) */ public function transform(array $attributes) { - if (2 !== count($attributes)) { + if (count($attributes) !== 2) { throw new \Exception( 'Invalid configuration of EndpointIndexMap transformer, exactly 2 input attributes exptected' ); diff --git a/lib/transformers/EndpointList.php b/lib/transformers/EndpointList.php index 92b8c5b6..b7363370 100644 --- a/lib/transformers/EndpointList.php +++ b/lib/transformers/EndpointList.php @@ -21,7 +21,7 @@ class EndpointList extends SingularAttributeTransformer public function __construct(\SimpleSAML\Configuration $config) { $this->binding = $config->getString('binding'); - if (0 !== strpos($this->binding, self::BINDING_PREFIX)) { + if (strpos($this->binding, self::BINDING_PREFIX) !== 0) { $this->binding = self::BINDING_PREFIX . $this->binding; } } diff --git a/lib/transformers/EndpointMapToArray.php b/lib/transformers/EndpointMapToArray.php index 9a1d5de9..8e9278e3 100644 --- a/lib/transformers/EndpointMapToArray.php +++ b/lib/transformers/EndpointMapToArray.php @@ -42,7 +42,7 @@ public function transform(array $attributes) private function getBindingName($binding) { - if (0 !== strpos($binding, 'urn:')) { + if (strpos($binding, 'urn:') !== 0) { return self::BINDING_PREFIX . $binding; } @@ -68,14 +68,14 @@ private function getEndpointsArray($endpointMap) $endpointMap = $fullBindingNames; // if all endpoints use the default binding and there are no spaces - if (1 === count($endpointMap) && isset($endpointMap[$this->defaultBinding]) - && false === strpos( + if (count($endpointMap) === 1 && isset($endpointMap[$this->defaultBinding]) + && strpos( $endpointMap[$this->defaultBinding], self::MAPLIST_SEPARATOR . self::MAPLIST_SEPARATOR - )) { + ) === false) { $result = explode(self::MAPLIST_SEPARATOR, $endpointMap[$this->defaultBinding]); - return 1 === count($result) ? $result[0] : $result; + return count($result) === 1 ? $result[0] : $result; } $result = []; @@ -83,7 +83,7 @@ private function getEndpointsArray($endpointMap) // prefer default binding if (isset($endpointMap[$this->defaultBinding])) { foreach (explode(self::MAPLIST_SEPARATOR, $endpointMap[$this->defaultBinding]) as $location) { - $result[] = $this->getEndpoint($location, $this->defaultBinding, $index++, self::INDEX_MIN === $index); + $result[] = $this->getEndpoint($location, $this->defaultBinding, $index++, $index === self::INDEX_MIN); } } foreach ($endpointMap as $binding => $locations) { diff --git a/lib/transformers/KeyLists.php b/lib/transformers/KeyLists.php index c89f889d..81dc7636 100644 --- a/lib/transformers/KeyLists.php +++ b/lib/transformers/KeyLists.php @@ -26,7 +26,7 @@ public function __construct(\SimpleSAML\Configuration $config) */ public function transform(array $attributes) { - if (1 !== count($attributes)) { + if (count($attributes) !== 1) { throw new \Exception('KeyLists transformer only works with 1 attribute.'); } foreach ($attributes as $keys) { @@ -56,7 +56,7 @@ private function getCertData(array $keys) $attributes[$internal] = []; } foreach ($keys as $key) { - if ('X509Certificate' === $key['type'] && !empty($key['X509Certificate'])) { + if ($key['type'] === 'X509Certificate' && !empty($key['X509Certificate'])) { foreach ($this->purpose2internal as $purpose => $internal) { if ($key[$purpose]) { $attributes[$internal][] = $key['X509Certificate']; diff --git a/lib/transformers/KeyListsToArray.php b/lib/transformers/KeyListsToArray.php index 0e57b4f9..c4b659fd 100644 --- a/lib/transformers/KeyListsToArray.php +++ b/lib/transformers/KeyListsToArray.php @@ -60,7 +60,7 @@ public function transform(array $attributes) } // one key for everything (certData) if ( - !empty($this->outputCertData) && 1 === count($keys) + !empty($this->outputCertData) && count($keys) === 1 && count(array_filter(current($keys))) === count($this->purposes) ) { return array_merge($result, [ diff --git a/lib/transformers/ShibbolethAttributeFilter.php b/lib/transformers/ShibbolethAttributeFilter.php index 5b8dae63..7a4deb42 100644 --- a/lib/transformers/ShibbolethAttributeFilter.php +++ b/lib/transformers/ShibbolethAttributeFilter.php @@ -51,7 +51,7 @@ public function __construct(\SimpleSAML\Configuration $config) $this->throwOnMismatch = $config->getBoolean('throwOnMismatch', false); $data = $config->getString('file', null); - if (null !== $data) { + if ($data !== null) { $data_is_url = true; } else { $data_is_url = false; @@ -72,7 +72,7 @@ public function transform(array $attributes) $entityCategories = $attributes[$this->entityCategoriesAttribute] ?? []; $releasedAttributes = $this->getReleasedAttributes($entityId, $entityCategories); - if (null === $releasedAttributes) { + if ($releasedAttributes === null) { return [ $this->entityIdAttribute => null, ]; @@ -91,7 +91,7 @@ public function transform(array $attributes) $result = [ $this->attributesAttribute => $releasedAttributes, ]; - if (null !== $this->tagsAttribute && !empty($this->tags[$entityId])) { + if ($this->tagsAttribute !== null && !empty($this->tags[$entityId])) { $result[$this->tagsAttribute] = $this->tags[$entityId]; } @@ -140,7 +140,7 @@ public function getDescription(array $attributes) $description ), ]; - if (null !== $this->tagsAttribute) { + if ($this->tagsAttribute !== null) { $d[$this->tagsAttribute] = sprintf('internal tags from Shibboleth configuration'); } @@ -163,7 +163,7 @@ private function parseAttributeFilter($data, $data_is_url) foreach ($attributeFilterPolicyGroup->AttributeFilterPolicy as $policy) { $sps = []; $notSps = []; - if (1 !== count($policy->PolicyRequirementRule)) { + if (count($policy->PolicyRequirementRule) !== 1) { self::error('Not exactly one PolicyRequirementRule'); } $requirement = $policy->PolicyRequirementRule; @@ -204,7 +204,7 @@ private function normalizeReleasedAttributes($attributes, $entityCategories = [] { $arr = array_unique(array_merge($attributes, $this->getDefaultAttributes($entityCategories))); $arr = array_filter($arr, function ($attr) use ($attributes) { - return self::DENIED_ATTRIBUTE_PREFIX !== substr($attr, 0, strlen(self::DENIED_ATTRIBUTE_PREFIX)) + return substr($attr, 0, strlen(self::DENIED_ATTRIBUTE_PREFIX)) !== self::DENIED_ATTRIBUTE_PREFIX && !in_array(self::DENIED_ATTRIBUTE_PREFIX . $attr, $attributes, true); }); sort($arr); @@ -223,7 +223,7 @@ private function requirementSps($requirement) { $sps = []; foreach ($requirement->children('basic', true) as $rule) { - if ('Rule' !== $rule->getName()) { + if ($rule->getName() !== 'Rule') { continue; } switch ($rule->attributes('xsi', true)->type) { diff --git a/templates/choose-vo-and-group-tpl.php b/templates/choose-vo-and-group-tpl.php index 777adaa9..4685e34f 100644 --- a/templates/choose-vo-and-group-tpl.php +++ b/templates/choose-vo-and-group-tpl.php @@ -49,7 +49,7 @@ $params['vo'] = $vo; - if ('members' !== $group) { + if ($group !== 'members') { $params['group'] = $group; } diff --git a/templates/listOfSps-tpl.php b/templates/listOfSps-tpl.php index b933fb3c..b27c9c6a 100644 --- a/templates/listOfSps-tpl.php +++ b/templates/listOfSps-tpl.php @@ -150,7 +150,7 @@ foreach ($attributesToShow as $attr) { $type = $service['facilityAttributes'][$attr]['type']; $value = $service['facilityAttributes'][$attr]['value']; - if (null !== $value && in_array($attr, $this->data['multilingualAttributes'], true)) { + if ($value !== null && in_array($attr, $this->data['multilingualAttributes'], true)) { $type = 'java.lang.String'; $value = ListOfSps::getPreferredTranslation($value, $this->getLanguage()); } diff --git a/templates/sp-authorization-select-tpl.php b/templates/sp-authorization-select-tpl.php index 6ecaa4e6..0a35497d 100644 --- a/templates/sp-authorization-select-tpl.php +++ b/templates/sp-authorization-select-tpl.php @@ -20,7 +20,7 @@ $group = explode(':', $_POST['selectedGroup'], 2)[1]; $params[PerunConstants::VO] = $vo; - if (PerunConstants::GROUP_MEMBERS !== $group) { + if ($group !== PerunConstants::GROUP_MEMBERS) { $params[PerunConstants::GROUP] = $group; } diff --git a/themes/perun/consent/consentform.php b/themes/perun/consent/consentform.php index d2290ae5..35bab24c 100644 --- a/themes/perun/consent/consentform.php +++ b/themes/perun/consent/consentform.php @@ -25,7 +25,7 @@ assert(is_array($this->data['noData'])); assert(is_array($this->data['attributes'])); assert(is_array($this->data['hiddenAttributes'])); -assert(false === $this->data['sppp'] || is_string($this->data['sppp'])); +assert($this->data['sppp'] === false || is_string($this->data['sppp'])); if (!isset($this->data['label-col'])) { $this->data['label-col'] = 5; @@ -91,7 +91,7 @@ ); } -if (false !== $this->data['sppp']) { +if ($this->data['sppp'] !== false) { echo '

' . htmlspecialchars($this->t('{perun:consent:consent_privacypolicy}')) . ' '; echo "" . $dstName . ''; echo '

'; diff --git a/themes/perun/core/loginuserpass.php b/themes/perun/core/loginuserpass.php index 46288b1b..3cdf4e2c 100644 --- a/themes/perun/core/loginuserpass.php +++ b/themes/perun/core/loginuserpass.php @@ -10,7 +10,7 @@ $this->includeAtTemplateBase('includes/header.php'); -if (null !== $this->data['errorcode']) { +if ($this->data['errorcode'] !== null) { ?>
getConfigItem(Disco::ADD_INSTITUTION, null); $warningAttributes = $this->data[Disco::WARNING_ATTRIBUTES]; -if (null !== $warningAttributes) { +if ($warningAttributes !== null) { $this->includeInlineTranslation('{perun:disco:warning_title}', $warningAttributes->getTitle()); $this->includeInlineTranslation('{perun:disco:warning_text}', $warningAttributes->getText()); // IF WARNING ERROR IS ENABLED, DISPLAY IT AND STOP THE USER - if ($warningAttributes->isEnabled() && WarningConfiguration::WARNING_TYPE_ERROR === $warningAttributes->getType()) { + if ($warningAttributes->isEnabled() && $warningAttributes->getType() === WarningConfiguration::WARNING_TYPE_ERROR) { $this->data['header'] = $this->t('{perun:disco:warning}'); $this->includeAtTemplateBase('includes/header.php'); echo Disco::showWarning($this, $warningAttributes); @@ -66,7 +66,7 @@ $this->includeAtTemplateBase('includes/header.php'); // IF WE HAVE A WARNING, DISPLAY IT TO THE USER -if (null !== $warningAttributes && $warningAttributes->isEnabled()) { +if ($warningAttributes !== null && $warningAttributes->isEnabled()) { echo Disco::showWarning($this, $warningAttributes); } //## @@ -82,7 +82,7 @@ $blockConfig = $blocksConfig->getConfigItem($key); $type = $blockConfig->getString(Disco::IDP_BLOCK_TYPE); echo '