Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP move to SSP UI #267

Draft
wants to merge 6 commits into
base: wip-version-6
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions hooks/hook_adminmenu.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

use SimpleSAML\Locale\Translate;
use SimpleSAML\Module\oidc\Codebooks\RoutesEnum;
use SimpleSAML\Module\oidc\ModuleConfig;
use SimpleSAML\XHTML\Template;

/** @noinspection PhpParameterByRefIsNotUsedAsReferenceInspection Reference is actually used by SimpleSAMLphp */
function oidc_hook_adminmenu(Template &$template): void
{
$menuKey = 'menu';

if (!isset($template->data[$menuKey]) || !is_array($template->data[$menuKey])) {
return;
}

$moduleConfig = new ModuleConfig();

$oidcMenuEntry = [
ModuleConfig::MODULE_NAME => [
'url' => $moduleConfig->getModuleUrl(RoutesEnum::AdminConfigOverview->value),
'name' => Translate::noop('OIDC'),
],
];

// Put OIDC entry before the 'Log out' entry, if it exists.
$logoutEntryKey = 'logout';
$logoutEntryValue = null;
if (
array_key_exists($logoutEntryKey, $template->data[$menuKey]) &&
is_array($template->data[$menuKey][$logoutEntryKey])
) {
$logoutEntryValue = $template->data[$menuKey][$logoutEntryKey];
unset($template->data[$menuKey][$logoutEntryKey]);
}

$template->data[$menuKey] += $oidcMenuEntry;

if ($logoutEntryValue !== null) {
$template->data[$menuKey][$logoutEntryKey] = $logoutEntryValue;
}

$template->getLocalization()->addModuleDomain(ModuleConfig::MODULE_NAME);
}
61 changes: 0 additions & 61 deletions hooks/hook_frontpage.php

This file was deleted.

71 changes: 71 additions & 0 deletions public/assets/css/src/default.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
.wrap {
/*max-width: 1300px;*/
}

/*h2 {*/
/* margin: 0.3em;*/
/*}*/

h3 {
margin-bottom: 0.5em;
font-size: 1.2em;
font-weight: 600;
color: #1c1c1c;
}

h4 {
margin: 0.4em 0;
font-size: 1.0em;
font-weight: 600;
color: #1c1c1c;
}

/* Container to hold menu and content */
.oidc-container {
display: flex;
max-width: inherit;
margin: 0 auto;
}

/* Style for the left menu */
.menu {
min-width: 200px;
/*background-color: #f4f4f4;*/
/*border-right: solid 1px #bbb;*/
width: auto;
}

/* Style for the menu items */
.menu ul {
list-style-type: none;
padding: 0;
}

.menu ul li {
padding: 0.25rem;
}

.menu ul li a {
text-decoration: none;
color: #333;
display: block;
padding: 0.5rem;
}

.menu ul li a:hover {
background-color: #ddd;
padding: 0.5rem;
}

.menu ul li a.active {
background-color: #eeeeee;
padding: 0.5rem;
}

/* Style for the content area */
.content {
flex-grow: 1;
padding: 20px;
max-width: inherit;
background-color: #fff;
}
10 changes: 10 additions & 0 deletions routing/routes/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

use SimpleSAML\Module\oidc\Codebooks\RoutesEnum;
use SimpleSAML\Module\oidc\Controller\AccessTokenController;
use SimpleSAML\Module\oidc\Controller\AdminController;
use SimpleSAML\Module\oidc\Controller\AuthorizationController;
use SimpleSAML\Module\oidc\Controller\ConfigurationDiscoveryController;
use SimpleSAML\Module\oidc\Controller\EndSessionController;
Expand All @@ -19,6 +20,15 @@

/** @psalm-suppress InvalidArgument */
return function (RoutingConfigurator $routes): void {
/**
* Admin area routes.
*/
$routes->add(RoutesEnum::AdminConfigOverview->name, RoutesEnum::AdminConfigOverview->value)
->controller([AdminController::class, 'configOverview']);

/**
* OpenID Connect Discovery routes.
*/
$routes->add(RoutesEnum::Configuration->name, RoutesEnum::Configuration->value)
->controller(ConfigurationDiscoveryController::class);

Expand Down
3 changes: 3 additions & 0 deletions routing/services/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ services:
SimpleSAML\Module\oidc\Factories\:
resource: '../../src/Factories/*'

SimpleSAML\Module\oidc\Admin\:
resource: '../../src/Admin/*'

SimpleSAML\Module\oidc\Stores\:
resource: '../../src/Stores/*'

Expand Down
40 changes: 40 additions & 0 deletions src/Admin/Authorization.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\Module\oidc\Admin;

use SimpleSAML\Error\Exception;
use SimpleSAML\Locale\Translate;
use SimpleSAML\Module\oidc\Bridges\SspBridge;
use SimpleSAML\Module\oidc\Exceptions\AuthorizationException;

class Authorization
{
public function __construct(
protected readonly SspBridge $sspBridge,
) {
}

/**
* @throws \SimpleSAML\Module\oidc\Exceptions\AuthorizationException
*/
public function requireSspAdmin(bool $forceAdminAuthentication = false): void
{
if ($forceAdminAuthentication) {
try {
$this->sspBridge->utils()->auth()->requireAdmin();
} catch (Exception $exception) {
throw new AuthorizationException(
Translate::noop('Unable to initiate SimpleSAMLphp admin authentication.'),
$exception->getCode(),
$exception,
);
}
}

if (! $this->sspBridge->utils()->auth()->isAdmin()) {
throw new AuthorizationException(Translate::noop('SimpleSAMLphp admin access required.'));
}
}
}
52 changes: 52 additions & 0 deletions src/Admin/Menu.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\Module\oidc\Admin;

use SimpleSAML\Module\oidc\Admin\Menu\Item;

class Menu
{
/**
* @var array<Item>
*/
protected array $items = [];

protected ?string $activeHrefPath = null;

public function __construct(Item ...$items)
{
array_push($this->items, ...$items);
}

public function addItem(Item $menuItem, int $offset = null): void
{
$offset ??= count($this->items);

array_splice($this->items, $offset, 0, [$menuItem]);
}

public function getItems(): array
{
return $this->items;
}

public function setActiveHrefPath(?string $value): void
{
$this->activeHrefPath = $value;
}

public function getActiveHrefPath(): ?string
{
return $this->activeHrefPath;
}

/**
* Item factory method for easy injection in tests.
*/
public function buildItem(string $hrefPath, string $label, ?string $iconAssetPath = null): Item
{
return new Item($hrefPath, $label, $iconAssetPath);
}
}
30 changes: 30 additions & 0 deletions src/Admin/Menu/Item.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\Module\oidc\Admin\Menu;

class Item
{
public function __construct(
protected string $hrefPath,
protected string $label,
protected ?string $iconAssetPath = null,
) {
}

public function getHrefPath(): string
{
return $this->hrefPath;
}

public function getLabel(): string
{
return $this->label;
}

public function getIconAssetPath(): ?string
{
return $this->iconAssetPath;
}
}
16 changes: 16 additions & 0 deletions src/Bridges/SspBridge/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,27 @@
namespace SimpleSAML\Module\oidc\Bridges\SspBridge;

use SimpleSAML\Module as SspModule;
use SimpleSAML\Module\oidc\Bridges\SspBridge\Module\Admin;

class Module
{
protected static ?SspModule\oidc\Bridges\SspBridge\Module\Admin $admin = null;

public function admin(): Admin
{
return self::$admin ??= new Admin();
}

public function getModuleUrl(string $resource, array $parameters = []): string
{
return SspModule::getModuleURL($resource, $parameters);
}

/**
* @throws \Exception
*/
public function isModuleEnabled(string $moduleName): bool
{
return SspModule::isModuleEnabled($moduleName);
}
}
15 changes: 15 additions & 0 deletions src/Bridges/SspBridge/Module/Admin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

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

use SimpleSAML\Module\admin\Controller\Menu;

class Admin
{
public function buildSspAdminMenu(): Menu
{
return new Menu();
}
}
Loading