type fixes
This commit is contained in:
@@ -75,6 +75,9 @@ class Data
|
||||
return $this->createSecret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string,mixed> $data
|
||||
*/
|
||||
public static function create(array $data): self
|
||||
{
|
||||
$object = new self();
|
||||
|
||||
@@ -70,30 +70,27 @@ class Authentication
|
||||
{
|
||||
private const LOGOUT_USERNAME = '**logout';
|
||||
|
||||
private $allowAnyAccess;
|
||||
private bool $allowAnyAccess;
|
||||
|
||||
private $portal;
|
||||
private ?Portal $portal = null;
|
||||
|
||||
private $applicationUser;
|
||||
private ApplicationUser $applicationUser;
|
||||
|
||||
private $applicationState;
|
||||
private ApplicationState $applicationState;
|
||||
|
||||
private $configDataProvider;
|
||||
private ConfigDataProvider $configDataProvider;
|
||||
|
||||
/**
|
||||
* @var EntityManagerProxy
|
||||
*/
|
||||
private $entityManager;
|
||||
private EntityManagerProxy $entityManager;
|
||||
|
||||
private $loginFactory;
|
||||
private LoginFactory $loginFactory;
|
||||
|
||||
private $twoFactorLoginFactory;
|
||||
private TwoFactorLoginFactory $twoFactorLoginFactory;
|
||||
|
||||
private $authTokenManager;
|
||||
private AuthTokenManager $authTokenManager;
|
||||
|
||||
private $hookManager;
|
||||
private HookManager $hookManager;
|
||||
|
||||
private $log;
|
||||
private Log $log;
|
||||
|
||||
public function __construct(
|
||||
ApplicationUser $applicationUser,
|
||||
|
||||
@@ -38,9 +38,9 @@ use Espo\Core\Authentication\Result;
|
||||
|
||||
class Manager
|
||||
{
|
||||
private $metadata;
|
||||
private Metadata $metadata;
|
||||
|
||||
private $injectableFactory;
|
||||
private InjectableFactory $injectableFactory;
|
||||
|
||||
public function __construct(Metadata $metadata, InjectableFactory $injectableFactory)
|
||||
{
|
||||
@@ -84,7 +84,7 @@ class Manager
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
* @return class-string[]
|
||||
*/
|
||||
private function getHookClassNameList(string $type): array
|
||||
{
|
||||
|
||||
@@ -31,6 +31,9 @@ namespace Espo\Core\Authentication\LDAP;
|
||||
|
||||
class ClientFactory
|
||||
{
|
||||
/**
|
||||
* @param array<string,mixed> $options
|
||||
*/
|
||||
public function create(array $options): Client
|
||||
{
|
||||
return new Client($options);
|
||||
|
||||
@@ -33,11 +33,17 @@ use Espo\Core\Utils\Config;
|
||||
|
||||
class Utils
|
||||
{
|
||||
private $config;
|
||||
private Config $config;
|
||||
|
||||
protected $options = null;
|
||||
/**
|
||||
* @var ?array<string,mixed>
|
||||
*/
|
||||
private ?array $options = null;
|
||||
|
||||
protected $fieldMap = [
|
||||
/**
|
||||
* @var array<string,string>
|
||||
*/
|
||||
private $fieldMap = [
|
||||
'host' => 'ldapHost',
|
||||
'port' => 'ldapPort',
|
||||
'useSsl' => 'ldapSecurity',
|
||||
@@ -69,7 +75,10 @@ class Utils
|
||||
'portalUserRolesIds' => 'ldapPortalUserRolesIds',
|
||||
];
|
||||
|
||||
protected $permittedEspoOptions = [
|
||||
/**
|
||||
* @var array<int,string>
|
||||
*/
|
||||
private $permittedEspoOptions = [
|
||||
'createEspoUser',
|
||||
'userNameAttribute',
|
||||
'userObjectClass',
|
||||
@@ -87,9 +96,11 @@ class Utils
|
||||
];
|
||||
|
||||
/**
|
||||
* accountCanonicalForm Map between Espo and Laminas value.
|
||||
* AccountCanonicalForm Map between Espo and Laminas value.
|
||||
*
|
||||
* @var array<string,int>
|
||||
*/
|
||||
protected $accountCanonicalFormMap = [
|
||||
private $accountCanonicalFormMap = [
|
||||
'Dn' => 1,
|
||||
'Username' => 2,
|
||||
'Backslash' => 3,
|
||||
@@ -103,25 +114,21 @@ class Utils
|
||||
}
|
||||
}
|
||||
|
||||
protected function getConfig()
|
||||
{
|
||||
return $this->config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Options from espo config according to $this->fieldMap.
|
||||
*
|
||||
* @return array
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
public function getOptions()
|
||||
public function getOptions(): array
|
||||
{
|
||||
if (isset($this->options)) {
|
||||
return $this->options;
|
||||
}
|
||||
|
||||
$options = [];
|
||||
|
||||
foreach ($this->fieldMap as $ldapName => $espoName) {
|
||||
$option = $this->getConfig()->get($espoName);
|
||||
$option = $this->config->get($espoName);
|
||||
|
||||
if (isset($option)) {
|
||||
$options[$ldapName] = $option;
|
||||
@@ -136,24 +143,24 @@ class Utils
|
||||
/**
|
||||
* Normalize options to LDAP client format
|
||||
*
|
||||
* @param array $options
|
||||
* @param array<string,mixed> $options
|
||||
*
|
||||
* @return array
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
public function normalizeOptions(array $options)
|
||||
public function normalizeOptions(array $options): array
|
||||
{
|
||||
$options['useSsl'] = (bool) ($options['useSsl'] == 'SSL');
|
||||
$options['useStartTls'] = (bool) ($options['useStartTls'] == 'TLS');
|
||||
$options['accountCanonicalForm'] = $this->accountCanonicalFormMap[ $options['accountCanonicalForm'] ];
|
||||
$options['accountCanonicalForm'] = $this->accountCanonicalFormMap[$options['accountCanonicalForm']];
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an ldap option.
|
||||
* Get an LDAP option.
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $returns Return value
|
||||
* @param string $name
|
||||
* @param mixed $returns A default value.
|
||||
* @return mixed
|
||||
*/
|
||||
public function getOption($name, $returns = null)
|
||||
@@ -172,11 +179,12 @@ class Utils
|
||||
/**
|
||||
* Get Laminas options for using Laminas\Ldap.
|
||||
*
|
||||
* @return array
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
public function getLdapClientOptions()
|
||||
public function getLdapClientOptions(): array
|
||||
{
|
||||
$options = $this->getOptions();
|
||||
|
||||
$zendOptions = array_diff_key($options, array_flip($this->permittedEspoOptions));
|
||||
|
||||
return $zendOptions;
|
||||
|
||||
@@ -33,11 +33,11 @@ use Espo\Core\Authentication\AuthToken\AuthToken;
|
||||
|
||||
class DataBuilder
|
||||
{
|
||||
private $username = null;
|
||||
private ?string $username = null;
|
||||
|
||||
private $password = null;
|
||||
private ?string $password = null;
|
||||
|
||||
private $authToken = null;
|
||||
private ?AuthToken $authToken = null;
|
||||
|
||||
public function setUsername(?string $username): self
|
||||
{
|
||||
|
||||
@@ -37,11 +37,11 @@ class LoginFactory
|
||||
{
|
||||
private const DEFAULT_METHOD = 'Espo';
|
||||
|
||||
private $injectableFactory;
|
||||
private InjectableFactory $injectableFactory;
|
||||
|
||||
private $metadata;
|
||||
private Metadata $metadata;
|
||||
|
||||
private $config;
|
||||
private Config $config;
|
||||
|
||||
public function __construct(InjectableFactory $injectableFactory, Metadata $metadata, Config $config)
|
||||
{
|
||||
@@ -52,12 +52,14 @@ class LoginFactory
|
||||
|
||||
public function create(string $method, bool $isPortal = false): Login
|
||||
{
|
||||
/** @var class-string */
|
||||
$className = $this->metadata->get(['authenticationMethods', $method, 'implementationClassName']);
|
||||
|
||||
if (!$className) {
|
||||
$sanitizedName = preg_replace('/[^a-zA-Z0-9]+/', '', $method);
|
||||
|
||||
if (!class_exists($className)) {
|
||||
/** @var class-string */
|
||||
$className = "Espo\\Core\\Authentication\\Logins\\" . $sanitizedName;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,29 +60,32 @@ class LDAP implements Login
|
||||
{
|
||||
private $utils;
|
||||
|
||||
private $client;
|
||||
/**
|
||||
* @var ?Client
|
||||
*/
|
||||
private $client = null;
|
||||
|
||||
private $isPortal;
|
||||
private bool $isPortal;
|
||||
|
||||
private $config;
|
||||
private Config $config;
|
||||
|
||||
private $entityManager;
|
||||
private EntityManager $entityManager;
|
||||
|
||||
private $passwordHash;
|
||||
private PasswordHash $passwordHash;
|
||||
|
||||
private $language;
|
||||
private Language $language;
|
||||
|
||||
private $log;
|
||||
private Log $log;
|
||||
|
||||
private $baseLogin;
|
||||
private Espo $baseLogin;
|
||||
|
||||
private $clientFactory;
|
||||
private ClientFactory $clientFactory;
|
||||
|
||||
private $linkMultipleSaver;
|
||||
private LinkMultipleSaver $linkMultipleSaver;
|
||||
|
||||
private $emailAddressSaver;
|
||||
private EmailAddressSaver $emailAddressSaver;
|
||||
|
||||
private $phoneNumberSaver;
|
||||
private PhoneNumberSaver $phoneNumberSaver;
|
||||
|
||||
public function __construct(
|
||||
Config $config,
|
||||
@@ -113,6 +116,9 @@ class LDAP implements Login
|
||||
$this->utils = new LDAPUtils($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* @var array<string,string>
|
||||
*/
|
||||
private $ldapFieldMap = [
|
||||
'userName' => 'userNameAttribute',
|
||||
'firstName' => 'userFirstNameAttribute',
|
||||
@@ -122,11 +128,17 @@ class LDAP implements Login
|
||||
'phoneNumber' => 'userPhoneNumberAttribute',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array<string,string>
|
||||
*/
|
||||
private $userFieldMap = [
|
||||
'teamsIds' => 'userTeamsIds',
|
||||
'defaultTeamId' => 'userDefaultTeamId',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array<string,string>
|
||||
*/
|
||||
private $portalUserFieldMap = [
|
||||
'portalsIds' => 'portalUserPortalsIds',
|
||||
'portalRolesIds' => 'portalUserRolesIds',
|
||||
@@ -273,9 +285,9 @@ class LDAP implements Login
|
||||
/**
|
||||
* Login by authorization token.
|
||||
*/
|
||||
private function loginByToken($username, AuthToken $authToken = null): ?User
|
||||
private function loginByToken(?string $username, AuthToken $authToken = null): ?User
|
||||
{
|
||||
if (!isset($authToken)) {
|
||||
if (!isset($authToken) || $username === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -308,7 +320,7 @@ class LDAP implements Login
|
||||
->findOne();
|
||||
}
|
||||
|
||||
private function adminLogin($username, $password)
|
||||
private function adminLogin(string $username, string $password): ?User
|
||||
{
|
||||
$hash = $this->passwordHash->hash($password);
|
||||
|
||||
@@ -324,8 +336,10 @@ class LDAP implements Login
|
||||
|
||||
/**
|
||||
* Create Espo user with data gets from LDAP server.
|
||||
*
|
||||
* @param array<string,mixed> $userData
|
||||
*/
|
||||
private function createUser(array $userData, $isPortal = false)
|
||||
private function createUser(array $userData, bool $isPortal = false): ?User
|
||||
{
|
||||
$this->log->info('Creating new user...');
|
||||
|
||||
@@ -387,7 +401,7 @@ class LDAP implements Login
|
||||
/**
|
||||
* Find LDAP user DN by his username.
|
||||
*/
|
||||
private function findLdapUserDnByUsername($username)
|
||||
private function findLdapUserDnByUsername(string $username): ?string
|
||||
{
|
||||
$ldapClient = $this->getLdapClient();
|
||||
|
||||
@@ -411,12 +425,14 @@ class LDAP implements Login
|
||||
foreach ($result as $item) {
|
||||
return $item["dn"];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check and convert filter item into LDAP format.
|
||||
*/
|
||||
private function convertToFilterFormat($filter)
|
||||
private function convertToFilterFormat(string $filter): string
|
||||
{
|
||||
$filter = trim($filter);
|
||||
|
||||
@@ -433,6 +449,8 @@ class LDAP implements Login
|
||||
|
||||
/**
|
||||
* Load fields for a user.
|
||||
*
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
private function loadFields(string $type): array
|
||||
{
|
||||
|
||||
@@ -46,21 +46,21 @@ class Result
|
||||
|
||||
public const STATUS_FAIL = 'fail';
|
||||
|
||||
private $user;
|
||||
private ?User $user = null;
|
||||
|
||||
private $status;
|
||||
private string $status;
|
||||
|
||||
private $message = null;
|
||||
private ?string $message = null;
|
||||
|
||||
private $token = null;
|
||||
private ?string $token = null;
|
||||
|
||||
private $view = null;
|
||||
private ?string $view = null;
|
||||
|
||||
private $loggedUser = null;
|
||||
private ?User $loggedUser = null;
|
||||
|
||||
private $failReason = null;
|
||||
private ?string $failReason = null;
|
||||
|
||||
private $data = null;
|
||||
private ?Data $data = null;
|
||||
|
||||
private function __construct(string $status, ?User $user = null, ?Data $data = null)
|
||||
{
|
||||
|
||||
@@ -35,17 +35,20 @@ use stdClass;
|
||||
|
||||
class Data
|
||||
{
|
||||
private $message = null;
|
||||
private ?string $message = null;
|
||||
|
||||
private $token = null;
|
||||
private ?string$token = null;
|
||||
|
||||
private $view = null;
|
||||
private ?string $view = null;
|
||||
|
||||
private $loggedUser = null;
|
||||
private ?User $loggedUser = null;
|
||||
|
||||
private $failReason = null;
|
||||
private ?string $failReason = null;
|
||||
|
||||
private $data = [];
|
||||
/**
|
||||
* @var array<string,mixed>
|
||||
*/
|
||||
private array $data = [];
|
||||
|
||||
private function __construct(
|
||||
?string $message = null,
|
||||
|
||||
@@ -35,9 +35,9 @@ use Espo\Core\Exceptions\Error;
|
||||
|
||||
class LoginFactory
|
||||
{
|
||||
private $injectableFactory;
|
||||
private InjectableFactory $injectableFactory;
|
||||
|
||||
private $metadata;
|
||||
private Metadata $metadata;
|
||||
|
||||
public function __construct(InjectableFactory $injectableFactory, Metadata $metadata)
|
||||
{
|
||||
@@ -47,6 +47,7 @@ class LoginFactory
|
||||
|
||||
public function create(string $method): Login
|
||||
{
|
||||
/** @var ?class-string */
|
||||
$className = $this->metadata->get(['app', 'authentication2FAMethods', $method, 'loginClassName']);
|
||||
|
||||
if (!$className) {
|
||||
|
||||
@@ -36,9 +36,9 @@ use Espo\Core\Exceptions\Error;
|
||||
|
||||
class UserSetupFactory
|
||||
{
|
||||
private $injectableFactory;
|
||||
private InjectableFactory $injectableFactory;
|
||||
|
||||
private $metadata;
|
||||
private Metadata $metadata;
|
||||
|
||||
public function __construct(InjectableFactory $injectableFactory, Metadata $metadata)
|
||||
{
|
||||
@@ -48,6 +48,7 @@ class UserSetupFactory
|
||||
|
||||
public function create(string $method): UserSetup
|
||||
{
|
||||
/** @var ?class-string */
|
||||
$className = $this->metadata->get(['app', 'authentication2FAMethods', $method, 'userSetupClassName']);
|
||||
|
||||
if (!$className) {
|
||||
|
||||
Reference in New Issue
Block a user