-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathAuthenticationService.php
700 lines (618 loc) · 26.1 KB
/
AuthenticationService.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
<?php
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace Causal\Oidc\Service;
use League\OAuth2\Client\Token\AccessToken;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\Restriction\EndTimeRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\StartTimeRestriction;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\HttpUtility;
use Causal\Oidc\Service\OAuthService;
use TYPO3\CMS\Core\Utility\RootlineUtility;
use TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication;
/**
* OpenID Connect authentication service.
*/
class AuthenticationService extends \TYPO3\CMS\Sv\AuthenticationService
{
/**
* true - this service was able to authenticate the user
*/
const STATUS_AUTHENTICATION_SUCCESS_CONTINUE = true;
/**
* 200 - authenticated and no more checking needed
*/
const STATUS_AUTHENTICATION_SUCCESS_BREAK = 200;
/**
* false - this service was the right one to authenticate the user but it failed
*/
const STATUS_AUTHENTICATION_FAILURE_BREAK = false;
/**
* 100 - just go on. User is not authenticated but there's still no reason to stop
*/
const STATUS_AUTHENTICATION_FAILURE_CONTINUE = 100;
/**
* Global extension configuration
*
* @var array
*/
protected $config;
/**
* AuthenticationService constructor.
*/
public function __construct()
{
$typo3Branch = class_exists(\TYPO3\CMS\Core\Information\Typo3Version::class)
? (new \TYPO3\CMS\Core\Information\Typo3Version())->getBranch()
: TYPO3_branch;
if (version_compare($typo3Branch, '9.0', '<')) {
$this->config = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['oidc']);
} else {
$this->config = $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['oidc'] ?? [];
}
}
/**
* Finds a user.
*
* @return array|bool
* @throws \RuntimeException
*/
public function getUser()
{
$user = false;
$params = GeneralUtility::_GET('tx_oidc');
$code = isset($params['code']) ? $params['code'] : null;
$username = isset($this->login['uname']) ? $this->login['uname'] : null;
if (isset($this->login['uident_text'])) {
$password = $this->login['uident_text'];
} elseif (isset($this->login['uident'])) {
$password = $this->login['uident'];
} else {
$password = null;
}
if ($code !== null) {
$user = $this->authenticateWithAuhorizationCode($code);
} elseif (!(empty($username) || empty($password))) {
$user = $this->authenticateWithResourceOwnerPasswordCredentials($username, $password);
}
return $user;
}
/**
* Authenticates a user using authorization code grant.
*
* @param string $code
* @return array|bool
*/
protected function authenticateWithAuhorizationCode($code)
{
static::getLogger()->debug('Initializing OpenID Connect service');
/** @var OAuthService $service */
$service = GeneralUtility::makeInstance(OAuthService::class);
$service->setSettings($this->config);
// Try to get an access token using the authorization code grant
try {
static::getLogger()->debug('Retrieving an access token');
$accessToken = $service->getAccessToken($code);
static::getLogger()->debug('Access token retrieved', $accessToken->jsonSerialize());
} catch (\League\OAuth2\Client\Provider\Exception\IdentityProviderException $e) {
// Probably a "server_error", meaning the code is not valid anymore
static::getLogger()->error('Possibly replay: code has been refused by the authentication server', [
'code' => $code,
'message' => $e->getMessage(),
]);
return false;
}
$user = $this->getUserFromAccessToken($service, $accessToken);
return $user;
}
/**
* Authenticates a user using resource owner password credentials grant.
*
* @param string $username
* @param string $password
* @return array|bool
*/
protected function authenticateWithResourceOwnerPasswordCredentials($username, $password)
{
$user = false;
static::getLogger()->debug('Initializing OpenID Connect service');
/** @var OAuthService $service */
$service = GeneralUtility::makeInstance(OAuthService::class);
$service->setSettings($this->config);
try {
if ((bool)$this->config['oidcUseRequestPathAuthentication']) {
static::getLogger()->debug('Retrieving an access token using request path authentication');
$accessToken = $service->getAccessTokenWithRequestPathAuthentication($username, $password);
} else {
static::getLogger()->debug('Retrieving an access token using resource owner password credentials');
$accessToken = $service->getAccessToken($username, $password);
}
if ($accessToken !== null) {
static::getLogger()->debug('Access token retrieved', $accessToken->jsonSerialize());
$user = $this->getUserFromAccessToken($service, $accessToken);
}
} catch (\League\OAuth2\Client\Provider\Exception\IdentityProviderException $e) {
static::getLogger()->error('Authentication has been refused by the authentication server', [
'username' => $username,
'message' => $e->getMessage(),
]);
}
return $user;
}
/**
* Looks up a TYPO3 user from an access token.
*
* @param OAuthService $service
* @param AccessToken $accessToken
* @return array|bool
*/
protected function getUserFromAccessToken(OAuthService $service, AccessToken $accessToken)
{
// Using the access token, we may look up details about the resource owner
try {
static::getLogger()->debug('Retrieving resource owner');
$resourceOwner = $service->getResourceOwner($accessToken)->toArray();
static::getLogger()->debug('Resource owner retrieved', $resourceOwner);
} catch (\League\OAuth2\Client\Provider\Exception\IdentityProviderException $e) {
static::getLogger()->error('Could not retrieve resource owner', [
'message' => $e->getMessage(),
]);
return false;
}
if (empty($resourceOwner['sub'])) {
static::getLogger()->error('No "sub" found in resource owner, revoking access token');
$service->revokeToken($accessToken);
throw new \RuntimeException(
'Resource owner does not have a sub part: ' . json_encode($resourceOwner)
. '. Your access token has been revoked. Please try again.',
1490086626
);
}
$user = $this->convertResourceOwner($resourceOwner);
if ($this->config['oidcRevokeAccessTokenAfterLogin']) {
$service->revokeToken($accessToken);
}
return $user;
}
/**
* Authenticates a user
*
* @param array $user
* @return int
*/
public function authUser(array $user): int
{
$status = static::STATUS_AUTHENTICATION_FAILURE_CONTINUE;
if (!empty($user['tx_oidc'])) {
$status = static::STATUS_AUTHENTICATION_SUCCESS_BREAK;
}
return $status;
}
/**
* Converts a resource owner into a TYPO3 Frontend user.
*
* @param array $info
* @return array|bool
* @throws \InvalidArgumentException
*/
protected function convertResourceOwner(array $info)
{
if (TYPO3_MODE === 'FE') {
$userTable = 'fe_users';
$userGroupTable = 'fe_groups';
} else {
$userTable = 'be_users';
$userGroupTable = 'be_groups';
}
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable($userTable);
$queryBuilder->getRestrictions()->removeAll();
$row = $queryBuilder
->select('*')
->from($userTable)
->where(
$queryBuilder->expr()->eq('tx_oidc', $queryBuilder->createNamedParameter($info['sub'], \PDO::PARAM_STR))
)
->execute()
->fetch();
$reEnableUser = (bool)$this->config['reEnableFrontendUsers'];
$undeleteUser = (bool)$this->config['undeleteFrontendUsers'];
$frontendUserMustExistLocally = (bool)$this->config['frontendUserMustExistLocally'];
if (!empty($row) && (bool)$row['deleted'] && !$undeleteUser) {
// User was manually deleted, it should not get automatically restored
static::getLogger()->info('User was manually deleted, denying access', ['user' => $row]);
return false;
}
if (!empty($row) && (bool)$row['disable'] && !$reEnableUser) {
// User was manually disabled, it should not get automatically re-enabled
static::getLogger()->info('User was manually disabled, denying access', ['user' => $row]);
return false;
}
if (empty($row) && $frontendUserMustExistLocally) {
// User does not exist locally, it should not be created on-the-fly
static::getLogger()->info('User does not exist locally, denying access', ['info' => $info]);
return false;
}
/** @var $objInstanceSaltedPW \TYPO3\CMS\Saltedpasswords\Salt\SaltInterface */
$typo3Branch = class_exists(\TYPO3\CMS\Core\Information\Typo3Version::class)
? (new \TYPO3\CMS\Core\Information\Typo3Version())->getBranch()
: TYPO3_branch;
if (version_compare($typo3Branch, '9.0', '>=')) {
$objInstanceSaltedPW = \TYPO3\CMS\Saltedpasswords\Salt\SaltFactory::getDefaultHashInstance(TYPO3_MODE);
} else {
$objInstanceSaltedPW = \TYPO3\CMS\Saltedpasswords\Salt\SaltFactory::getSaltingInstance(null, TYPO3_MODE);
}
$password = substr(str_shuffle('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$'), 0, 20);
$hashedPassword = $objInstanceSaltedPW->getHashedPassword($password);
$data = $this->applyMapping(
$userTable,
$info,
$row ?: [],
[
'password' => $hashedPassword,
'deleted' => 0,
'disable' => 0,
]
);
$newUserGroups = [];
$defaultUserGroups = GeneralUtility::intExplode(',', $this->config['usersDefaultGroup'], true);
if (!empty($row)) {
$currentUserGroups = GeneralUtility::intExplode(',', $row['usergroup'], true);
if (!empty($currentUserGroups)) {
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable($userGroupTable);
$queryBuilder->getRestrictions()
->removeByType(HiddenRestriction::class)
->removeByType(StartTimeRestriction::class)
->removeByType(EndTimeRestriction::class);
$groups = $queryBuilder
->select('uid')
->from($userGroupTable)
->where(
$queryBuilder->expr()->in('uid', $currentUserGroups),
$queryBuilder->expr()->neq('tx_oidc_pattern', $queryBuilder->quote(''))
)
->execute()
->fetchAll();
$oidcUserGroups = [];
foreach ($groups as $group) {
$oidcUserGroups[] = $group['uid'];
}
// Remove OIDC-related groups
$newUserGroups = array_diff($currentUserGroups, $oidcUserGroups);
}
}
// Map OIDC roles to TYPO3 user groups
if (!empty($info['Roles'])) {
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable($userGroupTable);
$typo3Roles = $queryBuilder
->select('uid', 'tx_oidc_pattern')
->from($userGroupTable)
->where(
$queryBuilder->expr()->neq('tx_oidc_pattern', $queryBuilder->quote(''))
)
->execute()
->fetchAll();
$roles = GeneralUtility::trimExplode(',', $info['Roles'], true);
$roles = ',' . implode(',', $roles) . ',';
foreach ($typo3Roles as $typo3Role) {
// Convert the pattern into a proper regular expression
$subpatterns = GeneralUtility::trimExplode('|', $typo3Role['tx_oidc_pattern'], true);
foreach ($subpatterns as $k => $subpattern) {
$pattern = preg_quote($subpattern, '/');
$pattern = str_replace('\\*', '[^,]*', $pattern);
$subpatterns[$k] = $pattern;
}
$pattern = '/,(' . implode('|', $subpatterns) . '),/i';
if (preg_match($pattern, $roles)) {
$newUserGroups[] = (int)$typo3Role['uid'];
}
}
}
// Add default user groups
$newUserGroups = array_unique(array_merge($newUserGroups, $defaultUserGroups));
$tableConnection = GeneralUtility::makeInstance(ConnectionPool::class)
->getConnectionForTable($userTable);
if (!empty($row)) { // fe_users record already exists => update it
static::getLogger()->info('Detected a returning user');
$data['usergroup'] = implode(',', $newUserGroups);
$user = array_merge($row, $data);
if ($user != $row) {
static::getLogger()->debug('Updating existing user', [
'old' => $row,
'new' => $user,
]);
$user['tstamp'] = $GLOBALS['EXEC_TIME'];
$tableConnection->update(
$userTable,
$user,
[
'uid' => $user['uid'],
]
);
}
} else { // fe_users record does not already exist => create it
if (empty($newUserGroups)) {
// Somehow the user is not mapped to any local user group, we should not create the record
static::getLogger()->info('User has no associated local TYPO3 user group, denying access', ['user' => $row]);
return false;
}
static::getLogger()->info('New user detected, creating a TYPO3 user');
$data = array_merge($data, [
'pid' => $this->config['usersStoragePid'],
'usergroup' => implode(',', $newUserGroups),
'crdate' => $GLOBALS['EXEC_TIME'],
'tx_oidc' => $info['sub'],
]);
$tableConnection->insert(
$userTable,
$data
);
$userUid = $tableConnection->lastInsertId();
// Retrieve the created user from database to get all columns
$user = $tableConnection
->select(
['*'],
$userTable,
[
'uid' => $userUid,
]
)
->fetch();
}
static::getLogger()->debug('Authentication user record processed', $user);
// Hook for post-processing the user record
$reloadUserRecord = false;
if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['oidc']['resourceOwner'])) {
foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['oidc']['resourceOwner'] as $className) {
/** @var \Causal\Oidc\Service\ResourceOwnerHookInterface $postProcessor */
$postProcessor = GeneralUtility::getUserObj($className);
if ($postProcessor instanceof \Causal\Oidc\Service\ResourceOwnerHookInterface) {
$postProcessor->postProcessUser(TYPO3_MODE, $user, $info);
$reloadUserRecord = true;
} else {
throw new \InvalidArgumentException(
sprintf(
'Invalid post-processing class %s. It must implement the \\Causal\\Oidc\\Service\\ResourceOwnerHookInterface interface',
$className
),
1491229263
);
}
}
}
if ($reloadUserRecord) {
$user = $tableConnection
->select(
['*'],
$userTable,
[
'uid' => (int)$user['uid'],
]
)
->fetch();
static::getLogger()->debug('User record reloaded', $user);
}
// We need that for the upcoming call to authUser()
$user['tx_oidc'] = true;
return $user;
}
/**
* Merges info from OIDC to TYPO3 using a mapping configuration.
*
* @param string $table
* @param array $oidc
* @param array $typo3
* @param array $baseData
* @param bool $reportErrors
* @return array
* @see \Causal\IgLdapSsoAuth\Library\Authentication::merge()
*/
protected function applyMapping($table, array $oidc, array $typo3, array $baseData = [], $reportErrors = false)
{
$out = array_merge($typo3, $baseData);
$typoScriptKeys = [];
$mapping = $this->getMapping($table);
// Process every field (except "usergroup" and "parentGroup") which is not a TypoScript definition
foreach ($mapping as $field => $value) {
if (substr($field, -1) !== '.') {
if ($field !== 'usergroup' && $field !== 'parentGroup') {
try {
$out = $this->mergeSimple($oidc, $out, $field, $value);
} catch (\UnexpectedValueException $uve) {
if ($reportErrors) {
$out['__errors'][] = $uve->getMessage();
}
}
}
} else {
$typoScriptKeys[] = $field;
}
}
if (count($typoScriptKeys) > 0) {
$backupTSFE = $GLOBALS['TSFE'];
// Advanced stdWrap methods require a valid $GLOBALS['TSFE'] => create the most lightweight one
$GLOBALS['TSFE'] = GeneralUtility::makeInstance(
\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::class,
$GLOBALS['TYPO3_CONF_VARS'],
0,
''
);
$GLOBALS['TSFE']->initTemplate();
$GLOBALS['TSFE']->renderCharset = 'utf-8';
/** @var $contentObj \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer */
$contentObj = GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class);
$contentObj->start($oidc, '');
// Process every TypoScript definition
foreach ($typoScriptKeys as $typoScriptKey) {
// Remove the trailing period to get corresponding field name
$field = substr($typoScriptKey, 0, -1);
$value = isset($out[$field]) ? $out[$field] : '';
$value = $contentObj->stdWrap($value, $mapping[$typoScriptKey]);
$out = $this->mergeSimple([$field => $value], $out, $field, $value);
}
// Instantiation of TypoScriptFrontendController instantiates PageRenderer which
// sets backPath to TYPO3_mainDir which is very bad in the Backend. Therefore,
// we must set it back to null to not get frontend-prefixed asset URLs.
if (TYPO3_MODE === 'BE') {
$pageRenderer = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Page\PageRenderer::class);
$pageRenderer->setBackPath(null);
}
$GLOBALS['TSFE'] = $backupTSFE;
}
return $out;
}
/**
* Replaces all OIDC markers (e.g. <cn>) with their corresponding values
* in the OIDC data array.
*
* If no matching value was found in the array the marker will be removed.
*
* @param array $oidc
* @param array $typo3
* @param string $field
* @param string $value
* @return array Modified $typo3 array
* @throws \UnexpectedValueException
* @see \Causal\IgLdapSsoAuth\Library\Authentication::mergeSimple()
* @see \Causal\IgLdapSsoAuth\Library\Authentication::replaceLdapMarkers()
* @see \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::getFieldVal()
*/
protected function mergeSimple(array $oidc, array $typo3, $field, $value)
{
// Constant by default
$mappedValue = $value;
if (preg_match("`<([^$]*)>`", $value, $attribute)) { // OIDC attribute
$sections = !strstr($value, '//')
? [$value]
: GeneralUtility::trimExplode('//', $value, true);
$mappedValue = '';
foreach ($sections as $sectionKey => $sectionValue) {
preg_match_all('/<(.+?)>/', $sectionValue, $matches);
foreach ($matches[0] as $index => $fullMatchedMarker) {
$oidcProperty = strtolower($matches[1][$index]);
if (isset($oidc[$oidcProperty])) {
$oidcValue = $oidc[$oidcProperty];
if (is_array($oidcValue)) {
$oidcValue = $oidcValue[0];
}
$sectionValue = str_replace($fullMatchedMarker, $oidcValue, $sectionValue);
} else {
$sectionValue = str_replace($fullMatchedMarker, '', $sectionValue);
}
}
$sections[$sectionKey] = $sectionValue;
}
foreach ($sections as $sectionValue) {
if ($sectionValue !== '') {
$mappedValue = $sectionValue;
break;
}
}
}
$typo3[$field] = $mappedValue;
return $typo3;
}
/**
* Returns the mapping configuration for OIDC fields.
*
* @param string $table
* @return array
*/
protected function getMapping($table)
{
$mapping = [];
$defaultMapping = [
'username' => '<sub>',
'name' => '<name>',
'first_name' => '<Vorname>',
'last_name' => '<FamilienName>',
'address' => '<Strasse>',
'title' => '<Anredecode>',
'zip' => '<PLZ>',
'city' => '<Ort>',
'country' => '<Land>',
];
if ($table === 'fe_users') {
$setup = $this->getTypoScriptSetup();
if (!empty($setup['plugin.']['tx_oidc.']['mapping.'][$table . '.'])) {
$mapping = $setup['plugin.']['tx_oidc.']['mapping.'][$table . '.'];
}
}
return $mapping ?: $defaultMapping;
}
/**
* Returns TypoScript Setup array from current environment.
*
* Note: $GLOBALS['TSFE']->tmpl->setup is not yet available at this point.
*
* @return array the raw TypoScript setup
*/
protected function getTypoScriptSetup()
{
// This is needed for the PageRepository
$files = ['EXT:core/Configuration/TCA/pages.php'];
foreach ($files as $file) {
$file = GeneralUtility::getFileAbsFileName($file);
$table = substr($file, strrpos($file, '/') + 1, -4); // strip ".php" at the end
$GLOBALS['TCA'][$table] = include($file);
}
/** @var \TYPO3\CMS\Frontend\Page\PageRepository $pageRepository */
$pageRepository = GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Page\PageRepository::class);
$pageRepository->init(false);
/** @var \TYPO3\CMS\Core\TypoScript\TemplateService $templateService */
$templateService = GeneralUtility::makeInstance(\TYPO3\CMS\Core\TypoScript\TemplateService::class);
$typo3Branch = class_exists(\TYPO3\CMS\Core\Information\Typo3Version::class)
? (new \TYPO3\CMS\Core\Information\Typo3Version())->getBranch()
: TYPO3_branch;
if (version_compare($typo3Branch, '9.0', '<')) {
$templateService->init();
}
$templateService->tt_track = false;
$currentPage = $GLOBALS['TSFE']->id;
if ($currentPage === null) {
// root page is not yet populated
$localTSFE = clone $GLOBALS['TSFE'];
if (version_compare($typo3Branch, '9.5', '>=')) {
$localTSFE->fe_user = GeneralUtility::makeInstance(FrontendUserAuthentication::class);
}
$localTSFE->determineId();
$currentPage = $localTSFE->id;
}
if (version_compare($typo3Branch, '9.5', '>=')) {
$rootLine = GeneralUtility::makeInstance(RootlineUtility::class, (int)$currentPage)->get();
} else {
$rootLine = $pageRepository->getRootLine((int)$currentPage);
}
$templateService->start($rootLine);
$setup = $templateService->setup;
return $setup;
}
/**
* Returns a logger.
*
* @return \TYPO3\CMS\Core\Log\Logger
*/
protected static function getLogger()
{
/** @var \TYPO3\CMS\Core\Log\Logger $logger */
static $logger = null;
if ($logger === null) {
$logger = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Log\LogManager::class)->getLogger(__CLASS__);
}
return $logger;
}
}