Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F117755436
D1429.1775203412.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None
D1429.1775203412.diff
View Options
diff --git a/src/app/Backends/LDAP.php b/src/app/Backends/LDAP.php
--- a/src/app/Backends/LDAP.php
+++ b/src/app/Backends/LDAP.php
@@ -7,13 +7,41 @@
class LDAP
{
- /** @const array UserSettings used by th backend */
+ /** @const array UserSettings used by the backend */
public const USER_SETTINGS = [
'first_name',
'last_name',
'organization',
];
+ /** @var ?\Net_LDAP3 LDAP connection object */
+ protected static $ldap;
+
+
+ /**
+ * Starts a new LDAP connection that will be used by all methods
+ * until you call self::disconnect() explicitely. Normally every
+ * method uses a separate connection.
+ */
+ public static function connect(): void
+ {
+ if (empty(self::$ldap)) {
+ $config = self::getConfig('admin');
+ self::$ldap = self::initLDAP($config);
+ }
+ }
+
+ /**
+ * Close the connection created by self::connect()
+ */
+ public static function disconnect(): void
+ {
+ if (!empty(self::$ldap)) {
+ self::$ldap->close();
+ self::$ldap = null;
+ }
+ }
+
/**
* Create a domain in LDAP.
*
@@ -146,7 +174,9 @@
}
}
- $ldap->close();
+ if (empty(self::$ldap)) {
+ $ldap->close();
+ }
}
/**
@@ -196,7 +226,9 @@
$ldap->add_entry($dn, $entry);
}
- $ldap->close();
+ if (empty(self::$ldap)) {
+ $ldap->close();
+ }
}
/**
@@ -220,7 +252,9 @@
$ldap->modify_entry($ldapDomain['dn'], $oldEntry, $newEntry);
- $ldap->close();
+ if (empty(self::$ldap)) {
+ $ldap->close();
+ }
}
/**
@@ -250,7 +284,9 @@
}
}
- $ldap->close();
+ if (empty(self::$ldap)) {
+ $ldap->close();
+ }
}
/**
@@ -269,7 +305,9 @@
$ldap->delete_entry($dn);
}
- $ldap->close();
+ if (empty(self::$ldap)) {
+ $ldap->close();
+ }
}
/**
@@ -286,7 +324,9 @@
$user = self::getUserEntry($ldap, $email, $dn, true);
- $ldap->close();
+ if (empty(self::$ldap)) {
+ $ldap->close();
+ }
return $user;
}
@@ -305,14 +345,16 @@
$newEntry = $oldEntry = self::getUserEntry($ldap, $user->email, $dn, true);
- if ($oldEntry) {
- self::setUserAttributes($user, $newEntry);
+ if (!$oldEntry) {
+ return false;
+ }
- $ldap->modify_entry($dn, $oldEntry, $newEntry);
- $ldap->close();
- } else {
+ self::setUserAttributes($user, $newEntry);
+
+ $ldap->modify_entry($dn, $oldEntry, $newEntry);
+
+ if (empty(self::$ldap)) {
$ldap->close();
- return false;
}
}
@@ -321,6 +363,10 @@
*/
private static function initLDAP(array $config, string $privilege = 'admin')
{
+ if (self::$ldap) {
+ return self::$ldap;
+ }
+
$ldap = new \Net_LDAP3($config);
$ldap->connect();
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Apr 3, 8:03 AM (15 h, 29 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18823124
Default Alt Text
D1429.1775203412.diff (3 KB)
Attached To
Mode
D1429: Allow multiple ldap operations in a single connection
Attached
Detach File
Event Timeline