Skip to content

Commit

Permalink
WIP move to SSP UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Marko Ivančić committed Nov 19, 2024
1 parent 14e91bc commit 76073b5
Show file tree
Hide file tree
Showing 16 changed files with 555 additions and 203 deletions.
29 changes: 28 additions & 1 deletion public/assets/css/src/default.css
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,14 @@ h4 {
background-color: #fff;
}

ul.config {
ul.disc {
list-style: disc outside none;
}

em {
font-style: italic;
}

/* Text colors */
.black-text { color: black; }
.red-text { color: red; }
Expand All @@ -85,3 +89,26 @@ ul.config {
.cyan-text { color: cyan; }
.lightcyan-text { color: lightcyan; }
.white-text { color: white; }

/* Button sizes */
.button-small {
font-size: 75%;
}

/* Client Table */
table.client-table {
width: 100%;
}

.client-col.col-info {
width: 79%;
}

.client-col.col-actions {
width: 21%;
}

.client-col.col-property {
width: 25%;
font-weight: bolder;
}
2 changes: 2 additions & 0 deletions routing/routes/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@

$routes->add(RoutesEnum::AdminClients->name, RoutesEnum::AdminClients->value)
->controller([ClientController::class, 'index']);
$routes->add(RoutesEnum::AdminClientsShow->name, RoutesEnum::AdminClientsShow->value)
->controller([ClientController::class, 'show']);

/*****************************************************************************************************************
* OpenID Connect
Expand Down
36 changes: 34 additions & 2 deletions src/Admin/Authorization.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,25 @@
use SimpleSAML\Locale\Translate;
use SimpleSAML\Module\oidc\Bridges\SspBridge;
use SimpleSAML\Module\oidc\Exceptions\AuthorizationException;
use SimpleSAML\Module\oidc\Services\AuthContextService;

class Authorization
{
public function __construct(

Check warning on line 15 in src/Admin/Authorization.php

View check run for this annotation

Codecov / codecov/patch

src/Admin/Authorization.php#L15

Added line #L15 was not covered by tests
protected readonly SspBridge $sspBridge,
protected readonly AuthContextService $authContextService,
) {
}

Check warning on line 19 in src/Admin/Authorization.php

View check run for this annotation

Codecov / codecov/patch

src/Admin/Authorization.php#L19

Added line #L19 was not covered by tests

public function isAdmin(): bool

Check warning on line 21 in src/Admin/Authorization.php

View check run for this annotation

Codecov / codecov/patch

src/Admin/Authorization.php#L21

Added line #L21 was not covered by tests
{
return $this->sspBridge->utils()->auth()->isAdmin();

Check warning on line 23 in src/Admin/Authorization.php

View check run for this annotation

Codecov / codecov/patch

src/Admin/Authorization.php#L23

Added line #L23 was not covered by tests
}

/**
* @throws \SimpleSAML\Module\oidc\Exceptions\AuthorizationException
*/
public function requireSspAdmin(bool $forceAdminAuthentication = false): void
public function requireAdmin(bool $forceAdminAuthentication = false): void

Check warning on line 29 in src/Admin/Authorization.php

View check run for this annotation

Codecov / codecov/patch

src/Admin/Authorization.php#L29

Added line #L29 was not covered by tests
{
if ($forceAdminAuthentication) {

Check warning on line 31 in src/Admin/Authorization.php

View check run for this annotation

Codecov / codecov/patch

src/Admin/Authorization.php#L31

Added line #L31 was not covered by tests
try {
Expand All @@ -33,8 +40,33 @@ public function requireSspAdmin(bool $forceAdminAuthentication = false): void
}
}

if (! $this->sspBridge->utils()->auth()->isAdmin()) {
if (! $this->isAdmin()) {
throw new AuthorizationException(Translate::noop('SimpleSAMLphp admin access required.'));

Check warning on line 44 in src/Admin/Authorization.php

View check run for this annotation

Codecov / codecov/patch

src/Admin/Authorization.php#L43-L44

Added lines #L43 - L44 were not covered by tests
}
}

/**
* @throws \SimpleSAML\Module\oidc\Exceptions\AuthorizationException
*/
public function requireAdminOrUserWithPermission(string $permission): void

Check warning on line 51 in src/Admin/Authorization.php

View check run for this annotation

Codecov / codecov/patch

src/Admin/Authorization.php#L51

Added line #L51 was not covered by tests
{
if ($this->isAdmin()) {
return;

Check warning on line 54 in src/Admin/Authorization.php

View check run for this annotation

Codecov / codecov/patch

src/Admin/Authorization.php#L53-L54

Added lines #L53 - L54 were not covered by tests
}

try {
$this->authContextService->requirePermission($permission);
} catch (Exception $exception) {
throw new AuthorizationException(
Translate::noop('User not authorized.'),
$exception->getCode(),
$exception,
);

Check warning on line 64 in src/Admin/Authorization.php

View check run for this annotation

Codecov / codecov/patch

src/Admin/Authorization.php#L58-L64

Added lines #L58 - L64 were not covered by tests
}
}

public function getUserId(): string

Check warning on line 68 in src/Admin/Authorization.php

View check run for this annotation

Codecov / codecov/patch

src/Admin/Authorization.php#L68

Added line #L68 was not covered by tests
{
return $this->authContextService->getAuthUserId();

Check warning on line 70 in src/Admin/Authorization.php

View check run for this annotation

Codecov / codecov/patch

src/Admin/Authorization.php#L70

Added line #L70 was not covered by tests
}
}
1 change: 1 addition & 0 deletions src/Codebooks/RoutesEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ enum RoutesEnum: string
// Client management

case AdminClients = 'admin/clients';
case AdminClientsShow = 'admin/clients/show';

/*****************************************************************************************************************
* OpenID Connect
Expand Down
60 changes: 57 additions & 3 deletions src/Controllers/Admin/ClientController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,77 @@

use SimpleSAML\Module\oidc\Admin\Authorization;
use SimpleSAML\Module\oidc\Codebooks\RoutesEnum;
use SimpleSAML\Module\oidc\Entities\Interfaces\ClientEntityInterface;
use SimpleSAML\Module\oidc\Exceptions\OidcException;
use SimpleSAML\Module\oidc\Factories\TemplateFactory;
use SimpleSAML\Module\oidc\Repositories\AllowedOriginRepository;
use SimpleSAML\Module\oidc\Repositories\ClientRepository;
use SimpleSAML\Module\oidc\Services\AuthContextService;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class ClientController
{
public function __construct(

Check warning on line 20 in src/Controllers/Admin/ClientController.php

View check run for this annotation

Codecov / codecov/patch

src/Controllers/Admin/ClientController.php#L20

Added line #L20 was not covered by tests
protected readonly TemplateFactory $templateFactory,
protected readonly Authorization $authorization,
protected readonly ClientRepository $clientRepository,
protected readonly AllowedOriginRepository $allowedOriginRepository,
) {
$this->authorization->requireSspAdmin(true);
$this->authorization->requireAdminOrUserWithPermission(AuthContextService::PERM_CLIENT);

Check warning on line 26 in src/Controllers/Admin/ClientController.php

View check run for this annotation

Codecov / codecov/patch

src/Controllers/Admin/ClientController.php#L26

Added line #L26 was not covered by tests
}
public function index(): Response

/**
* @throws \SimpleSAML\Module\oidc\Server\Exceptions\OidcServerException
* @throws \JsonException
* @throws \SimpleSAML\Module\oidc\Exceptions\OidcException
*/
protected function getClientFromRequest(Request $request): ClientEntityInterface

Check warning on line 34 in src/Controllers/Admin/ClientController.php

View check run for this annotation

Codecov / codecov/patch

src/Controllers/Admin/ClientController.php#L34

Added line #L34 was not covered by tests
{
($clientId = $request->query->getString('client_id'))
|| throw new OidcException('Client ID not provided.');

Check warning on line 37 in src/Controllers/Admin/ClientController.php

View check run for this annotation

Codecov / codecov/patch

src/Controllers/Admin/ClientController.php#L36-L37

Added lines #L36 - L37 were not covered by tests

$authedUserId = $this->authorization->isAdmin() ? null : $this->authorization->getUserId();

Check warning on line 39 in src/Controllers/Admin/ClientController.php

View check run for this annotation

Codecov / codecov/patch

src/Controllers/Admin/ClientController.php#L39

Added line #L39 was not covered by tests

return $this->clientRepository->findById($clientId, $authedUserId) ??
throw new OidcException('Client not found.');

Check warning on line 42 in src/Controllers/Admin/ClientController.php

View check run for this annotation

Codecov / codecov/patch

src/Controllers/Admin/ClientController.php#L41-L42

Added lines #L41 - L42 were not covered by tests
}

public function index(Request $request): Response

Check warning on line 45 in src/Controllers/Admin/ClientController.php

View check run for this annotation

Codecov / codecov/patch

src/Controllers/Admin/ClientController.php#L45

Added line #L45 was not covered by tests
{
$page = $request->query->getInt('page', 1);
$query = $request->query->getString('q', '');
$authedUserId = $this->authorization->isAdmin() ? null : $this->authorization->getUserId();

Check warning on line 49 in src/Controllers/Admin/ClientController.php

View check run for this annotation

Codecov / codecov/patch

src/Controllers/Admin/ClientController.php#L47-L49

Added lines #L47 - L49 were not covered by tests

$pagination = $this->clientRepository->findPaginated($page, $query, $authedUserId);

Check warning on line 51 in src/Controllers/Admin/ClientController.php

View check run for this annotation

Codecov / codecov/patch

src/Controllers/Admin/ClientController.php#L51

Added line #L51 was not covered by tests


return $this->templateFactory->build(
'oidc:clients.twig',
[
//
'clients' => $pagination['items'],
'numPages' => $pagination['numPages'],
'currentPage' => $pagination['currentPage'],
'query' => $query,
],
RoutesEnum::AdminClients->value,
);

Check warning on line 63 in src/Controllers/Admin/ClientController.php

View check run for this annotation

Codecov / codecov/patch

src/Controllers/Admin/ClientController.php#L54-L63

Added lines #L54 - L63 were not covered by tests
}

/**
* @throws \SimpleSAML\Module\oidc\Exceptions\OidcException
*/
public function show(Request $request): Response

Check warning on line 69 in src/Controllers/Admin/ClientController.php

View check run for this annotation

Codecov / codecov/patch

src/Controllers/Admin/ClientController.php#L69

Added line #L69 was not covered by tests
{
$client = $this->getClientFromRequest($request);
$allowedOrigins = $this->allowedOriginRepository->get($client->getIdentifier());

Check warning on line 72 in src/Controllers/Admin/ClientController.php

View check run for this annotation

Codecov / codecov/patch

src/Controllers/Admin/ClientController.php#L71-L72

Added lines #L71 - L72 were not covered by tests

// TODO mivanci rename *-ssp.twig templates after removing old ones.
return $this->templateFactory->build(
'oidc:clients/show-ssp.twig',
[
'client' => $client,
'allowedOrigins' => $allowedOrigins,
],
RoutesEnum::AdminClients->value,
);

Check warning on line 82 in src/Controllers/Admin/ClientController.php

View check run for this annotation

Codecov / codecov/patch

src/Controllers/Admin/ClientController.php#L75-L82

Added lines #L75 - L82 were not covered by tests
Expand Down
15 changes: 14 additions & 1 deletion src/Controllers/Admin/ConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use SimpleSAML\Module\oidc\ModuleConfig;
use SimpleSAML\Module\oidc\Services\DatabaseMigration;
use SimpleSAML\Module\oidc\Services\SessionMessagesService;
use SimpleSAML\OpenID\Federation;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;

Expand All @@ -22,8 +23,9 @@ public function __construct(
protected readonly Authorization $authorization,
protected readonly DatabaseMigration $databaseMigration,
protected readonly SessionMessagesService $sessionMessagesService,
protected readonly Federation $federation,
) {
$this->authorization->requireSspAdmin(true);
$this->authorization->requireAdmin(true);

Check warning on line 28 in src/Controllers/Admin/ConfigController.php

View check run for this annotation

Codecov / codecov/patch

src/Controllers/Admin/ConfigController.php#L28

Added line #L28 was not covered by tests
}

public function migrations(): Response

Check warning on line 31 in src/Controllers/Admin/ConfigController.php

View check run for this annotation

Codecov / codecov/patch

src/Controllers/Admin/ConfigController.php#L31

Added line #L31 was not covered by tests
Expand Down Expand Up @@ -65,10 +67,21 @@ public function protocolSettings(): Response

public function federationSettings(): Response

Check warning on line 68 in src/Controllers/Admin/ConfigController.php

View check run for this annotation

Codecov / codecov/patch

src/Controllers/Admin/ConfigController.php#L68

Added line #L68 was not covered by tests
{
$trustMarks = null;
if (is_array($trustMarkTokens = $this->moduleConfig->getFederationTrustMarkTokens())) {
$trustMarks = array_map(
function (string $token): Federation\TrustMark {
return $this->federation->trustMarkFactory()->fromToken($token);
},
$trustMarkTokens,
);

Check warning on line 77 in src/Controllers/Admin/ConfigController.php

View check run for this annotation

Codecov / codecov/patch

src/Controllers/Admin/ConfigController.php#L70-L77

Added lines #L70 - L77 were not covered by tests
}

return $this->templateFactory->build(
'oidc:config/federation.twig',
[
'moduleConfig' => $this->moduleConfig,
'trustMarks' => $trustMarks,
],
RoutesEnum::AdminConfigFederation->value,
);

Check warning on line 87 in src/Controllers/Admin/ConfigController.php

View check run for this annotation

Codecov / codecov/patch

src/Controllers/Admin/ConfigController.php#L80-L87

Added lines #L80 - L87 were not covered by tests
Expand Down
4 changes: 2 additions & 2 deletions src/Controllers/Federation/EntityStatementController.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public function configuration(): Response

$this->federationCache?->set(
$entityConfigurationToken,
$this->moduleConfig->getFederationEntityStatementCacheDuration(),
$this->moduleConfig->getFederationEntityStatementCacheDurationForProduced(),

Check warning on line 161 in src/Controllers/Federation/EntityStatementController.php

View check run for this annotation

Codecov / codecov/patch

src/Controllers/Federation/EntityStatementController.php#L161

Added line #L161 was not covered by tests
self::KEY_OP_ENTITY_CONFIGURATION_STATEMENT,
$this->moduleConfig->getIssuer(),
);
Expand Down Expand Up @@ -253,7 +253,7 @@ public function fetch(Request $request): Response

$this->federationCache?->set(
$subordinateStatementToken,
$this->moduleConfig->getFederationEntityStatementCacheDuration(),
$this->moduleConfig->getFederationEntityStatementCacheDurationForProduced(),

Check warning on line 256 in src/Controllers/Federation/EntityStatementController.php

View check run for this annotation

Codecov / codecov/patch

src/Controllers/Federation/EntityStatementController.php#L256

Added line #L256 was not covered by tests
self::KEY_RP_SUBORDINATE_ENTITY_STATEMENT,
$subject,
);
Expand Down
2 changes: 1 addition & 1 deletion src/Factories/FederationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function build(): Federation

return new Federation(
supportedAlgorithms: $supportedAlgorithms,
maxCacheDuration: $this->moduleConfig->getFederationCacheMaxDuration(),
maxCacheDuration: $this->moduleConfig->getFederationCacheMaxDurationForFetched(),

Check warning on line 43 in src/Factories/FederationFactory.php

View check run for this annotation

Codecov / codecov/patch

src/Factories/FederationFactory.php#L43

Added line #L43 was not covered by tests
cache: $this->federationCache?->cache,
logger: $this->loggerService,
);
Expand Down
2 changes: 1 addition & 1 deletion src/Factories/JwksFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function build(): Jwks

return new Jwks(
supportedAlgorithms: $supportedAlgorithms,
maxCacheDuration: $this->moduleConfig->getFederationCacheMaxDuration(),
maxCacheDuration: $this->moduleConfig->getFederationCacheMaxDurationForFetched(),

Check warning on line 38 in src/Factories/JwksFactory.php

View check run for this annotation

Codecov / codecov/patch

src/Factories/JwksFactory.php#L38

Added line #L38 was not covered by tests
cache: $this->federationCache?->cache,
logger: $this->loggerService,
);
Expand Down
2 changes: 1 addition & 1 deletion src/Factories/TemplateFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ protected function includeDefaultMenuItems(): void
$this->oidcMenu->addItem(
$this->oidcMenu->buildItem(
$this->moduleConfig->getModuleUrl(RoutesEnum::AdminClients->value),
Translate::noop('Clients'),
Translate::noop('Client Registry'),
),
);

Check warning on line 116 in src/Factories/TemplateFactory.php

View check run for this annotation

Codecov / codecov/patch

src/Factories/TemplateFactory.php#L111-L116

Added lines #L111 - L116 were not covered by tests
}
Expand Down
4 changes: 2 additions & 2 deletions src/ModuleConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ public function getFederationEntityStatementDuration(): DateInterval
/**
* @throws \Exception
*/
public function getFederationEntityStatementCacheDuration(): DateInterval
public function getFederationEntityStatementCacheDurationForProduced(): DateInterval

Check warning on line 537 in src/ModuleConfig.php

View check run for this annotation

Codecov / codecov/patch

src/ModuleConfig.php#L537

Added line #L537 was not covered by tests
{
return new DateInterval(
$this->config()->getOptionalString(
Expand Down Expand Up @@ -614,7 +614,7 @@ public function getFederationCacheAdapterArguments(): array
return $this->config()->getOptionalArray(self::OPTION_FEDERATION_CACHE_ADAPTER_ARGUMENTS, []);
}

public function getFederationCacheMaxDuration(): DateInterval
public function getFederationCacheMaxDurationForFetched(): DateInterval

Check warning on line 617 in src/ModuleConfig.php

View check run for this annotation

Codecov / codecov/patch

src/ModuleConfig.php#L617

Added line #L617 was not covered by tests
{
return new DateInterval(
$this->config()->getOptionalString(self::OPTION_FEDERATION_CACHE_MAX_DURATION_FOR_FETCHED, 'PT6H'),

Check warning on line 620 in src/ModuleConfig.php

View check run for this annotation

Codecov / codecov/patch

src/ModuleConfig.php#L620

Added line #L620 was not covered by tests
Expand Down
9 changes: 7 additions & 2 deletions src/Utils/Routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public function getModuleUrl(string $resource = '', array $parameters = []): str
return $this->sspBridge->module()->getModuleUrl($resource, $parameters);

Check warning on line 23 in src/Utils/Routes.php

View check run for this annotation

Codecov / codecov/patch

src/Utils/Routes.php#L23

Added line #L23 was not covered by tests
}


/*****************************************************************************************************************
* Admin area
****************************************************************************************************************/
Expand Down Expand Up @@ -52,7 +51,13 @@ public function urlAdminMigrationsRun(array $parameters = []): string

public function urlAdminClients(array $parameters = []): string

Check warning on line 52 in src/Utils/Routes.php

View check run for this annotation

Codecov / codecov/patch

src/Utils/Routes.php#L52

Added line #L52 was not covered by tests
{
return $this->getModuleUrl(RoutesEnum::AdminMigrationsRun->value, $parameters);
return $this->getModuleUrl(RoutesEnum::AdminClients->value, $parameters);

Check warning on line 54 in src/Utils/Routes.php

View check run for this annotation

Codecov / codecov/patch

src/Utils/Routes.php#L54

Added line #L54 was not covered by tests
}

public function urlAdminClientsShow(string $clientId, array $parameters = []): string

Check warning on line 57 in src/Utils/Routes.php

View check run for this annotation

Codecov / codecov/patch

src/Utils/Routes.php#L57

Added line #L57 was not covered by tests
{
$parameters['client_id'] = $clientId;
return $this->getModuleUrl(RoutesEnum::AdminClientsShow->value, $parameters);

Check warning on line 60 in src/Utils/Routes.php

View check run for this annotation

Codecov / codecov/patch

src/Utils/Routes.php#L59-L60

Added lines #L59 - L60 were not covered by tests
}

/*****************************************************************************************************************
Expand Down
Loading

0 comments on commit 76073b5

Please sign in to comment.