Skip to content

Commit c76c9de

Browse files
committed
Migrate to non-static utils
1 parent 505f316 commit c76c9de

File tree

6 files changed

+34
-25
lines changed

6 files changed

+34
-25
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"simplesamlphp/xml-common": "^0.0.12"
3030
},
3131
"require-dev": {
32-
"simplesamlphp/simplesamlphp-test-framework": "~1.0.4"
32+
"simplesamlphp/simplesamlphp-test-framework": "~1.1.0"
3333
},
3434
"support": {
3535
"issues": "https://github.com/simplesamlphp/simplesamlphp-module-casserver/issues",

lib/Cas/Ticket/TicketFactory.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
namespace SimpleSAML\Module\casserver\Cas\Ticket;
2727

2828
use SimpleSAML\Configuration;
29-
use SimpleSAML\Utils\Random;
29+
use SimpleSAML\Utils;
3030

3131
class TicketFactory
3232
{
@@ -58,10 +58,11 @@ public function __construct(Configuration $config)
5858
*/
5959
public function createSessionTicket(string $sessionId, int $expiresAt): array
6060
{
61+
$randomUtils = new Utils\Random();
6162
return [
6263
'id' => $sessionId,
6364
'validBefore' => $expiresAt,
64-
'renewId' => Random::generateID()
65+
'renewId' => $randomUtils->generateID()
6566
];
6667
}
6768

@@ -72,7 +73,8 @@ public function createSessionTicket(string $sessionId, int $expiresAt): array
7273
*/
7374
public function createServiceTicket(array $content): array
7475
{
75-
$id = str_replace('_', 'ST-', Random::generateID());
76+
$randomUtils = new Utils\Random();
77+
$id = str_replace('_', 'ST-', $randomUtils->generateID());
7678
$expiresAt = time() + $this->serviceTicketExpireTime;
7779

7880
return array_merge(['id' => $id, 'validBefore' => $expiresAt], $content);
@@ -85,8 +87,9 @@ public function createServiceTicket(array $content): array
8587
*/
8688
public function createProxyGrantingTicket(array $content): array
8789
{
88-
$id = str_replace('_', 'PGT-', Random::generateID());
89-
$iou = str_replace('_', 'PGTIOU-', Random::generateID());
90+
$randomUtils = new Utils\Random();
91+
$id = str_replace('_', 'PGT-', $randomUtils->generateID());
92+
$iou = str_replace('_', 'PGTIOU-', $randomUtils->generateID());
9093

9194
$expireAt = time() + $this->proxyGrantingTicketExpireTime;
9295

@@ -100,7 +103,8 @@ public function createProxyGrantingTicket(array $content): array
100103
*/
101104
public function createProxyTicket(array $content): array
102105
{
103-
$id = str_replace('_', 'PT-', Random::generateID());
106+
$randomUtils = new Utils\Random();
107+
$id = str_replace('_', 'PT-', $randomUtils->generateID());
104108
$expiresAt = time() + $this->proxyTicketExpireTime;
105109

106110
return array_merge(['id' => $id, 'validBefore' => $expiresAt], $content);

lib/Shib13/AuthnResponse.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ public function validate(): bool
135135
$this->validator->validateFingerprint($certFingerprints);
136136
} elseif ($md->hasValue('caFile')) {
137137
// Validate against CA
138-
$this->validator->validateCA(Utils\Config::getCertPath($md->getString('caFile')));
138+
$configUtils = new Utils\Config();
139+
$this->validator->validateCA($configUtils->getCertPath($md->getString('caFile')));
139140
} else {
140141
throw new Error\Exception(
141142
'Missing certificate in Shibboleth 1.3 IdP Remote metadata for identity provider [' . $issuer . '].'
@@ -354,23 +355,25 @@ public function generate(Configuration $idp, Configuration $sp, string $shire, ?
354355
$scopedAttributes = [];
355356
}
356357

357-
$id = Utils\Random::generateID();
358+
$randomUtils = new Utils\Random();
359+
$timeUtils = new Utils\Time();
358360

359-
$issueInstant = Utils\Time::generateTimestamp();
361+
$id = $randomUtils->generateID();
362+
$issueInstant = $timeUtils->generateTimestamp();
360363

361364
// 30 seconds timeskew back in time to allow differing clocks
362-
$notBefore = Utils\Time::generateTimestamp(time() - 30);
365+
$notBefore = $timeUtils->generateTimestamp(time() - 30);
363366

364-
$assertionExpire = Utils\Time::generateTimestamp(time() + 300); // 5 minutes
365-
$assertionid = Utils\Random::generateID();
367+
$assertionExpire = $timeUtils->generateTimestamp(time() + 300); // 5 minutes
368+
$assertionid = $randomUtils->generateID();
366369

367370
$spEntityId = $sp->getString('entityid');
368371

369372
$audience = $sp->getString('audience', $spEntityId);
370373
$base64 = $sp->getBoolean('base64attributes', false);
371374

372375
$namequalifier = $sp->getString('NameQualifier', $spEntityId);
373-
$nameid = Utils\Random::generateID();
376+
$nameid = $randomUtils->generateID();
374377
$subjectNode =
375378
'<Subject>' .
376379
'<NameIdentifier' .

tests/lib/Ticket/DelegatingTicketStoreTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use SimpleSAML\Module\casserver\Cas\Ticket\DelegatingTicketStore;
1010
use SimpleSAML\Module\casserver\Cas\Ticket\FileSystemTicketStore;
1111
use SimpleSAML\Module\casserver\Cas\Ticket\TicketStore;
12-
use SimpleSAML\Utils\Config;
12+
use SimpleSAML\Utils;
1313

1414
class DelegatingTicketStoreTest extends TestCase
1515
{
@@ -33,8 +33,9 @@ class DelegatingTicketStoreTest extends TestCase
3333
*/
3434
public function setup(): void
3535
{
36+
$configUtils = new Utils\Config();
3637
putenv('SIMPLESAMLPHP_CONFIG_DIR=' . dirname(dirname(__DIR__)) . '/config');
37-
Configuration::setConfigDir(Config::getConfigDir());
38+
Configuration::setConfigDir($configUtils->getConfigDir());
3839
$this->ticketstoreConfig = array(
3940
'delegateTo' => 'all',
4041
'ticketStores' => [

tests/lib/TicketValidatorTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use SimpleSAML\Module\casserver\Cas\Ticket\FileSystemTicketStore;
1111
use SimpleSAML\Module\casserver\Cas\Ticket\TicketStore;
1212
use SimpleSAML\Module\casserver\Cas\TicketValidator;
13-
use SimpleSAML\Utils\Random;
13+
use SimpleSAML\Utils;
1414

1515
class TicketValidatorTest extends TestCase
1616
{
@@ -165,7 +165,8 @@ public function urlSanitizationProvider(): array
165165
*/
166166
private function createTicket(string $serviceUrl, int $expiration = 0): array
167167
{
168-
$id = Random::generateID();
168+
$randomUtils = new Utils\Random();
169+
$id = $randomUtils->generateID();
169170
$serviceTicket = [
170171
'id' => $id,
171172
'validBefore' => time() + $expiration,

www/login.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
use SimpleSAML\Logger;
3939
use SimpleSAML\Module;
4040
use SimpleSAML\Session;
41-
use SimpleSAML\Utils\HTTP;
41+
use SimpleSAML\Utils;
4242

4343
require_once('utility/urlUtils.php');
4444

@@ -97,7 +97,7 @@
9797
/** @var $ticketFactory TicketFactory */
9898
/** @psalm-suppress InvalidStringClass */
9999
$ticketFactory = new $ticketFactoryClass($casconfig);
100-
100+
$httpUtils = new Utils\HTTP();
101101
$session = Session::getSessionFromRequest();
102102

103103
$sessionTicket = $ticketStore->getTicket($session->getSessionId());
@@ -139,7 +139,7 @@
139139
$query['debugMode'] = $_REQUEST['debugMode'];
140140
}
141141

142-
$returnUrl = HTTP::getSelfURLNoQuery() . '?' . http_build_query($query);
142+
$returnUrl = $httpUtils->getSelfURLNoQuery() . '?' . http_build_query($query);
143143

144144
$params = [
145145
'ForceAuthn' => $forceAuthn,
@@ -227,12 +227,12 @@
227227
echo '<pre>' . htmlspecialchars($casResponse) . '</pre>';
228228
}
229229
} elseif ($redirect) {
230-
HTTP::redirectTrustedURL(HTTP::addURLParameters($serviceUrl, $parameters));
230+
$httpUtils->redirectTrustedURL($httpUtils->addURLParameters($serviceUrl, $parameters));
231231
} else {
232-
HTTP::submitPOSTData($serviceUrl, $parameters);
232+
$httpUtils->submitPOSTData($serviceUrl, $parameters);
233233
}
234234
} else {
235-
HTTP::redirectTrustedURL(
236-
HTTP::addURLParameters(Module::getModuleURL('casserver/loggedIn.php'), $parameters)
235+
$httpUtils->redirectTrustedURL(
236+
$httpUtils->addURLParameters(Module::getModuleURL('casserver/loggedIn.php'), $parameters)
237237
);
238238
}

0 commit comments

Comments
 (0)