diff --git a/routing/routes/routes.yml b/routing/routes/routes.yml index dcd41bc49956a6cac60dee067200cdddf49aab1e..516aec8520b9af1a987848882fb5b0cecc2aefb4 100644 --- a/routing/routes/routes.yml +++ b/routing/routes/routes.yml @@ -22,7 +22,11 @@ accounting-user-oidc-token-revoke-xhr: accounting-user-logout: path: /user/logout - controller: SimpleSAML\Module\accounting\Http\Controllers\User\Profile::logout + controller: SimpleSAML\Module\accounting\Http\Controllers\Logout::logout methods: - GET - POST + +accounting-logout: + path: /logged-out + controller: SimpleSAML\Module\accounting\Http\Controllers\Logout::loggedOut \ No newline at end of file diff --git a/src/Helpers/Routes.php b/src/Helpers/Routes.php index 70bec363a3194f6b492368b26ca072173fb9b124..fdd6632927097e1dd0e099b2cdb6ddb41f996341 100644 --- a/src/Helpers/Routes.php +++ b/src/Helpers/Routes.php @@ -16,6 +16,7 @@ class Routes public const PATH_USER_PERSONAL_DATA = 'user/personal-data'; public const PATH_USER_OIDC_TOKENS = 'user/oidc-tokens'; public const QUERY_REDIRECT_TO_PATH = 'redirectTo'; + public const PATH_LOGGED_OUT = 'logged-out'; protected HTTP $sspHttpUtils; protected Arr $arr; diff --git a/src/Http/Controllers/Logout.php b/src/Http/Controllers/Logout.php new file mode 100644 index 0000000000000000000000000000000000000000..539a83914a2eae716a52b869b43e2ab42ad8a29b --- /dev/null +++ b/src/Http/Controllers/Logout.php @@ -0,0 +1,93 @@ +<?php + +declare(strict_types=1); + +namespace SimpleSAML\Module\accounting\Http\Controllers; + +use Psr\Log\LoggerInterface; +use SimpleSAML\Auth\Simple; +use SimpleSAML\Configuration as SspConfiguration; +use SimpleSAML\Error\ConfigurationError; +use SimpleSAML\Error\CriticalConfigurationError; +use SimpleSAML\HTTP\RunnableResponse; +use SimpleSAML\Locale\Translate; +use SimpleSAML\Metadata\MetaDataStorageHandler; +use SimpleSAML\Module\accounting\Data\Providers\Builders\DataProviderBuilder; +use SimpleSAML\Module\accounting\Data\Providers\Interfaces\ActivityInterface; +use SimpleSAML\Module\accounting\Data\Providers\Interfaces\DataProviderInterface; +use SimpleSAML\Module\accounting\Entities\Authentication\Protocol\Oidc; +use SimpleSAML\Module\accounting\Entities\ConnectedService; +use SimpleSAML\Module\accounting\Entities\User; +use SimpleSAML\Module\accounting\Exceptions\Exception; +use SimpleSAML\Module\accounting\Exceptions\InvalidConfigurationException; +use SimpleSAML\Module\accounting\Helpers\Attributes; +use SimpleSAML\Module\accounting\Helpers\ProviderResolver; +use SimpleSAML\Module\accounting\Helpers\Routes; +use SimpleSAML\Module\accounting\ModuleConfiguration; +use SimpleSAML\Module\accounting\ModuleConfiguration\ConnectionType; +use SimpleSAML\Module\accounting\Services\AlertsBag; +use SimpleSAML\Module\accounting\Services\CsrfToken; +use SimpleSAML\Module\accounting\Services\HelpersManager; +use SimpleSAML\Module\accounting\Services\MenuManager; +use SimpleSAML\Module\accounting\Services\SspModuleManager; +use SimpleSAML\Module\oidc\Services\OidcOpenIdProviderMetadataService; +use SimpleSAML\Session; +use SimpleSAML\Utils\Config\Metadata; +use SimpleSAML\XHTML\Template; +use Symfony\Component\HttpFoundation\Cookie; +use Symfony\Component\HttpFoundation\JsonResponse; +use Symfony\Component\HttpFoundation\RedirectResponse; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; + +/** + * @psalm-suppress UnusedClass Used as route controller. + */ +class Logout +{ + protected ModuleConfiguration $moduleConfiguration; + protected Session $session; + protected LoggerInterface $logger; + protected string $defaultAuthenticationSource; + protected Simple $authSimple; + protected HelpersManager $helpersManager; + protected User $user; + protected SspConfiguration $sspConfiguration; + + /** + * @param ModuleConfiguration $moduleConfiguration + * @param SspConfiguration $sspConfiguration + * @param Session $session The current user session. + * @param LoggerInterface $logger + * @param Simple|null $authSimple + * @param HelpersManager|null $helpersManager + */ + public function __construct( + ModuleConfiguration $moduleConfiguration, + SspConfiguration $sspConfiguration, + Session $session, + Simple $authSimple = null, + HelpersManager $helpersManager = null + ) { + $this->defaultAuthenticationSource = $moduleConfiguration->getDefaultAuthenticationSource(); + $this->sspConfiguration = $sspConfiguration; + $this->authSimple = $authSimple ?? new Simple($this->defaultAuthenticationSource, $sspConfiguration, $session); + + $this->helpersManager = $helpersManager ?? new HelpersManager(); + } + + public function logout(): Response + { + return new RunnableResponse([$this->authSimple, 'logout'], [$this->getLoggedOutUrl()]); + } + + public function loggedOut(): Response + { + return new Template($this->sspConfiguration, 'accounting:logged-out.twig'); + } + + protected function getLoggedOutUrl(): string + { + return $this->helpersManager->getRoutes()->getUrl(Routes::PATH_LOGGED_OUT); + } +} diff --git a/src/Http/Controllers/User/Profile.php b/src/Http/Controllers/User/Profile.php index 09dd023332d1f9c6fba630d2cab536886382e82c..c4b029ec9001838695b03699af090080f35e6648 100644 --- a/src/Http/Controllers/User/Profile.php +++ b/src/Http/Controllers/User/Profile.php @@ -288,21 +288,6 @@ class Profile return $userIdentifier; } - public function logout(): Response - { - return new RunnableResponse([$this->authSimple, 'logout'], [$this->getLogoutUrl()]); - } - - protected function getLogoutUrl(): string - { - try { - return $this->sspConfiguration->getBasePath() . 'logout.php'; - } catch (CriticalConfigurationError $exception) { - $message = \sprintf('Could not resolve SimpleSAMLphp base path. Error was: %s', $exception->getMessage()); - throw new InvalidConfigurationException($message, $exception->getCode(), $exception); - } - } - /** * Load all attribute map files which translate attribute names to user-friendly name format. */ diff --git a/templates/logged-out.twig b/templates/logged-out.twig new file mode 100644 index 0000000000000000000000000000000000000000..5674c87849f01d96e3d37dab54bfdc67cfeaf992 --- /dev/null +++ b/templates/logged-out.twig @@ -0,0 +1,23 @@ +<!DOCTYPE html> +<html lang="{{ currentLanguage }}"> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> +{# <meta name="viewport" content="initial-scale=1.0">#} +{# <meta http-equiv="X-UA-Compatible" content="IE=Edge">#} + <title>{{ pagetitle }}</title> + <link rel="stylesheet" href="{{ asset('css/src/default.css', 'accounting') }}"> + <link rel="icon" href="{{ asset("icons/favicon.ico") }}"> + <meta name="robots" content="noindex, nofollow"> +</head> +<body id="{{ templateId }}"> + +{% include '@accounting/includes/_header.twig' %} + +<section id="main"> + <h1>{{ 'Logout successful'|trans }}</h1> + + <p><a href="./user/personal-data">{{ 'Go back to Profile Page'|trans }}</a></p> +</section> + +</body> +</html> \ No newline at end of file