Skip to content

Commit f94c683

Browse files
committed
WIP move to SSP UI
1 parent c4393ab commit f94c683

File tree

17 files changed

+326
-8
lines changed

17 files changed

+326
-8
lines changed

hooks/hook_adminmenu.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function oidc_hook_adminmenu(Template &$template): void
2020

2121
$oidcMenuEntry = [
2222
ModuleConfig::MODULE_NAME => [
23-
'url' => $moduleConfig->getModuleUrl(RoutesEnum::Configuration->value),
23+
'url' => $moduleConfig->getModuleUrl(RoutesEnum::AdminConfigOverview->value),
2424
'name' => Translate::noop('OIDC'),
2525
],
2626
];

public/assets/css/src/default.css

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
.wrap {
2+
max-width: 1300px;
3+
}
4+
5+
h2 {
6+
margin: 0.3em;
7+
}
8+
9+
h3 {
10+
margin-bottom: 0.5em;
11+
font-size: 1.2em;
12+
font-weight: 600;
13+
color: #1c1c1c;
14+
}
15+
16+
h4 {
17+
margin: 0.4em 0;
18+
font-size: 1.0em;
19+
font-weight: 600;
20+
color: #1c1c1c;
21+
}
22+
23+
/* Container to hold menu and content */
24+
.oidc-container {
25+
display: flex;
26+
max-width: inherit;
27+
margin: 0 auto;
28+
}
29+
30+
/* Style for the left menu */
31+
.menu {
32+
min-width: 200px;
33+
/*background-color: #f4f4f4;*/
34+
/*border-right: solid 1px #bbb;*/
35+
width: auto;
36+
}
37+
38+
/* Style for the menu items */
39+
.menu ul {
40+
list-style-type: none;
41+
padding: 0;
42+
}
43+
44+
.menu ul li {
45+
padding: 0.25rem;
46+
}
47+
48+
.menu ul li a {
49+
text-decoration: none;
50+
color: #333;
51+
display: block;
52+
padding: 0.5rem;
53+
}
54+
55+
.menu ul li a:hover {
56+
background-color: #ddd;
57+
padding: 0.5rem;
58+
}
59+
60+
.menu ul li a.active {
61+
background-color: #eeeeee;
62+
padding: 0.5rem;
63+
}
64+
65+
/* Style for the content area */
66+
.content {
67+
flex-grow: 1;
68+
padding: 20px;
69+
max-width: inherit;
70+
background-color: #fff;
71+
}

routing/routes/routes.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
use SimpleSAML\Module\oidc\Codebooks\RoutesEnum;
1010
use SimpleSAML\Module\oidc\Controller\AccessTokenController;
11+
use SimpleSAML\Module\oidc\Controller\AdminController;
1112
use SimpleSAML\Module\oidc\Controller\AuthorizationController;
1213
use SimpleSAML\Module\oidc\Controller\ConfigurationDiscoveryController;
1314
use SimpleSAML\Module\oidc\Controller\EndSessionController;
@@ -19,6 +20,15 @@
1920

2021
/** @psalm-suppress InvalidArgument */
2122
return function (RoutingConfigurator $routes): void {
23+
/**
24+
* Admin area routes.
25+
*/
26+
$routes->add(RoutesEnum::AdminConfigOverview->name, RoutesEnum::AdminConfigOverview->value)
27+
->controller([AdminController::class, 'configOverview']);
28+
29+
/**
30+
* OpenID Connect Discovery routes.
31+
*/
2232
$routes->add(RoutesEnum::Configuration->name, RoutesEnum::Configuration->value)
2333
->controller(ConfigurationDiscoveryController::class);
2434

routing/services/services.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ services:
2929
SimpleSAML\Module\oidc\Factories\:
3030
resource: '../../src/Factories/*'
3131

32+
SimpleSAML\Module\oidc\Admin\:
33+
resource: '../../src/Admin/*'
34+
3235
SimpleSAML\Module\oidc\Stores\:
3336
resource: '../../src/Stores/*'
3437

src/Admin/Authorization.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\Module\oidc\Admin;
6+
7+
use SimpleSAML\Error\Exception;
8+
use SimpleSAML\Locale\Translate;
9+
use SimpleSAML\Module\oidc\Bridges\SspBridge;
10+
use SimpleSAML\Module\oidc\Exceptions\AuthorizationException;
11+
12+
class Authorization
13+
{
14+
public function __construct(
15+
protected readonly SspBridge $sspBridge,
16+
) {
17+
}
18+
19+
/**
20+
* @throws \SimpleSAML\Module\oidc\Exceptions\AuthorizationException
21+
*/
22+
public function requireSspAdmin(bool $forceAdminAuthentication = false): void
23+
{
24+
if ($forceAdminAuthentication) {
25+
try {
26+
$this->sspBridge->utils()->auth()->requireAdmin();
27+
} catch (Exception $exception) {
28+
throw new AuthorizationException(
29+
Translate::noop('Unable to initiate SimpleSAMLphp admin authentication.'),
30+
$exception->getCode(),
31+
$exception,
32+
);
33+
}
34+
}
35+
36+
if (! $this->sspBridge->utils()->auth()->isAdmin()) {
37+
throw new AuthorizationException(Translate::noop('SimpleSAMLphp admin access required.'));
38+
}
39+
}
40+
}

src/Admin/Menu.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\Module\oidc\Admin;
6+
7+
use SimpleSAML\Module\oidc\Admin\Menu\Item;
8+
9+
class Menu
10+
{
11+
/**
12+
* @var array<Item>
13+
*/
14+
protected array $items = [];
15+
16+
protected ?string $activeHrefPath = null;
17+
18+
public function __construct(Item ...$items)
19+
{
20+
array_push($this->items, ...$items);
21+
}
22+
23+
public function addItem(Item $menuItem, int $offset = null): void
24+
{
25+
$offset ??= count($this->items);
26+
27+
array_splice($this->items, $offset, 0, [$menuItem]);
28+
}
29+
30+
public function getItems(): array
31+
{
32+
return $this->items;
33+
}
34+
35+
public function setActiveHrefPath(?string $value): void
36+
{
37+
$this->activeHrefPath = $value;
38+
}
39+
40+
public function getActiveHrefPath(): ?string
41+
{
42+
return $this->activeHrefPath;
43+
}
44+
45+
/**
46+
* Item factory method for easy injection in tests.
47+
*/
48+
public function buildItem(string $hrefPath, string $label, ?string $iconAssetPath = null): Item
49+
{
50+
return new Item($hrefPath, $label, $iconAssetPath);
51+
}
52+
}

src/Admin/Menu/Item.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\Module\oidc\Admin\Menu;
6+
7+
class Item
8+
{
9+
public function __construct(
10+
protected string $hrefPath,
11+
protected string $label,
12+
protected ?string $iconAssetPath = null,
13+
) {
14+
}
15+
16+
public function getHrefPath(): string
17+
{
18+
return $this->hrefPath;
19+
}
20+
21+
public function getLabel(): string
22+
{
23+
return $this->label;
24+
}
25+
26+
public function getIconAssetPath(): ?string
27+
{
28+
return $this->iconAssetPath;
29+
}
30+
}

src/Bridges/SspBridge/Utils.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace SimpleSAML\Module\oidc\Bridges\SspBridge;
66

7+
use SimpleSAML\Utils\Auth;
78
use SimpleSAML\Utils\Config;
89
use SimpleSAML\Utils\HTTP;
910
use SimpleSAML\Utils\Random;
@@ -13,6 +14,7 @@ class Utils
1314
protected static ?Config $config = null;
1415
protected static ?HTTP $http = null;
1516
protected static ?Random $random = null;
17+
protected static ?Auth $auth = null;
1618

1719
public function config(): Config
1820
{
@@ -28,4 +30,9 @@ public function random(): Random
2830
{
2931
return self::$random ??= new Random();
3032
}
33+
34+
public function auth(): Auth
35+
{
36+
return self::$auth ??= new Auth();
37+
}
3138
}

src/Codebooks/RoutesEnum.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
enum RoutesEnum: string
88
{
9+
// Admin area
10+
case AdminConfigOverview = 'admin/config-overview';
11+
12+
// Protocols
913
case Authorization = 'authorization';
1014
case Configuration = '.well-known/openid-configuration';
1115
case FederationConfiguration = '.well-known/openid-federation';

src/Controller/AdminController.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\Module\oidc\Controller;
6+
7+
use SimpleSAML\Module\oidc\Admin\Authorization;
8+
use SimpleSAML\Module\oidc\Factories\TemplateFactory;
9+
use SimpleSAML\Module\oidc\ModuleConfig;
10+
use Symfony\Component\HttpFoundation\Response;
11+
12+
class AdminController
13+
{
14+
public function __construct(
15+
protected readonly ModuleConfig $moduleConfig,
16+
protected readonly TemplateFactory $templateFactory,
17+
protected readonly Authorization $authorization,
18+
) {
19+
$this->authorization->requireSspAdmin(true);
20+
}
21+
22+
public function configOverview(): Response
23+
{
24+
return $this->templateFactory->render(
25+
'oidc:config/overview.twig',
26+
[
27+
'moduleConfig' => $this->moduleConfig,
28+
],
29+
);
30+
}
31+
}

0 commit comments

Comments
 (0)