‪TYPO3CMS  ‪main
BackendUserAuthenticator.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Psr\Http\Message\ResponseInterface;
21 use Psr\Http\Message\ServerRequestInterface;
22 use Psr\Http\Server\MiddlewareInterface;
23 use Psr\Http\Server\RequestHandlerInterface;
29 
50 abstract class ‪BackendUserAuthenticator implements MiddlewareInterface
51 {
52  public function ‪__construct(protected ‪Context $context) {}
53 
54  abstract public function ‪process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface;
55 
64  protected function ‪applyHeadersToResponse(ResponseInterface $response): ResponseInterface
65  {
66  $headers = [
67  'Expires' => 0,
68  'Last-Modified' => gmdate('D, d M Y H:i:s') . ' GMT',
69  'Cache-Control' => 'no-cache, no-store',
70  // HTTP 1.0 compatibility, see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Pragma
71  'Pragma' => 'no-cache',
72  ];
73  foreach ($headers as $headerName => $headerValue) {
74  $response = $response->withHeader($headerName, (string)$headerValue);
75  }
76  return $response;
77  }
78 
84  protected function ‪setBackendUserAspect(?‪BackendUserAuthentication $user, int $alternativeWorkspaceId = null): void
85  {
86  $this->context->setAspect(
87  'backend.user',
88  GeneralUtility::makeInstance(UserAspect::class, $user)
89  );
90  $this->context->setAspect(
91  'workspace',
92  GeneralUtility::makeInstance(WorkspaceAspect::class, $alternativeWorkspaceId ?? $user->workspace ?? 0)
93  );
94  }
95 }
‪TYPO3\CMS\Core\Context\WorkspaceAspect
Definition: WorkspaceAspect.php:31
‪TYPO3\CMS\Core\Middleware\BackendUserAuthenticator\process
‪process(ServerRequestInterface $request, RequestHandlerInterface $handler)
‪TYPO3\CMS\Core\Middleware\BackendUserAuthenticator\setBackendUserAspect
‪setBackendUserAspect(?BackendUserAuthentication $user, int $alternativeWorkspaceId=null)
Definition: BackendUserAuthenticator.php:84
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:54
‪TYPO3\CMS\Core\Middleware\BackendUserAuthenticator
Definition: BackendUserAuthenticator.php:51
‪TYPO3\CMS\Core\Middleware\BackendUserAuthenticator\applyHeadersToResponse
‪ResponseInterface applyHeadersToResponse(ResponseInterface $response)
Definition: BackendUserAuthenticator.php:64
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Core\Middleware\BackendUserAuthenticator\__construct
‪__construct(protected Context $context)
Definition: BackendUserAuthenticator.php:52
‪TYPO3\CMS\Core\Middleware
Definition: AbstractContentSecurityPolicyReporter.php:18
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\Context\UserAspect
Definition: UserAspect.php:37