Skip to content

Commit

Permalink
[BUGFIX] Fix Undefined array key warning with PHP 8
Browse files Browse the repository at this point in the history
Related: #129
  • Loading branch information
xperseguers committed Nov 25, 2021
1 parent 7aa2c95 commit 2a3d9a9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
31 changes: 20 additions & 11 deletions Classes/Library/Authentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public static function synchroniseUser($userdn, $username = null)
static::getLogger()->debug('User record has been deleted because she has no LDAP groups.', $typo3_user);
}
// Set groups to user.
$groupTable = static::$authenticationService->authInfo['db_groups']['table'];
$groupTable = static::getGroupTable();
$typo3_user = Typo3UserRepository::setUserGroups($typo3_user, $typo3_groups, $groupTable);
// Merge LDAP user with TYPO3 user from mapping.
if ($typo3_user) {
Expand Down Expand Up @@ -334,15 +334,7 @@ public static function getUserGroups(array $ldapUser, array $configuration = nul
$configuration = static::$config;
}
if (empty($groupTable)) {
if (isset(static::$authenticationService)) {
$groupTable = static::$authenticationService->authInfo['db_groups']['table'];
} else {
if (TYPO3_MODE === 'BE') {
$groupTable = 'be_groups';
} else {
$groupTable = 'fe_groups';
}
}
$groupTable = static::getGroupTable();
}

// User is valid only if exist in TYPO3.
Expand Down Expand Up @@ -445,7 +437,7 @@ public static function getUserGroups(array $ldapUser, array $configuration = nul
}
}
// Hook for processing the groups
if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ig_ldap_sso_auth']['getGroupsProcessing'])) {
if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ig_ldap_sso_auth']['getGroupsProcessing'] ?? null)) {
foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ig_ldap_sso_auth']['getGroupsProcessing'] as $className) {
/** @var $postProcessor \Causal\IgLdapSsoAuth\Utility\GetGroupsProcessorInterface */
$postProcessor = GeneralUtility::makeInstance($className);
Expand Down Expand Up @@ -909,6 +901,23 @@ protected static function getCreationUserId(): int
return $cruserId ?? 0;
}

/**
* @return string
*/
protected static function getGroupTable(): string
{
if (isset(static::$authenticationService) && !empty(static::$authenticationService->authInfo['db_groups']['table'])) {
$groupTable = static::$authenticationService->authInfo['db_groups']['table'];
} else {
if (TYPO3_MODE === 'BE') {
$groupTable = 'be_groups';
} else {
$groupTable = 'fe_groups';
}
}
return $groupTable;
}

/**
* Returns a logger.
*
Expand Down
7 changes: 5 additions & 2 deletions Classes/Service/AuthenticationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,10 @@ public function getUser()
if (!$userRecordOrIsValid && $this->login['status'] === 'login' && $this->login['uident']) {

// Configuration of authentication service.
$loginSecurityLevel = $GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['loginSecurityLevel'];
$typo3Branch = (new \TYPO3\CMS\Core\Information\Typo3Version())->getBranch();
$loginSecurityLevel = version_compare($typo3Branch, '11.0', '>')
? 'normal'
: $GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['loginSecurityLevel'];
// normal case
// Check if $loginSecurityLevel is set to "challenged" or "superchallenged" and throw an error if the configuration allows it
// By default, it will not throw an exception
Expand Down Expand Up @@ -243,7 +246,7 @@ public function authUser(array $user): int
}

// Checking the domain (lockToDomain)
if ($status && $user['lockToDomain'] && $user['lockToDomain'] != $this->authInfo['HTTP_HOST']) {
if ($status && !empty($user['lockToDomain']) && $user['lockToDomain'] !== $this->authInfo['HTTP_HOST']) {

// Lock domain didn't match, so error:
static::getLogger()->error(sprintf('Locked domain "%s" did not match "%s"', $user['lockToDomain'], $this->authInfo['HTTP_HOST']), [
Expand Down

0 comments on commit 2a3d9a9

Please sign in to comment.