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

Commit ad38c1d

Browse files
committed
fix: update ECS, update configuration and fix the code
1 parent f805f93 commit ad38c1d

17 files changed

Lines changed: 122 additions & 107 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@
2222
"ext-curl": "*"
2323
},
2424
"require-dev": {
25-
"symplify/easy-coding-standard": "^9.2"
25+
"symplify/easy-coding-standard": "^10.0"
2626
}
2727
}

config-templates/module_cesnet_IsCesnetEligible.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
* copy command (from SimpleSAML base dir) cp modules/perun/module_cesnet_IsCesnetEligible.php config/
1010
*/
1111
$config = [
12-
/**
12+
/*
1313
* hostname of CESNET ldap with ldap(s):// at the beginning.
1414
*/
1515
'ldap.hostname' => '',
1616

17-
/**
17+
/*
1818
* ldap credentials if ldap search is protected. If it is null or not set at all. No user is used for bind.
1919
*/
2020
'ldap.username' => '',

ecs.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,6 @@
88
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;
99

1010
return static function (ContainerConfigurator $containerConfigurator): void {
11-
$services = $containerConfigurator->services();
12-
$services->set(ArraySyntaxFixer::class)
13-
->call('configure', [[
14-
'syntax' => 'short',
15-
]])
16-
;
17-
1811
$parameters = $containerConfigurator->parameters();
1912
$parameters->set(Option::PATHS, [
2013
__DIR__ . '/ecs.php',
@@ -25,7 +18,9 @@
2518
__DIR__ . '/www',
2619
__DIR__ . '/composer.json',
2720
]);
28-
21+
$parameters->set(Option::PARALLEL, true);
22+
$parameters->set(Option::SKIP, [NotOperatorWithSuccessorSpaceFixer::class, FunctionTypehintSpaceFixer::class]);
23+
$containerConfigurator->import(SetList::PHP_CS_FIXER);
2924
$containerConfigurator->import(SetList::CLEAN_CODE);
3025
$containerConfigurator->import(SetList::SYMPLIFY);
3126
$containerConfigurator->import(SetList::ARRAY);
@@ -36,5 +31,14 @@
3631
$containerConfigurator->import(SetList::NAMESPACES);
3732
$containerConfigurator->import(SetList::PHPUNIT);
3833
$containerConfigurator->import(SetList::SPACES);
34+
$containerConfigurator->import(SetList::STRICT);
35+
$containerConfigurator->import(SetList::SYMFONY);
3936
$containerConfigurator->import(SetList::PSR_12);
37+
38+
$services = $containerConfigurator->services();
39+
$services->set(ArraySyntaxFixer::class)
40+
->call('configure', [[
41+
'syntax' => 'short',
42+
]])
43+
;
4044
};

lib/Auth/Process/ComputeLoA.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use SimpleSAML\Metadata\MetaDataStorageHandler;
99

1010
/**
11-
* Class ComputeLoA
11+
* Class ComputeLoA.
1212
*
1313
* Filter compute the LoA and save it to attribute defined by 'attrName' config property.
1414
*/
@@ -32,7 +32,7 @@ class ComputeLoA extends \SimpleSAML\Auth\ProcessingFilter
3232

3333
private $metadata;
3434

35-
private $entityCategory = null;
35+
private $entityCategory;
3636

3737
private $eduPersonScopedAffiliation = [];
3838

@@ -75,7 +75,7 @@ public function process(&$request)
7575
}
7676

7777
foreach ($entityCategoryAttributes as $entityCategoryAttribute) {
78-
if (substr($entityCategoryAttribute, 0, strlen(self::EDUID_IDP_GROUP)) === self::EDUID_IDP_GROUP) {
78+
if (self::EDUID_IDP_GROUP === substr($entityCategoryAttribute, 0, strlen(self::EDUID_IDP_GROUP))) {
7979
$this->entityCategory = substr(
8080
$entityCategoryAttribute,
8181
strlen(self::EDUID_IDP_GROUP),
@@ -91,15 +91,16 @@ public function process(&$request)
9191
}
9292

9393
/**
94-
* Get LoA by CESNET filter
94+
* Get LoA by CESNET filter.
9595
*
9696
* @return int 2 if combination of IdP attributes and User attributes corresponds to the filter, 0 if not
9797
*/
9898
private function getLoA()
9999
{
100-
if ($this->entityCategory === null || empty($this->entityCategory)) {
100+
if (null === $this->entityCategory || empty($this->entityCategory)) {
101101
return 0;
102-
} elseif ($this->entityCategory === self::UNIVERSITY) {
102+
}
103+
if (self::UNIVERSITY === $this->entityCategory) {
103104
foreach ($this->eduPersonScopedAffiliation as $affiliation) {
104105
if (preg_match(
105106
'/(^employee@.+\.cz$)|' .
@@ -114,31 +115,32 @@ private function getLoA()
114115
return 2;
115116
}
116117
}
117-
} elseif ($this->entityCategory === self::AVCR) {
118+
} elseif (self::AVCR === $this->entityCategory) {
118119
foreach ($this->eduPersonScopedAffiliation as $affiliation) {
119120
if (preg_match('/^member@.+\.cz$/', $affiliation, $matches)) {
120121
return 2;
121122
}
122123
}
123-
} elseif ($this->entityCategory === self::LIBRARY) {
124+
} elseif (self::LIBRARY === $this->entityCategory) {
124125
foreach ($this->eduPersonScopedAffiliation as $affiliation) {
125126
if (preg_match('/^employee@.+\.cz$/', $affiliation, $matches)) {
126127
return 2;
127128
}
128129
}
129-
} elseif ($this->entityCategory === self::HOSPITAL) {
130+
} elseif (self::HOSPITAL === $this->entityCategory) {
130131
foreach ($this->eduPersonScopedAffiliation as $affiliation) {
131132
if (preg_match('/^employee@.+\.cz$/', $affiliation, $matches)) {
132133
return 2;
133134
}
134135
}
135-
} elseif ($this->entityCategory === self::OTHER) {
136+
} elseif (self::OTHER === $this->entityCategory) {
136137
foreach ($this->eduPersonScopedAffiliation as $affiliation) {
137138
if (preg_match('/(^employee@.+\.cz$)|(^member@.+\.cz$)/', $affiliation, $matches)) {
138139
return 2;
139140
}
140141
}
141142
}
143+
142144
return 0;
143145
}
144146
}

lib/Auth/Process/IsCesnetEligible.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use SimpleSAML\Module\perun\model\User;
1818

1919
/**
20-
* Class IsCesnetEligible
20+
* Class IsCesnetEligible.
2121
*
2222
* This class put the timestamp of last login into list of Attributes, when at least one value of attribute
2323
* 'eduPersonScopedAffiliation' is marked as isCesnetEligible in CESNET LDAP
@@ -87,8 +87,7 @@ public function __construct($config, $reserved)
8787
$conf = Configuration::loadFromArray($config);
8888
if (! isset($config[self::RPC_ATTRIBUTE_NAME]) || empty($config[self::RPC_ATTRIBUTE_NAME])) {
8989
throw new Exception(
90-
'cesnet:IsCesnetEligible - missing mandatory configuration option \'' .
91-
self::RPC_ATTRIBUTE_NAME . '\'.'
90+
'cesnet:IsCesnetEligible - missing mandatory configuration option \'' . self::RPC_ATTRIBUTE_NAME . '\'.'
9291
);
9392
}
9493

@@ -102,7 +101,7 @@ public function __construct($config, $reserved)
102101
}
103102

104103
if (isset($config[self::INTERFACE_PROPNAME], $config[self::LDAP_ATTRIBUTE_NAME]) &&
105-
$config[self::INTERFACE_PROPNAME] === self::LDAP && ! empty($config[self::LDAP_ATTRIBUTE_NAME])) {
104+
self::LDAP === $config[self::INTERFACE_PROPNAME] && ! empty($config[self::LDAP_ATTRIBUTE_NAME])) {
106105
$this->interface = $config[self::INTERFACE_PROPNAME];
107106
$this->ldapAttrName = $config[self::LDAP_ATTRIBUTE_NAME];
108107
$this->adapter = Adapter::getInstance(Adapter::LDAP);
@@ -150,7 +149,7 @@ public function process(&$request)
150149
}
151150

152151
if (! empty($user)) {
153-
if ($this->interface === self::LDAP) {
152+
if (self::LDAP === $this->interface) {
154153
$attrs = $this->adapter->getUserAttributes($user, [$this->ldapAttrName]);
155154
if (isset($attrs[$this->ldapAttrName][0])) {
156155
$this->cesnetEligibleLastSeenValue = $attrs[$this->ldapAttrName][0];
@@ -188,7 +187,7 @@ public function process(&$request)
188187
}
189188
}
190189

191-
if ($this->cesnetEligibleLastSeenValue !== null) {
190+
if (null !== $this->cesnetEligibleLastSeenValue) {
192191
$request['Attributes'][$this->returnAttrName] = [$this->cesnetEligibleLastSeenValue];
193192
Logger::debug(
194193
'cesnet:IsCesnetEligible - Attribute ' . $this->returnAttrName . ' was set to value ' .
@@ -197,7 +196,7 @@ public function process(&$request)
197196
}
198197

199198
$request['Attributes']['isCesnetEligible'] = ['false'];
200-
if (($this->cesnetEligibleLastSeenValue !== null) && $this->cesnetEligibleLastSeenValue > date(
199+
if ((null !== $this->cesnetEligibleLastSeenValue) && $this->cesnetEligibleLastSeenValue > date(
201200
'Y-m-d H:i:s',
202201
strtotime('-1 year')
203202
)) {
@@ -207,7 +206,7 @@ public function process(&$request)
207206
}
208207

209208
/**
210-
* Returns true if one of user's affiliation is in allowed affiliations for this IdP , False if not
209+
* Returns true if one of user's affiliation is in allowed affiliations for this IdP , False if not.
211210
*
212211
* @param User $user or Null
213212
*/
@@ -218,7 +217,7 @@ private function isCesnetEligible($user): bool
218217
return true;
219218
}
220219

221-
# Check if user has isCesnetEligible by sponsoring in some organization
220+
// Check if user has isCesnetEligible by sponsoring in some organization
222221
try {
223222
if (isset($user, $this->userAffiliationsAttrName, $this->userSponsoringOrganizationsAttrName)) {
224223
$userAttributes = $this->rpcAdapter->getUserAttributesValues(
@@ -235,10 +234,12 @@ private function isCesnetEligible($user): bool
235234
json_encode($perunUserAffiliations) . ', ' . $this->userSponsoringOrganizationsAttrName .
236235
':' . json_encode($perunUserSponsoringOrganizations) . '] has empty value!'
237236
);
237+
238238
return false;
239239
}
240240

241241
$allowedSponsoredAffiliations = $this->getAllowedAffiliations($perunUserSponsoringOrganizations);
242+
242243
return $this->compareAffiliations($perunUserAffiliations, $allowedSponsoredAffiliations);
243244
}
244245
} catch (\Exception $exception) {
@@ -252,9 +253,10 @@ private function isCesnetEligible($user): bool
252253
}
253254

254255
/**
255-
* Return list of allowed affiliations for IdP from CESNET LDAP
256+
* Return list of allowed affiliations for IdP from CESNET LDAP.
256257
*
257258
* @param array $idpEntityIds of entityId of IdPs
259+
*
258260
* @return array of allowed affiliations
259261
*/
260262
private function getAllowedAffiliations($idpEntityIds): array
@@ -298,7 +300,7 @@ private function getAllowedAffiliations($idpEntityIds): array
298300
/**
299301
* Compare two lists of affiliations and returns true if one of affiliations without scope is in booth lists.
300302
*
301-
* @param array $userAffiliations of user scoped affiliations
303+
* @param array $userAffiliations of user scoped affiliations
302304
* @param array $allowedAffiliations of allowed unscoped affiliations
303305
*/
304306
private function compareAffiliations($userAffiliations, $allowedAffiliations): bool
@@ -307,6 +309,7 @@ private function compareAffiliations($userAffiliations, $allowedAffiliations): b
307309
if (! empty($result)) {
308310
return true;
309311
}
312+
310313
return false;
311314
}
312315
}

themes/cesnet/default/includes/footer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<div class="row">
2121
<div class="col-md-4 logo">
2222
<a href="http://www.cesnet.cz/">
23-
<img src="<?php echo Module::getModuleUrl('cesnet/res/img/logo-cesnet.png') ?>"
23+
<img src="<?php echo Module::getModuleUrl('cesnet/res/img/logo-cesnet.png'); ?>"
2424
width="250px">
2525
</a>
2626
</div>

themes/cesnet/default/includes/header.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use SimpleSAML\Module;
44
use SimpleSAML\Utils\HTTP;
55

6-
/**
6+
/*
77
* Support the htmlinject hook, which allows modules to change header, pre and post body on all pages.
88
*/
99
$this->data['htmlinject'] = [
@@ -30,7 +30,7 @@
3030
}
3131
// - o - o - o - o - o - o - o - o - o - o - o - o -
3232

33-
/**
33+
/*
3434
* Do not allow to frame SimpleSAMLphp pages from another location. This prevents clickjacking attacks in modern
3535
* browsers.
3636
*
@@ -66,7 +66,7 @@
6666
$version = $jquery['version'];
6767
}
6868

69-
if ($version === '1.8') {
69+
if ('1.8' === $version) {
7070
if (isset($jquery['core']) && $jquery['core']) {
7171
echo '<script type="text/javascript" src="/' . $this->data['baseurlpath'] .
7272
'resources/jquery-1.8.js"></script>' . "\n"
@@ -97,7 +97,6 @@
9797
}
9898
}
9999

100-
101100
if ($this->isLanguageRTL()) {
102101
?>
103102
<link rel="stylesheet" type="text/css"
@@ -133,7 +132,7 @@
133132
$onLoad .= $this->data['onLoad'];
134133
}
135134

136-
if ($onLoad !== '') {
135+
if ('' !== $onLoad) {
137136
$onLoad = ' onload="' . $onLoad . '"';
138137
}
139138

@@ -147,7 +146,7 @@
147146
<?php
148147

149148
$includeLanguageBar = true;
150-
if (isset($this->data['hideLanguageBar']) && $this->data['hideLanguageBar'] === true) {
149+
if (isset($this->data['hideLanguageBar']) && true === $this->data['hideLanguageBar']) {
151150
$includeLanguageBar = false;
152151
}
153152

0 commit comments

Comments
 (0)