-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathConfigController.php
More file actions
107 lines (94 loc) · 3.75 KB
/
ConfigController.php
File metadata and controls
107 lines (94 loc) · 3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
declare(strict_types=1);
namespace SimpleSAML\Module\oidc\Controllers\Admin;
use SimpleSAML\Locale\Translate;
use SimpleSAML\Module\oidc\Admin\Authorization;
use SimpleSAML\Module\oidc\Codebooks\RoutesEnum;
use SimpleSAML\Module\oidc\Factories\TemplateFactory;
use SimpleSAML\Module\oidc\ModuleConfig;
use SimpleSAML\Module\oidc\Services\DatabaseMigration;
use SimpleSAML\Module\oidc\Services\SessionMessagesService;
use SimpleSAML\Module\oidc\Utils\Routes;
use SimpleSAML\OpenID\Federation;
use Symfony\Component\HttpFoundation\Response;
class ConfigController
{
public function __construct(
protected readonly ModuleConfig $moduleConfig,
protected readonly TemplateFactory $templateFactory,
protected readonly Authorization $authorization,
protected readonly DatabaseMigration $databaseMigration,
protected readonly SessionMessagesService $sessionMessagesService,
protected readonly Federation $federation,
protected readonly Routes $routes,
) {
$this->authorization->requireAdmin(true);
}
public function migrations(): Response
{
return $this->templateFactory->build(
'oidc:config/migrations.twig',
[
'databaseMigration' => $this->databaseMigration,
],
RoutesEnum::AdminMigrations->value,
);
}
public function runMigrations(): Response
{
if ($this->databaseMigration->isMigrated()) {
$message = Translate::noop('Database is already migrated.');
$this->sessionMessagesService->addMessage($message);
return $this->routes->newRedirectResponseToModuleUrl(RoutesEnum::AdminMigrations->value);
}
$this->databaseMigration->migrate();
$message = Translate::noop('Database migrated successfully.');
$this->sessionMessagesService->addMessage($message);
return $this->routes->newRedirectResponseToModuleUrl(RoutesEnum::AdminMigrations->value);
}
public function protocolSettings(): Response
{
return $this->templateFactory->build(
'oidc:config/protocol.twig',
[
'moduleConfig' => $this->moduleConfig,
],
RoutesEnum::AdminConfigProtocol->value,
);
}
public function federationSettings(): Response
{
$trustMarks = [];
if (is_array($trustMarkTokens = $this->moduleConfig->getFederationTrustMarkTokens())) {
$trustMarks = array_map(
function (string $token): Federation\TrustMark {
return $this->federation->trustMarkFactory()->fromToken($token);
},
$trustMarkTokens,
);
}
if (is_array($dynamicTrustMarks = $this->moduleConfig->getFederationDynamicTrustMarks())) {
/**
* @var non-empty-string $trustMarkId
* @var non-empty-string $trustMarkIssuerId
*/
foreach ($dynamicTrustMarks as $trustMarkId => $trustMarkIssuerId) {
$trustMarkIssuerConfigurationStatement = $this->federation->entityStatementFetcher()
->fromCacheOrWellKnownEndpoint($trustMarkIssuerId);
$trustMarks[] = $this->federation->trustMarkFetcher()->fromCacheOrFederationTrustMarkEndpoint(
$trustMarkId,
$this->moduleConfig->getIssuer(),
$trustMarkIssuerConfigurationStatement,
);
}
}
return $this->templateFactory->build(
'oidc:config/federation.twig',
[
'moduleConfig' => $this->moduleConfig,
'trustMarks' => $trustMarks,
],
RoutesEnum::AdminConfigFederation->value,
);
}
}