aboutsummaryrefslogtreecommitdiff
path: root/lib/middleware/AuthenticationMiddleware.php
diff options
context:
space:
mode:
authorAndré Noack <noack@data-quest.de>2024-12-12 14:52:00 +0000
committerDavid Siegfried <david.siegfried@uni-vechta.de>2024-12-12 14:52:00 +0000
commit940d2aaa8638b4e0c764579cb3977e7be527c81f (patch)
tree79bd2d7f02359e1bb24931b33513e082f8404a91 /lib/middleware/AuthenticationMiddleware.php
parent3a2a88172ccbe97aaecf4ea32b97cd07b92dcb11 (diff)
StEP 1552 closes #1552
Closes #1552 Merge request studip/studip!1137
Diffstat (limited to 'lib/middleware/AuthenticationMiddleware.php')
-rw-r--r--lib/middleware/AuthenticationMiddleware.php40
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/middleware/AuthenticationMiddleware.php b/lib/middleware/AuthenticationMiddleware.php
new file mode 100644
index 0000000..739ce89
--- /dev/null
+++ b/lib/middleware/AuthenticationMiddleware.php
@@ -0,0 +1,40 @@
+<?php
+/**
+ * PSR 15 middleware Stud.IP Authentication
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * @author André Noack <noack@data-quest.de>
+ * @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
+ * @category Stud.IP
+ * @since 6.0
+ */
+namespace Studip\Middleware;
+
+use Psr\Http\Message\ResponseFactoryInterface;
+use Psr\Http\Message\ResponseInterface;
+use Psr\Http\Message\ServerRequestInterface;
+use Psr\Http\Server\MiddlewareInterface;
+use Psr\Http\Server\RequestHandlerInterface;
+use Studip\Authentication\Manager;
+
+final class AuthenticationMiddleware implements MiddlewareInterface
+{
+ public function __construct(private Manager $auth_manager, private ResponseFactoryInterface $response_factory)
+ {
+ }
+
+ public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
+ {
+ if ($this->auth_manager->start()) {
+ return $handler->handle($request);
+ } else {
+ $_SESSION['redirect_after_login'] = \Request::url();
+ $response = $this->response_factory->createResponse(302);
+ return $response->withHeader('Location', \URLHelper::getURL('dispatch.php/login'));
+ }
+ }
+}