renaming of files and classes resolve conflict with plugin ldap-identities

This commit is contained in:
cm-schl 2022-11-29 16:51:54 +01:00
parent 79191cf7a3
commit 71069a8cc9
5 changed files with 35 additions and 36 deletions

View file

@ -1,5 +0,0 @@
<?php
class LdapException extends \RainLoop\Exceptions\ClientException
{
}

View file

@ -17,7 +17,7 @@ class LdapMailAccounts
/** @var bool */ /** @var bool */
private $ldapBound = false; private $ldapBound = false;
/** @var LdapConfig */ /** @var LdapMailAccountsConfig */
private $config; private $config;
/** @var Logger */ /** @var Logger */
@ -28,10 +28,10 @@ class LdapMailAccounts
/** /**
* LdapMailAccount constructor. * LdapMailAccount constructor.
* *
* @param LdapConfig $config LdapConfig object containing the admin configuration for this plugin * @param LdapMailAccountsConfig $config LdapMailAccountsConfig object containing the admin configuration for this plugin
* @param Logger $logger Used to write to the logfile * @param Logger $logger Used to write to the logfile
*/ */
public function __construct(LdapConfig $config, Logger $logger) public function __construct(LdapMailAccountsConfig $config, Logger $logger)
{ {
$this->config = $config; $this->config = $config;
$this->logger = $logger; $this->logger = $logger;
@ -60,7 +60,7 @@ class LdapMailAccounts
{ {
try { try {
$this->EnsureBound(); $this->EnsureBound();
} catch (LdapException $e) { } catch (LdapMailAccountsException $e) {
return false; // exceptions are only thrown from the handleerror function that does logging already return false; // exceptions are only thrown from the handleerror function that does logging already
} }
@ -87,7 +87,7 @@ class LdapMailAccounts
$this->config->field_domain $this->config->field_domain
); );
} }
catch (LdapException $e) { catch (LdapMailAccountsException $e) {
return false; // exceptions are only thrown from the handleerror function that does logging already return false; // exceptions are only thrown from the handleerror function that does logging already
} }
if (count($mailAddressResults) < 1) { if (count($mailAddressResults) < 1) {
@ -165,7 +165,7 @@ class LdapMailAccounts
/** /**
* Checks if a connection to the LDAP was possible * Checks if a connection to the LDAP was possible
* *
* @throws LdapException * @throws LdapMailAccountsException
* *
* */ * */
private function EnsureConnected(): void private function EnsureConnected(): void
@ -204,7 +204,7 @@ class LdapMailAccounts
/** /**
* Ensures the plugin has been authenticated at the LDAP * Ensures the plugin has been authenticated at the LDAP
* *
* @throws LdapException * @throws LdapMailAccountsException
* *
* */ * */
private function EnsureBound(): void private function EnsureBound(): void
@ -239,7 +239,7 @@ class LdapMailAccounts
* Handles and logs an eventual LDAP error * Handles and logs an eventual LDAP error
* *
* @param string $op * @param string $op
* @throws LdapException * @throws LdapMailAccountsException
*/ */
private function HandleLdapError(string $op = ""): void private function HandleLdapError(string $op = ""): void
{ {
@ -249,7 +249,7 @@ class LdapMailAccounts
$message = empty($op) ? "LDAP Error: {$errorMsg} ({$errorNo})" : "LDAP Error during {$op}: {$errorMsg} ({$errorNo})"; $message = empty($op) ? "LDAP Error: {$errorMsg} ({$errorNo})" : "LDAP Error during {$op}: {$errorMsg} ({$errorNo})";
$this->logger->Write($message, \LOG_ERR, self::LOG_KEY); $this->logger->Write($message, \LOG_ERR, self::LOG_KEY);
throw new LdapException($message, $errorNo); throw new LdapMailAccountsException($message, $errorNo);
} }
/** /**
@ -264,8 +264,8 @@ class LdapMailAccounts
* @param string $nameField * @param string $nameField
* @param string $usernameField * @param string $usernameField
* @param string $domainField * @param string $domainField
* @return LdapResult[] * @return LdapMailAccountResult[]
* @throws LdapException * @throws LdapMailAccountsException
*/ */
private function FindLdapResults( private function FindLdapResults(
string $searchField, string $searchField,
@ -296,12 +296,12 @@ class LdapMailAccounts
return []; return [];
} }
// Save the found ldap entries into a LdapResult object and return them // Save the found ldap entries into a LdapMailAccountResult object and return them
$results = []; $results = [];
for ($i = 0; $i < $entries["count"]; $i++) { for ($i = 0; $i < $entries["count"]; $i++) {
$entry = $entries[$i]; $entry = $entries[$i];
$result = new LdapResult(); $result = new LdapMailAccountResult();
$result->dn = $entry["dn"]; $result->dn = $entry["dn"];
$result->name = $this->LdapGetAttribute($entry, $nameField, true, true); $result->name = $this->LdapGetAttribute($entry, $nameField, true, true);
@ -394,7 +394,7 @@ class LdapMailAccounts
} }
} }
class LdapResult class LdapMailAccountResult
{ {
/** @var string */ /** @var string */
public $dn; public $dn;

View file

@ -3,7 +3,7 @@
use RainLoop\Config\Plugin; use RainLoop\Config\Plugin;
class LdapConfig class LdapMailAccountsConfig
{ {
public const CONFIG_SERVER = "server"; public const CONFIG_SERVER = "server";
public const CONFIG_PROTOCOL_VERSION = "server_version"; public const CONFIG_PROTOCOL_VERSION = "server_version";
@ -31,7 +31,7 @@ class LdapConfig
public $search_string; public $search_string;
public $field_domain; public $field_domain;
public static function MakeConfig(Plugin $config): LdapConfig public static function MakeConfig(Plugin $config): LdapMailAccountsConfig
{ {
$ldap = new self(); $ldap = new self();
$ldap->server = trim($config->Get("plugin", self::CONFIG_SERVER)); $ldap->server = trim($config->Get("plugin", self::CONFIG_SERVER));

View file

@ -0,0 +1,5 @@
<?php
class LdapMailAccountsException extends \RainLoop\Exceptions\ClientException
{
}

View file

@ -23,8 +23,8 @@ class LdapMailAccountsPlugin extends AbstractPlugin
public function __construct() public function __construct()
{ {
include_once __DIR__ . '/LdapMailAccounts.php'; include_once __DIR__ . '/LdapMailAccounts.php';
include_once __DIR__ . '/LdapConfig.php'; include_once __DIR__ . '/LdapMailAccountsConfig.php';
include_once __DIR__ . '/LdapException.php'; include_once __DIR__ . '/LdapMailAccountsException.php';
parent::__construct(); parent::__construct();
} }
@ -40,11 +40,10 @@ class LdapMailAccountsPlugin extends AbstractPlugin
* *
* @param Account $oAccount * @param Account $oAccount
*/ */
public function AddAdditionalLdapMailAccounts(Account $oAccount) public function AddAdditionalLdapMailAccounts(Account $oAccount)
{ {
// Set up config // Set up config
$config = LdapConfig::MakeConfig($this->Config()); $config = LdapMailAccountsConfig::MakeConfig($this->Config());
$oldapMailAccounts = new LdapMailAccounts($config, $this->Manager()->Actions()->Logger()); $oldapMailAccounts = new LdapMailAccounts($config, $this->Manager()->Actions()->Logger());
@ -57,44 +56,44 @@ class LdapMailAccountsPlugin extends AbstractPlugin
protected function configMapping(): array protected function configMapping(): array
{ {
return [ return [
Property::NewInstance(LdapConfig::CONFIG_SERVER) Property::NewInstance(LdapMailAccountsConfig::CONFIG_SERVER)
->SetLabel("LDAP Server URL") ->SetLabel("LDAP Server URL")
->SetPlaceholder("ldap://server:port") ->SetPlaceholder("ldap://server:port")
->SetType(PluginPropertyType::STRING), ->SetType(PluginPropertyType::STRING),
Property::NewInstance(LdapConfig::CONFIG_PROTOCOL_VERSION) Property::NewInstance(LdapMailAccountsConfig::CONFIG_PROTOCOL_VERSION)
->SetLabel("LDAP Protocol Version") ->SetLabel("LDAP Protocol Version")
->SetType(PluginPropertyType::SELECTION) ->SetType(PluginPropertyType::SELECTION)
->SetDefaultValue([2, 3]), ->SetDefaultValue([2, 3]),
Property::NewInstance(LdapConfig::CONFIG_BIND_USER) Property::NewInstance(LdapMailAccountsConfig::CONFIG_BIND_USER)
->SetLabel("LDAP Username") ->SetLabel("LDAP Username")
->SetDescription("The user to use for binding to the LDAP server. Should be a DN or RDN. Leave empty for anonymous bind.") ->SetDescription("The user to use for binding to the LDAP server. Should be a DN or RDN. Leave empty for anonymous bind.")
->SetType(PluginPropertyType::STRING), ->SetType(PluginPropertyType::STRING),
Property::NewInstance(LdapConfig::CONFIG_BIND_PASSWORD) Property::NewInstance(LdapMailAccountsConfig::CONFIG_BIND_PASSWORD)
->SetLabel("LDAP Password") ->SetLabel("LDAP Password")
->SetDescription("Leave empty for anonymous bind.") ->SetDescription("Leave empty for anonymous bind.")
->SetType(PluginPropertyType::PASSWORD), ->SetType(PluginPropertyType::PASSWORD),
Property::NewInstance(LdapConfig::CONFIG_OBJECTCLASS) Property::NewInstance(LdapMailAccountsConfig::CONFIG_OBJECTCLASS)
->SetLabel("Object class") ->SetLabel("Object class")
->SetType(PluginPropertyType::STRING) ->SetType(PluginPropertyType::STRING)
->SetDescription("The object class to use when searching for additional mail accounts of the logged in SnappyMail user") ->SetDescription("The object class to use when searching for additional mail accounts of the logged in SnappyMail user")
->SetDefaultValue("user"), ->SetDefaultValue("user"),
Property::NewInstance(LdapConfig::CONFIG_BASE) Property::NewInstance(LdapMailAccountsConfig::CONFIG_BASE)
->SetLabel("Base DN") ->SetLabel("Base DN")
->SetType(PluginPropertyType::STRING) ->SetType(PluginPropertyType::STRING)
->SetDescription("The base DN to search in for additional mail accounts of the logged in SnappyMail user"), ->SetDescription("The base DN to search in for additional mail accounts of the logged in SnappyMail user"),
Property::NewInstance(LdapConfig::CONFIG_FIELD_SEARCH) Property::NewInstance(LdapMailAccountsConfig::CONFIG_FIELD_SEARCH)
->SetLabel("Search field") ->SetLabel("Search field")
->SetType(PluginPropertyType::STRING) ->SetType(PluginPropertyType::STRING)
->SetDescription("The name of the ldap attribute that has to contain the here defined 'LDAP search string'.") ->SetDescription("The name of the ldap attribute that has to contain the here defined 'LDAP search string'.")
->SetDefaultValue("member"), ->SetDefaultValue("member"),
Property::NewInstance(LdapConfig::CONFIG_SEARCH_STRING) Property::NewInstance(LdapMailAccountsConfig::CONFIG_SEARCH_STRING)
->SetLabel("LDAP search string") ->SetLabel("LDAP search string")
->SetType(PluginPropertyType::STRING) ->SetType(PluginPropertyType::STRING)
->SetDescription("The search string used to find ldap objects of mail accounts the user has access to. ->SetDescription("The search string used to find ldap objects of mail accounts the user has access to.
@ -102,7 +101,7 @@ class LdapMailAccountsPlugin extends AbstractPlugin
\n#BASE_DN# - replaced with the value inside the field 'User base DN'.") \n#BASE_DN# - replaced with the value inside the field 'User base DN'.")
->SetDefaultValue("uid=#USERNAME#"), ->SetDefaultValue("uid=#USERNAME#"),
Property::NewInstance(LdapConfig::CONFIG_FIELD_USERNAME) Property::NewInstance(LdapMailAccountsConfig::CONFIG_FIELD_USERNAME)
->SetLabel("Username field of additional account") ->SetLabel("Username field of additional account")
->SetType(PluginPropertyType::STRING) ->SetType(PluginPropertyType::STRING)
->SetDescription("The field containing the username of the found additional mail account. ->SetDescription("The field containing the username of the found additional mail account.
@ -110,7 +109,7 @@ class LdapMailAccountsPlugin extends AbstractPlugin
\nIf this field contains an email address, only the local-part before the @ is used.") \nIf this field contains an email address, only the local-part before the @ is used.")
->SetDefaultValue("uid"), ->SetDefaultValue("uid"),
Property::NewInstance(LdapConfig::CONFIG_FIELD_MAIL_DOMAIN) Property::NewInstance(LdapMailAccountsConfig::CONFIG_FIELD_MAIL_DOMAIN)
->SetLabel("Domain name field of additional account") ->SetLabel("Domain name field of additional account")
->SetType(PluginPropertyType::STRING) ->SetType(PluginPropertyType::STRING)
->SetDescription("The field containing the domain name of the found additional mail account. ->SetDescription("The field containing the domain name of the found additional mail account.
@ -118,7 +117,7 @@ class LdapMailAccountsPlugin extends AbstractPlugin
\nIf this field contains an email address, only the domain-part after the @ is used.") \nIf this field contains an email address, only the domain-part after the @ is used.")
->SetDefaultValue("mail"), ->SetDefaultValue("mail"),
Property::NewInstance(LdapConfig::CONFIG_FIELD_NAME) Property::NewInstance(LdapMailAccountsConfig::CONFIG_FIELD_NAME)
->SetLabel("Additional account name field") ->SetLabel("Additional account name field")
->SetType(PluginPropertyType::STRING) ->SetType(PluginPropertyType::STRING)
->SetDescription("The field containing the default sender name of the found additional mail account.") ->SetDescription("The field containing the default sender name of the found additional mail account.")