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

Commit 66b69f3

Browse files
author
Dominik František Bučík
authored
Merge pull request #18 from dBucik/fix_ecs
fix: 🐛 Fix ECS new style
2 parents cae02be + 5eee8f3 commit 66b69f3

File tree

6 files changed

+54
-53
lines changed

6 files changed

+54
-53
lines changed

config-templates/module_elixir.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@
33
declare(strict_types=1);
44

55
/**
6-
* The config template for module ELIXIR
6+
* The config template for module ELIXIR.
77
*/
88
$config = [
9-
/**
9+
/*
1010
* The clientId from CSC_MFA server
1111
*/
1212
'clientId' => '',
1313

14-
/**
14+
/*
1515
* The clientSecret from CSC_MFA server
1616
*/
1717
'clientSecret' => '',
1818

19-
/**
19+
/*
2020
* List of requested scopes
2121
*/
2222
'requestedScopes' => [],
2323

24-
/**
24+
/*
2525
* The openid configuration url of CSC_MFA server
2626
*/
2727
'openidConfigurationUrl' => '',

ecs.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,25 @@
33
declare(strict_types=1);
44

55
use PhpCsFixer\Fixer\ArrayNotation\ArraySyntaxFixer;
6+
use PhpCsFixer\Fixer\FunctionNotation\FunctionTypehintSpaceFixer;
7+
use PhpCsFixer\Fixer\Operator\NotOperatorWithSuccessorSpaceFixer;
68
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
79
use Symplify\EasyCodingStandard\ValueObject\Option;
810
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;
911

1012
return static function (ContainerConfigurator $containerConfigurator): void {
11-
$services = $containerConfigurator->services();
12-
$services->set(ArraySyntaxFixer::class)
13-
->call('configure', [[
14-
'syntax' => 'short',
15-
]])
16-
;
17-
1813
$parameters = $containerConfigurator->parameters();
1914
$parameters->set(Option::PATHS, [
2015
__DIR__ . '/ecs.php',
2116
__DIR__ . '/config-templates',
2217
__DIR__ . '/lib',
2318
__DIR__ . '/themes',
2419
__DIR__ . '/www',
25-
__DIR__ . '/composer.json',
2620
]);
21+
$parameters->set(Option::PARALLEL, true);
22+
$parameters->set(Option::SKIP, [NotOperatorWithSuccessorSpaceFixer::class, FunctionTypehintSpaceFixer::class]);
2723

24+
$containerConfigurator->import(SetList::PHP_CS_FIXER);
2825
$containerConfigurator->import(SetList::CLEAN_CODE);
2926
$containerConfigurator->import(SetList::SYMPLIFY);
3027
$containerConfigurator->import(SetList::ARRAY);
@@ -35,5 +32,14 @@
3532
$containerConfigurator->import(SetList::NAMESPACES);
3633
$containerConfigurator->import(SetList::PHPUNIT);
3734
$containerConfigurator->import(SetList::SPACES);
35+
$containerConfigurator->import(SetList::STRICT);
36+
$containerConfigurator->import(SetList::SYMFONY);
3837
$containerConfigurator->import(SetList::PSR_12);
38+
39+
$services = $containerConfigurator->services();
40+
$services->set(ArraySyntaxFixer::class)
41+
->call('configure', [[
42+
'syntax' => 'short',
43+
]])
44+
;
3945
};

lib/Auth/Process/CSCMfa.php

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,19 @@ public function __construct($config, $reserved)
5252

5353
if (empty($this->clientId)) {
5454
throw new Exception(
55-
'elixir:CSCMfa: missing mandatory configuration option "' . self::CLIENT_ID .
56-
'" in configuration file "' . self::CONFIG_FILE_NAME . '".'
55+
'elixir:CSCMfa: missing mandatory configuration option "' . self::CLIENT_ID . '" in configuration file "' . self::CONFIG_FILE_NAME . '".'
5756
);
5857
}
5958

6059
if (empty($this->requestedScopes)) {
6160
throw new Exception(
62-
'elixir:CSCMfa: missing mandatory configuration option "' . self::REQUESTED_SCOPES .
63-
'" in configuration file "' . self::CONFIG_FILE_NAME . '".'
61+
'elixir:CSCMfa: missing mandatory configuration option "' . self::REQUESTED_SCOPES . '" in configuration file "' . self::CONFIG_FILE_NAME . '".'
6462
);
6563
}
6664

6765
if (empty($openidConfigurationUrl)) {
6866
throw new Exception(
69-
'elixir:CSCMfa: missing mandatory configuration option "' . self::AUTHORIZATION_ENDPOINT .
70-
'" in configuration file "' . self::CONFIG_FILE_NAME . '".'
67+
'elixir:CSCMfa: missing mandatory configuration option "' . self::AUTHORIZATION_ENDPOINT . '" in configuration file "' . self::CONFIG_FILE_NAME . '".'
7168
);
7269
}
7370

@@ -85,41 +82,43 @@ public function process(&$request)
8582

8683
if (isset($request['saml:RequestedAuthnContext']['AuthnContextClassRef'])) {
8784
$requestedAuthnContextClassRef = $request['saml:RequestedAuthnContext']['AuthnContextClassRef'][0];
88-
if (! is_array($requestedAuthnContextClassRef)) {
85+
if (!is_array($requestedAuthnContextClassRef)) {
8986
$requestedAuthnContextClassRef = [$requestedAuthnContextClassRef];
9087
}
9188
}
9289

93-
if (! in_array(self::MFA_IDENTIFIER, $requestedAuthnContextClassRef, true)) {
94-
# Everything is OK, SP didn't requested MFA
90+
if (!in_array(self::MFA_IDENTIFIER, $requestedAuthnContextClassRef, true)) {
91+
// Everything is OK, SP didn't requested MFA
9592
Logger::debug('Multi factor authentication is not required');
93+
9694
return;
9795
}
9896

99-
# Check if IdP did MFA
97+
// Check if IdP did MFA
10098
$authContextClassRef = [];
10199
if (isset($request['saml:sp:AuthnContext'])) {
102100
$authContextClassRef = $request['saml:sp:AuthnContext'];
103-
if (! is_array($authContextClassRef)) {
101+
if (!is_array($authContextClassRef)) {
104102
$authContextClassRef = [$authContextClassRef];
105103
}
106104
}
107105
if (in_array(self::MFA_IDENTIFIER, $authContextClassRef, true)) {
108-
# MFA was performed on IdP
106+
// MFA was performed on IdP
109107
Logger::debug('Multi factor authentication was performed on Identity provider side');
108+
110109
return;
111110
}
112111

113112
Logger::debug('Multi factor authentication wasn\'t performed and will be performed on CSC side.');
114113

115114
$stateId = State::saveState($request, 'elixir:CSCMfa', true);
116115

117-
if (! isset($request['Attributes']['eduPersonUniqueId'][0])) {
116+
if (!isset($request['Attributes']['eduPersonUniqueId'][0])) {
118117
throw new Exception('elixir:CSCMfa: missing required attribute "eduPersonUniqueId" in request');
119118
}
120119
$elixirId = $request['Attributes']['eduPersonUniqueId'][0];
121120

122-
# Prepare claims
121+
// Prepare claims
123122
$claims = [
124123
'id_token' => [
125124
'sub' => [
@@ -136,7 +135,7 @@ public function process(&$request)
136135
$claims['id_token']['mobile']['value'] = $phoneNumber;
137136
}
138137

139-
# Prepare params
138+
// Prepare params
140139
$params = [
141140
'response_type' => 'code',
142141
'scope' => implode(' ', $this->requestedScopes),
@@ -148,7 +147,7 @@ public function process(&$request)
148147

149148
$mfa_url = $this->authorizationEndpoint . '?' . http_build_query($params);
150149

151-
Header('Location: ' . $mfa_url);
150+
header('Location: ' . $mfa_url);
152151
exit();
153152
}
154153
}

themes/elixir/default/includes/footer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use SimpleSAML\Module;
44

5-
if (! empty($this->data['htmlinject']['htmlContentPost'])) {
5+
if (!empty($this->data['htmlinject']['htmlContentPost'])) {
66
foreach ($this->data['htmlinject']['htmlContentPost'] as $c) {
77
echo $c;
88
}
@@ -18,7 +18,7 @@
1818
<div style="margin: 0px auto; max-width: 1000px;">
1919

2020
<div style="float: left;">
21-
<img src="<?php echo Module::getModuleUrl('elixir/res/img/logo_64.png') ?>">
21+
<img src="<?php echo Module::getModuleUrl('elixir/res/img/logo_64.png'); ?>">
2222
</div>
2323

2424
<div style="float: left;">

themes/elixir/default/includes/header.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use SimpleSAML\Module;
44

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

32-
/**
32+
/*
3333
* Do not allow to frame SimpleSAMLphp pages from another location. This prevents clickjacking attacks in modern
3434
* browsers.
3535
*
@@ -59,13 +59,13 @@
5959

6060
<?php
6161

62-
if (! empty($jquery)) {
62+
if (!empty($jquery)) {
6363
$version = '1.8';
6464
if (array_key_exists('version', $jquery)) {
6565
$version = $jquery['version'];
6666
}
6767

68-
if ($version === '1.8') {
68+
if ('1.8' === $version) {
6969
if (isset($jquery['core']) && $jquery['core']) {
7070
echo '<script type="text/javascript" src="/' . $this->data['baseurlpath'] .
7171
'resources/jquery-1.8.js"></script>' . "\n";
@@ -88,7 +88,7 @@
8888
'resources/clipboard.min.js"></script>' . "\n";
8989
}
9090

91-
if (! empty($this->data['htmlinject']['htmlContentHead'])) {
91+
if (!empty($this->data['htmlinject']['htmlContentHead'])) {
9292
foreach ($this->data['htmlinject']['htmlContentHead'] as $c) {
9393
echo $c;
9494
}
@@ -130,7 +130,7 @@
130130
$onLoad .= $this->data['onLoad'];
131131
}
132132

133-
if ($onLoad !== '') {
133+
if ('' !== $onLoad) {
134134
$onLoad = ' onload="' . $onLoad . '"';
135135
}
136136

@@ -153,7 +153,7 @@
153153

154154
<?php
155155

156-
if (! empty($this->data['htmlinject']['htmlContentPre'])) {
156+
if (!empty($this->data['htmlinject']['htmlContentPre'])) {
157157
foreach ($this->data['htmlinject']['htmlContentPre'] as $c) {
158158
echo $c;
159159
}

www/CSCMfaContinue.php

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,21 @@
1616
$clientId = $conf->getString(CSCMfa::CLIENT_ID, '');
1717
if (empty($clientId)) {
1818
throw new Exception(
19-
'elixir:CSCMfa_continue: missing mandatory configuration option "' . CSCMfa::CLIENT_ID .
20-
'" in configuration file "' . CSCMfa::CONFIG_FILE_NAME . '".'
19+
'elixir:CSCMfa_continue: missing mandatory configuration option "' . CSCMfa::CLIENT_ID . '" in configuration file "' . CSCMfa::CONFIG_FILE_NAME . '".'
2120
);
2221
}
2322

2423
$clientSecret = $conf->getString(CSCMfa::CLIENT_SECRET, '');
2524
if (empty($clientSecret)) {
2625
throw new Exception(
27-
'elixir:CSCMfa_continue: missing mandatory configuration option "' . CSCMfa::CLIENT_SECRET .
28-
'" in configuration file "' . CSCMfa::CONFIG_FILE_NAME . '".'
26+
'elixir:CSCMfa_continue: missing mandatory configuration option "' . CSCMfa::CLIENT_SECRET . '" in configuration file "' . CSCMfa::CONFIG_FILE_NAME . '".'
2927
);
3028
}
3129

3230
$openidConfigurationUrl = $conf->getString(CSCMfa::OPENID_CONFIGURATION_URL, '');
3331
if (empty($openidConfigurationUrl)) {
3432
throw new Exception(
35-
'elixir:CSCMfa_continue: missing mandatory configuration option "' . CSCMfa::TOKEN_ENDPOINT .
36-
'" in configuration file "' . CSCMfa::CONFIG_FILE_NAME . '".'
33+
'elixir:CSCMfa_continue: missing mandatory configuration option "' . CSCMfa::TOKEN_ENDPOINT . '" in configuration file "' . CSCMfa::CONFIG_FILE_NAME . '".'
3734
);
3835
}
3936

@@ -47,16 +44,15 @@
4744
$mfaUserInfoUrl = $metadata[CSCMfa::USERINFO_ENDPOINT];
4845
}
4946

50-
if ($mfaTokenUrl === null || $mfaUserInfoUrl === null) {
47+
if (null === $mfaTokenUrl || null === $mfaUserInfoUrl) {
5148
throw new Exception(
52-
'elixir:CSCMfa_continue: Problem to get ' . CSCMfa::TOKEN_ENDPOINT . ' or ' .
53-
CSCMfa::USERINFO_ENDPOINT . ' from Openid configuration.'
49+
'elixir:CSCMfa_continue: Problem to get ' . CSCMfa::TOKEN_ENDPOINT . ' or ' . CSCMfa::USERINFO_ENDPOINT . ' from Openid configuration.'
5450
);
5551
}
5652

5753
$redirectUri = Module::getModuleURL('elixir') . '/CSCMfa_continue.php';
5854

59-
if (! isset($_GET['code'], $_GET['state'])) {
55+
if (!isset($_GET['code'], $_GET['state'])) {
6056
throw new Exception('elixir:CSCMfa_continue: One of following required params: "code", "state" is missing.');
6157
}
6258

@@ -65,7 +61,7 @@
6561

6662
$state = State::loadState($stateId, 'elixir:CSCMfa');
6763

68-
# Prepare params for token endpoint
64+
// Prepare params for token endpoint
6965
$params = [
7066
'code' => $code,
7167
'grant_type' => 'authorization_code',
@@ -75,15 +71,15 @@
7571
'nonce' => time(),
7672
];
7773

78-
# Request to token endpoint
74+
// Request to token endpoint
7975
$ch = curl_init();
8076
curl_setopt($ch, CURLOPT_URL, $mfaTokenUrl);
8177
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
8278
curl_setopt($ch, CURLOPT_POST, true);
8379
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
8480
$response = curl_exec($ch);
8581

86-
if ($response === false) {
82+
if (false === $response) {
8783
throw new \Exception("Request to token endpoint wasn't successful : " . curl_error($ch));
8884
}
8985
$response = json_decode($response, true);
@@ -102,15 +98,15 @@
10298
'access_token' => $accessToken,
10399
];
104100

105-
# Request to userinfo endpoint
101+
// Request to userinfo endpoint
106102
$ch = curl_init();
107103
curl_setopt($ch, CURLOPT_URL, $mfaUserInfoUrl);
108104
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
109105
curl_setopt($ch, CURLOPT_POST, true);
110106
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
111107
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Authorization: Bearer ' . $accessToken]);
112108
$response = curl_exec($ch);
113-
if ($response === false) {
109+
if (false === $response) {
114110
throw new \Exception("Request to token endpoint wasn't successful : " . curl_error($ch));
115111
}
116112

0 commit comments

Comments
 (0)