‪TYPO3CMS  10.4
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 
48 abstract class ‪BackendUserAuthenticator implements MiddlewareInterface
49 {
53  protected ‪$context;
54 
55  public function ‪__construct(‪Context ‪$context)
56  {
57  $this->context = ‪$context;
58  }
59 
63  abstract public function ‪process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface;
64 
74  protected function ‪applyHeadersToResponse(ResponseInterface $response): ResponseInterface
75  {
76  $headers = [
77  'Expires' => 0,
78  'Last-Modified' => gmdate('D, d M Y H:i:s') . ' GMT',
79  'Cache-Control' => 'no-cache, must-revalidate',
80  // HTTP 1.0 compatibility, see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Pragma
81  'Pragma' => 'no-cache'
82  ];
83  foreach ($headers as $headerName => $headerValue) {
84  $response = $response->withHeader($headerName, (string)$headerValue);
85  }
86  return $response;
87  }
88 
95  protected function ‪setBackendUserAspect(?BackendUserAuthentication $user, int $alternativeWorkspaceId = null): void
96  {
97  $this->context->setAspect(
98  'backend.user',
99  GeneralUtility::makeInstance(UserAspect::class, $user)
100  );
101  $this->context->setAspect(
102  'workspace',
103  GeneralUtility::makeInstance(WorkspaceAspect::class, $alternativeWorkspaceId ?? $user->workspace ?? 0)
104  );
105  }
106 }
‪TYPO3\CMS\Core\Context\WorkspaceAspect
Definition: WorkspaceAspect.php:31
‪TYPO3\CMS\Core\Middleware\BackendUserAuthenticator\__construct
‪__construct(Context $context)
Definition: BackendUserAuthenticator.php:54
‪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:94
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:53
‪TYPO3\CMS\Core\Middleware\BackendUserAuthenticator\$context
‪Context $context
Definition: BackendUserAuthenticator.php:52
‪TYPO3\CMS\Core\Middleware\BackendUserAuthenticator
Definition: BackendUserAuthenticator.php:49
‪TYPO3\CMS\Core\Middleware\BackendUserAuthenticator\applyHeadersToResponse
‪ResponseInterface applyHeadersToResponse(ResponseInterface $response)
Definition: BackendUserAuthenticator.php:73
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Core\Middleware
Definition: BackendUserAuthenticator.php:18
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Context\UserAspect
Definition: UserAspect.php:38