aboutsummaryrefslogtreecommitdiffstats
path: root/apps/user_ldap/lib
diff options
context:
space:
mode:
authorCôme Chilliet <91878298+come-nc@users.noreply.github.com>2022-12-05 12:03:39 +0100
committerGitHub <noreply@github.com>2022-12-05 12:03:39 +0100
commit30560d316584276a08c909f5198a839c1c170cc9 (patch)
tree154477dee76d6b7451671010aa2318c500975521 /apps/user_ldap/lib
parentcb0450b5c4fbe590e7b35284a40d78d96a0251f6 (diff)
parent4196bf81e653c39d33d25c76652cc78dab8c5e1c (diff)
downloadnextcloud-server-30560d316584276a08c909f5198a839c1c170cc9.tar.gz
nextcloud-server-30560d316584276a08c909f5198a839c1c170cc9.zip
Merge branch 'master' into tests/fix-phpunit-warnings
Signed-off-by: Côme Chilliet <91878298+come-nc@users.noreply.github.com>
Diffstat (limited to 'apps/user_ldap/lib')
-rw-r--r--apps/user_ldap/lib/AppInfo/Application.php27
-rw-r--r--apps/user_ldap/lib/Configuration.php3
-rw-r--r--apps/user_ldap/lib/Connection.php23
-rw-r--r--apps/user_ldap/lib/Group_LDAP.php7
4 files changed, 50 insertions, 10 deletions
diff --git a/apps/user_ldap/lib/AppInfo/Application.php b/apps/user_ldap/lib/AppInfo/Application.php
index 79998a580e5..757ac141d3d 100644
--- a/apps/user_ldap/lib/AppInfo/Application.php
+++ b/apps/user_ldap/lib/AppInfo/Application.php
@@ -31,6 +31,7 @@ use OCA\Files_External\Service\BackendService;
use OCA\User_LDAP\Controller\RenewPasswordController;
use OCA\User_LDAP\Events\GroupBackendRegistered;
use OCA\User_LDAP\Events\UserBackendRegistered;
+use OCA\User_LDAP\FilesystemHelper;
use OCA\User_LDAP\Group_Proxy;
use OCA\User_LDAP\GroupPluginManager;
use OCA\User_LDAP\Handler\ExtStorageConfigHandler;
@@ -38,6 +39,7 @@ use OCA\User_LDAP\Helper;
use OCA\User_LDAP\ILDAPWrapper;
use OCA\User_LDAP\LDAP;
use OCA\User_LDAP\Notification\Notifier;
+use OCA\User_LDAP\User\Manager;
use OCA\User_LDAP\User_Proxy;
use OCA\User_LDAP\UserPluginManager;
use OCP\AppFramework\App;
@@ -46,10 +48,17 @@ use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\AppFramework\IAppContainer;
use OCP\EventDispatcher\IEventDispatcher;
+use OCP\IAvatarManager;
+use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IL10N;
+use OCP\Image;
use OCP\IServerContainer;
+use OCP\IUserManager;
use OCP\Notification\IManager as INotificationManager;
+use OCP\Share\IManager as IShareManager;
+use Psr\Container\ContainerInterface;
+use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class Application extends App implements IBootstrap {
@@ -87,6 +96,24 @@ class Application extends App implements IBootstrap {
public function register(IRegistrationContext $context): void {
$context->registerNotifierService(Notifier::class);
+
+ $context->registerService(
+ Manager::class,
+ function (ContainerInterface $c) {
+ return new Manager(
+ $c->get(IConfig::class),
+ $c->get(FilesystemHelper::class),
+ $c->get(LoggerInterface::class),
+ $c->get(IAvatarManager::class),
+ $c->get(Image::class),
+ $c->get(IUserManager::class),
+ $c->get(INotificationManager::class),
+ $c->get(IShareManager::class),
+ );
+ },
+ // the instance is specific to a lazy bound Access instance, thus cannot be shared.
+ false
+ );
}
public function boot(IBootContext $context): void {
diff --git a/apps/user_ldap/lib/Configuration.php b/apps/user_ldap/lib/Configuration.php
index c16823d39ee..fc620e00e30 100644
--- a/apps/user_ldap/lib/Configuration.php
+++ b/apps/user_ldap/lib/Configuration.php
@@ -120,6 +120,7 @@ class Configuration {
'ldapDefaultPPolicyDN' => null,
'ldapExtStorageHomeAttribute' => null,
'ldapMatchingRuleInChainState' => self::LDAP_SERVER_FEATURE_UNKNOWN,
+ 'ldapConnectionTimeout' => 15,
];
public function __construct(string $configPrefix, bool $autoRead = true) {
@@ -463,6 +464,7 @@ class Configuration {
'ldap_user_avatar_rule' => 'default',
'ldap_ext_storage_home_attribute' => '',
'ldap_matching_rule_in_chain_state' => self::LDAP_SERVER_FEATURE_UNKNOWN,
+ 'ldap_connection_timeout' => 15,
];
}
@@ -526,6 +528,7 @@ class Configuration {
'ldap_ext_storage_home_attribute' => 'ldapExtStorageHomeAttribute',
'ldap_matching_rule_in_chain_state' => 'ldapMatchingRuleInChainState',
'ldapIgnoreNamingRules' => 'ldapIgnoreNamingRules', // sysconfig
+ 'ldap_connection_timeout' => 'ldapConnectionTimeout',
];
return $array;
}
diff --git a/apps/user_ldap/lib/Connection.php b/apps/user_ldap/lib/Connection.php
index 89b58b7ebfd..dca55c1750e 100644
--- a/apps/user_ldap/lib/Connection.php
+++ b/apps/user_ldap/lib/Connection.php
@@ -167,7 +167,7 @@ class Connection extends LDAPUtility {
*/
public function __clone() {
$this->configuration = new Configuration($this->configPrefix,
- !is_null($this->configID));
+ !is_null($this->configID));
if (count($this->bindResult) !== 0 && $this->bindResult['result'] === true) {
$this->bindResult = [];
}
@@ -407,9 +407,8 @@ class Connection extends LDAPUtility {
} else {
$uuidAttributes = Access::UUID_ATTRIBUTES;
array_unshift($uuidAttributes, 'auto');
- if (!in_array($this->configuration->$effectiveSetting,
- $uuidAttributes)
- && (!is_null($this->configID))) {
+ if (!in_array($this->configuration->$effectiveSetting, $uuidAttributes)
+ && !is_null($this->configID)) {
$this->configuration->$effectiveSetting = 'auto';
$this->configuration->saveConfiguration();
$this->logger->info(
@@ -606,12 +605,18 @@ class Connection extends LDAPUtility {
if (!$isBackupHost) {
throw $e;
}
+ $this->logger->warning(
+ 'Main LDAP not reachable, connecting to backup',
+ [
+ 'app' => 'user_ldap'
+ ]
+ );
}
//if LDAP server is not reachable, try the Backup (Replica!) Server
if ($isBackupHost || $isOverrideMainServer) {
$this->doConnect($this->configuration->ldapBackupHost,
- $this->configuration->ldapBackupPort);
+ $this->configuration->ldapBackupPort);
$this->bindResult = [];
$bindStatus = $this->bind();
$error = $this->ldap->isResource($this->ldapConnectionRes) ?
@@ -649,6 +654,10 @@ class Connection extends LDAPUtility {
throw new ServerNotAvailableException('Could not disable LDAP referrals.');
}
+ if (!$this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_NETWORK_TIMEOUT, $this->configuration->ldapConnectionTimeout)) {
+ throw new ServerNotAvailableException('Could not set network timeout');
+ }
+
if ($this->configuration->ldapTLS) {
if (!$this->ldap->startTls($this->ldapConnectionRes)) {
throw new ServerNotAvailableException('Start TLS failed, when connecting to LDAP host ' . $host . '.');
@@ -681,8 +690,8 @@ class Connection extends LDAPUtility {
}
$ldapLogin = @$this->ldap->bind($cr,
- $this->configuration->ldapAgentName,
- $this->configuration->ldapAgentPassword);
+ $this->configuration->ldapAgentName,
+ $this->configuration->ldapAgentPassword);
$this->bindResult = [
'sum' => md5($this->configuration->ldapAgentName . $this->configPrefix . $this->configuration->ldapAgentPassword),
diff --git a/apps/user_ldap/lib/Group_LDAP.php b/apps/user_ldap/lib/Group_LDAP.php
index 81cb30dd25b..b32e031175f 100644
--- a/apps/user_ldap/lib/Group_LDAP.php
+++ b/apps/user_ldap/lib/Group_LDAP.php
@@ -1324,10 +1324,11 @@ class Group_LDAP extends BackendUtility implements GroupInterface, IGroupLDAP, I
if (($displayName !== false) && (count($displayName) > 0)) {
$displayName = $displayName[0];
- $this->access->connection->writeToCache($cacheKey, $displayName);
- return $displayName;
+ } else {
+ $displayName = '';
}
- return '';
+ $this->access->connection->writeToCache($cacheKey, $displayName);
+ return $displayName;
}
}