Skip to content

Commit 8a3aff9

Browse files
committed
LoggedOut Controller
1 parent cc0dbaf commit 8a3aff9

File tree

8 files changed

+121
-51
lines changed

8 files changed

+121
-51
lines changed

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@
4040
"simplesamlphp/simplesamlphp": "^2.2",
4141
"simplesamlphp/xml-cas": "^v1.3",
4242
"simplesamlphp/xml-common": "^v1.17",
43-
"simplesamlphp/xml-soap": "^v1.5",
44-
"symfony/cache": "^6.0|^5.0|^4.3|^3.4"
43+
"simplesamlphp/xml-soap": "^v1.5"
4544
},
4645
"require-dev": {
4746
"simplesamlphp/simplesamlphp-test-framework": "^1.7",

public/loggedOut.php

Lines changed: 0 additions & 36 deletions
This file was deleted.

routing/routes/routes.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66

77
declare(strict_types=1);
88

9-
use SimpleSAML\Module\casserver\Codebooks\RoutesEnum;
109
use SimpleSAML\Module\casserver\Codebooks\LegacyRoutesEnum;
10+
use SimpleSAML\Module\casserver\Codebooks\RoutesEnum;
1111
use SimpleSAML\Module\casserver\Controller\Cas10Controller;
12+
use SimpleSAML\Module\casserver\Controller\LoggedOutController;
1213
use SimpleSAML\Module\casserver\Controller\LogoutController;
1314
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
1415

@@ -19,12 +20,16 @@
1920
// New Routes
2021
$routes->add(RoutesEnum::Validate->name, RoutesEnum::Validate->value)
2122
->controller([Cas10Controller::class, 'validate']);
22-
$routes->add(RoutesEnum::Validate->name, RoutesEnum::Logout->value)
23+
$routes->add(RoutesEnum::Logout->name, RoutesEnum::Logout->value)
2324
->controller([LogoutController::class, 'logout']);
25+
$routes->add(RoutesEnum::LoggedOut->name, RoutesEnum::LoggedOut->value)
26+
->controller([LoggedOutController::class, 'main']);
2427

2528
// Legacy Routes
2629
$routes->add(LegacyRoutesEnum::LegacyValidate->name, LegacyRoutesEnum::LegacyValidate->value)
2730
->controller([Cas10Controller::class, 'validate']);
28-
$routes->add(LegacyRoutesEnum::LegacyValidate->name, LegacyRoutesEnum::LegacyLogout->value)
31+
$routes->add(LegacyRoutesEnum::LegacyLogout->name, LegacyRoutesEnum::LegacyLogout->value)
2932
->controller([LogoutController::class, 'logout']);
33+
$routes->add(LegacyRoutesEnum::LegacyLoggedOut->name, LegacyRoutesEnum::LegacyLoggedOut->value)
34+
->controller([LoggedOutController::class, 'main']);
3035
};

routing/services/services.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,14 @@ services:
1212
exclude:
1313
- '../../src/Controller/Traits/*'
1414
public: true
15-
autowire: true
15+
tags: ['controller.service_arguments']
16+
17+
# Explicit service definitions for CasServer Controllers
18+
SimpleSAML\Module\casserver\Controller\Cas10Controller:
19+
public: true
20+
21+
SimpleSAML\Module\casserver\Controller\LogoutController:
22+
public: true
23+
24+
SimpleSAML\Module\casserver\Controller\LoggedOutController:
25+
public: true

src/Controller/Cas10Controller.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,9 @@
1111
use SimpleSAML\Module\casserver\Controller\Traits\UrlTrait;
1212
use Symfony\Component\HttpFoundation\Request;
1313
use Symfony\Component\HttpFoundation\Response;
14+
use Symfony\Component\HttpKernel\Attribute\AsController;
1415

15-
/**
16-
* Controller class for the casserver module.
17-
*
18-
* This class serves the different views available in the module.
19-
*
20-
* @package SimpleSAML\Module\casserver
21-
*/
16+
#[AsController]
2217
class Cas10Controller
2318
{
2419
use UrlTrait;
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\Module\casserver\Controller;
6+
7+
use SimpleSAML\Configuration;
8+
use SimpleSAML\XHTML\Template;
9+
use Symfony\Component\HttpFoundation\Request;
10+
use Symfony\Component\HttpFoundation\Response;
11+
use Symfony\Component\HttpKernel\Attribute\AsController;
12+
13+
#[AsController]
14+
class LoggedOutController
15+
{
16+
/** @var \SimpleSAML\Configuration */
17+
protected Configuration $config;
18+
19+
/**
20+
* Controller constructor.
21+
*
22+
* It initializes the global configuration for the controllers implemented here.
23+
*
24+
* @param Configuration|null $config
25+
*
26+
* @throws \Exception
27+
*/
28+
public function __construct(Configuration $config = null)
29+
{
30+
$this->config = $config ?? Configuration::getInstance();
31+
}
32+
33+
/**
34+
* Show Log out view.
35+
*
36+
* @param Request $request
37+
* @return Response
38+
* @throws \Exception
39+
*/
40+
public function main(Request $request): Response
41+
{
42+
$t = new Template($this->config, 'casserver:loggedOut.twig');
43+
if ($request->query->has('url')) {
44+
$t->data['url'] = $request->query->get('url');
45+
}
46+
return $t;
47+
}
48+
}

src/Controller/LogoutController.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@
77
use SimpleSAML\Auth\Simple;
88
use SimpleSAML\Configuration;
99
use SimpleSAML\Logger;
10+
use SimpleSAML\Module;
1011
use SimpleSAML\Module\casserver\Cas\Factories\TicketFactory;
1112
use SimpleSAML\Module\casserver\Controller\Traits\UrlTrait;
1213
use SimpleSAML\Session;
1314
use Symfony\Component\HttpFoundation\RedirectResponse;
15+
use Symfony\Component\HttpFoundation\Request;
16+
use Symfony\Component\HttpKernel\Attribute\AsController;
1417
use Symfony\Component\HttpKernel\Attribute\MapQueryParameter;
1518

19+
#[AsController]
1620
class LogoutController
1721
{
1822
use UrlTrait;
@@ -57,11 +61,13 @@ public function __construct()
5761

5862
/**
5963
*
64+
* @param Request $request
6065
* @param string|null $url
6166
*
6267
* @return RedirectResponse|null
6368
*/
6469
public function logout(
70+
Request $request,
6571
#[MapQueryParameter] ?string $url = null,
6672
): RedirectResponse|null {
6773
if (!$this->casConfig->getOptionalValue('enable_logout', false)) {
@@ -76,8 +82,13 @@ public function logout(
7682
}
7783

7884
// Construct the logout redirect url
79-
$logoutRedirectUrl = ($skipLogoutPage || $url === null) ? $url
80-
: $url . '?' . http_build_query(['url' => $url]);
85+
if ($skipLogoutPage) {
86+
$logoutRedirectUrl = $url;
87+
} else {
88+
$loggedOutUrl = Module::getModuleURL('casserver/loggedOut.php');
89+
$logoutRedirectUrl = $url === null ? $loggedOutUrl
90+
: $loggedOutUrl . '?' . http_build_query(['url' => $url]);
91+
}
8192

8293
// Delete the ticket from the session
8394
$session = $this->getSession();
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\Module\casserver\Tests\Controller;
6+
7+
use PHPUnit\Framework\Attributes\DataProvider;
8+
use PHPUnit\Framework\TestCase;
9+
use SimpleSAML\Module\casserver\Controller\LogoutController;
10+
use Symfony\Component\HttpFoundation\Request;
11+
12+
class LogoutControllerTest extends TestCase
13+
{
14+
/** @var LogoutController */
15+
private $controller;
16+
17+
protected function setUp(): void
18+
{
19+
$this->controller = new LogoutController();
20+
}
21+
22+
public static function requestParameters(): array
23+
{
24+
return [
25+
'no redirect url' => [''],
26+
'with redirect url' => ['http://example.com/redirect'],
27+
];
28+
}
29+
30+
#[DataProvider('requestParameters')]
31+
public function testLogout(string $redirectUrl): void
32+
{
33+
$request = Request::create(
34+
uri: 'https://localhost/casserver/logout',
35+
parameters: ['url' => $redirectUrl],
36+
);
37+
}
38+
}

0 commit comments

Comments
 (0)