Skip to content

Commit 76073b5

Browse files
committed
WIP move to SSP UI
1 parent 14e91bc commit 76073b5

File tree

16 files changed

+555
-203
lines changed

16 files changed

+555
-203
lines changed

public/assets/css/src/default.css

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,14 @@ h4 {
7070
background-color: #fff;
7171
}
7272

73-
ul.config {
73+
ul.disc {
7474
list-style: disc outside none;
7575
}
7676

77+
em {
78+
font-style: italic;
79+
}
80+
7781
/* Text colors */
7882
.black-text { color: black; }
7983
.red-text { color: red; }
@@ -85,3 +89,26 @@ ul.config {
8589
.cyan-text { color: cyan; }
8690
.lightcyan-text { color: lightcyan; }
8791
.white-text { color: white; }
92+
93+
/* Button sizes */
94+
.button-small {
95+
font-size: 75%;
96+
}
97+
98+
/* Client Table */
99+
table.client-table {
100+
width: 100%;
101+
}
102+
103+
.client-col.col-info {
104+
width: 79%;
105+
}
106+
107+
.client-col.col-actions {
108+
width: 21%;
109+
}
110+
111+
.client-col.col-property {
112+
width: 25%;
113+
font-weight: bolder;
114+
}

routing/routes/routes.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141

4242
$routes->add(RoutesEnum::AdminClients->name, RoutesEnum::AdminClients->value)
4343
->controller([ClientController::class, 'index']);
44+
$routes->add(RoutesEnum::AdminClientsShow->name, RoutesEnum::AdminClientsShow->value)
45+
->controller([ClientController::class, 'show']);
4446

4547
/*****************************************************************************************************************
4648
* OpenID Connect

src/Admin/Authorization.php

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,25 @@
88
use SimpleSAML\Locale\Translate;
99
use SimpleSAML\Module\oidc\Bridges\SspBridge;
1010
use SimpleSAML\Module\oidc\Exceptions\AuthorizationException;
11+
use SimpleSAML\Module\oidc\Services\AuthContextService;
1112

1213
class Authorization
1314
{
1415
public function __construct(
1516
protected readonly SspBridge $sspBridge,
17+
protected readonly AuthContextService $authContextService,
1618
) {
1719
}
1820

21+
public function isAdmin(): bool
22+
{
23+
return $this->sspBridge->utils()->auth()->isAdmin();
24+
}
25+
1926
/**
2027
* @throws \SimpleSAML\Module\oidc\Exceptions\AuthorizationException
2128
*/
22-
public function requireSspAdmin(bool $forceAdminAuthentication = false): void
29+
public function requireAdmin(bool $forceAdminAuthentication = false): void
2330
{
2431
if ($forceAdminAuthentication) {
2532
try {
@@ -33,8 +40,33 @@ public function requireSspAdmin(bool $forceAdminAuthentication = false): void
3340
}
3441
}
3542

36-
if (! $this->sspBridge->utils()->auth()->isAdmin()) {
43+
if (! $this->isAdmin()) {
3744
throw new AuthorizationException(Translate::noop('SimpleSAMLphp admin access required.'));
3845
}
3946
}
47+
48+
/**
49+
* @throws \SimpleSAML\Module\oidc\Exceptions\AuthorizationException
50+
*/
51+
public function requireAdminOrUserWithPermission(string $permission): void
52+
{
53+
if ($this->isAdmin()) {
54+
return;
55+
}
56+
57+
try {
58+
$this->authContextService->requirePermission($permission);
59+
} catch (Exception $exception) {
60+
throw new AuthorizationException(
61+
Translate::noop('User not authorized.'),
62+
$exception->getCode(),
63+
$exception,
64+
);
65+
}
66+
}
67+
68+
public function getUserId(): string
69+
{
70+
return $this->authContextService->getAuthUserId();
71+
}
4072
}

src/Codebooks/RoutesEnum.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ enum RoutesEnum: string
1818
// Client management
1919

2020
case AdminClients = 'admin/clients';
21+
case AdminClientsShow = 'admin/clients/show';
2122

2223
/*****************************************************************************************************************
2324
* OpenID Connect

src/Controllers/Admin/ClientController.php

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,77 @@
66

77
use SimpleSAML\Module\oidc\Admin\Authorization;
88
use SimpleSAML\Module\oidc\Codebooks\RoutesEnum;
9+
use SimpleSAML\Module\oidc\Entities\Interfaces\ClientEntityInterface;
10+
use SimpleSAML\Module\oidc\Exceptions\OidcException;
911
use SimpleSAML\Module\oidc\Factories\TemplateFactory;
12+
use SimpleSAML\Module\oidc\Repositories\AllowedOriginRepository;
13+
use SimpleSAML\Module\oidc\Repositories\ClientRepository;
14+
use SimpleSAML\Module\oidc\Services\AuthContextService;
15+
use Symfony\Component\HttpFoundation\Request;
1016
use Symfony\Component\HttpFoundation\Response;
1117

1218
class ClientController
1319
{
1420
public function __construct(
1521
protected readonly TemplateFactory $templateFactory,
1622
protected readonly Authorization $authorization,
23+
protected readonly ClientRepository $clientRepository,
24+
protected readonly AllowedOriginRepository $allowedOriginRepository,
1725
) {
18-
$this->authorization->requireSspAdmin(true);
26+
$this->authorization->requireAdminOrUserWithPermission(AuthContextService::PERM_CLIENT);
1927
}
20-
public function index(): Response
28+
29+
/**
30+
* @throws \SimpleSAML\Module\oidc\Server\Exceptions\OidcServerException
31+
* @throws \JsonException
32+
* @throws \SimpleSAML\Module\oidc\Exceptions\OidcException
33+
*/
34+
protected function getClientFromRequest(Request $request): ClientEntityInterface
2135
{
36+
($clientId = $request->query->getString('client_id'))
37+
|| throw new OidcException('Client ID not provided.');
38+
39+
$authedUserId = $this->authorization->isAdmin() ? null : $this->authorization->getUserId();
40+
41+
return $this->clientRepository->findById($clientId, $authedUserId) ??
42+
throw new OidcException('Client not found.');
43+
}
44+
45+
public function index(Request $request): Response
46+
{
47+
$page = $request->query->getInt('page', 1);
48+
$query = $request->query->getString('q', '');
49+
$authedUserId = $this->authorization->isAdmin() ? null : $this->authorization->getUserId();
50+
51+
$pagination = $this->clientRepository->findPaginated($page, $query, $authedUserId);
52+
53+
2254
return $this->templateFactory->build(
2355
'oidc:clients.twig',
2456
[
25-
//
57+
'clients' => $pagination['items'],
58+
'numPages' => $pagination['numPages'],
59+
'currentPage' => $pagination['currentPage'],
60+
'query' => $query,
61+
],
62+
RoutesEnum::AdminClients->value,
63+
);
64+
}
65+
66+
/**
67+
* @throws \SimpleSAML\Module\oidc\Exceptions\OidcException
68+
*/
69+
public function show(Request $request): Response
70+
{
71+
$client = $this->getClientFromRequest($request);
72+
$allowedOrigins = $this->allowedOriginRepository->get($client->getIdentifier());
73+
74+
// TODO mivanci rename *-ssp.twig templates after removing old ones.
75+
return $this->templateFactory->build(
76+
'oidc:clients/show-ssp.twig',
77+
[
78+
'client' => $client,
79+
'allowedOrigins' => $allowedOrigins,
2680
],
2781
RoutesEnum::AdminClients->value,
2882
);

src/Controllers/Admin/ConfigController.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use SimpleSAML\Module\oidc\ModuleConfig;
1212
use SimpleSAML\Module\oidc\Services\DatabaseMigration;
1313
use SimpleSAML\Module\oidc\Services\SessionMessagesService;
14+
use SimpleSAML\OpenID\Federation;
1415
use Symfony\Component\HttpFoundation\RedirectResponse;
1516
use Symfony\Component\HttpFoundation\Response;
1617

@@ -22,8 +23,9 @@ public function __construct(
2223
protected readonly Authorization $authorization,
2324
protected readonly DatabaseMigration $databaseMigration,
2425
protected readonly SessionMessagesService $sessionMessagesService,
26+
protected readonly Federation $federation,
2527
) {
26-
$this->authorization->requireSspAdmin(true);
28+
$this->authorization->requireAdmin(true);
2729
}
2830

2931
public function migrations(): Response
@@ -65,10 +67,21 @@ public function protocolSettings(): Response
6567

6668
public function federationSettings(): Response
6769
{
70+
$trustMarks = null;
71+
if (is_array($trustMarkTokens = $this->moduleConfig->getFederationTrustMarkTokens())) {
72+
$trustMarks = array_map(
73+
function (string $token): Federation\TrustMark {
74+
return $this->federation->trustMarkFactory()->fromToken($token);
75+
},
76+
$trustMarkTokens,
77+
);
78+
}
79+
6880
return $this->templateFactory->build(
6981
'oidc:config/federation.twig',
7082
[
7183
'moduleConfig' => $this->moduleConfig,
84+
'trustMarks' => $trustMarks,
7285
],
7386
RoutesEnum::AdminConfigFederation->value,
7487
);

src/Controllers/Federation/EntityStatementController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public function configuration(): Response
158158

159159
$this->federationCache?->set(
160160
$entityConfigurationToken,
161-
$this->moduleConfig->getFederationEntityStatementCacheDuration(),
161+
$this->moduleConfig->getFederationEntityStatementCacheDurationForProduced(),
162162
self::KEY_OP_ENTITY_CONFIGURATION_STATEMENT,
163163
$this->moduleConfig->getIssuer(),
164164
);
@@ -253,7 +253,7 @@ public function fetch(Request $request): Response
253253

254254
$this->federationCache?->set(
255255
$subordinateStatementToken,
256-
$this->moduleConfig->getFederationEntityStatementCacheDuration(),
256+
$this->moduleConfig->getFederationEntityStatementCacheDurationForProduced(),
257257
self::KEY_RP_SUBORDINATE_ENTITY_STATEMENT,
258258
$subject,
259259
);

src/Factories/FederationFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function build(): Federation
4040

4141
return new Federation(
4242
supportedAlgorithms: $supportedAlgorithms,
43-
maxCacheDuration: $this->moduleConfig->getFederationCacheMaxDuration(),
43+
maxCacheDuration: $this->moduleConfig->getFederationCacheMaxDurationForFetched(),
4444
cache: $this->federationCache?->cache,
4545
logger: $this->loggerService,
4646
);

src/Factories/JwksFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function build(): Jwks
3535

3636
return new Jwks(
3737
supportedAlgorithms: $supportedAlgorithms,
38-
maxCacheDuration: $this->moduleConfig->getFederationCacheMaxDuration(),
38+
maxCacheDuration: $this->moduleConfig->getFederationCacheMaxDurationForFetched(),
3939
cache: $this->federationCache?->cache,
4040
logger: $this->loggerService,
4141
);

src/Factories/TemplateFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ protected function includeDefaultMenuItems(): void
111111
$this->oidcMenu->addItem(
112112
$this->oidcMenu->buildItem(
113113
$this->moduleConfig->getModuleUrl(RoutesEnum::AdminClients->value),
114-
Translate::noop('Clients'),
114+
Translate::noop('Client Registry'),
115115
),
116116
);
117117
}

0 commit comments

Comments
 (0)