Changeset View
Changeset View
Standalone View
Standalone View
src/app/Backends/LDAP.php
Show First 20 Lines • Show All 1,025 Lines • ▼ Show 20 Lines | |||||
private static function setSharedFolderAttributes($ldap, SharedFolder $folder, &$entry) | private static function setSharedFolderAttributes($ldap, SharedFolder $folder, &$entry) | ||||
{ | { | ||||
$settings = $folder->getSettings(['acl', 'folder']); | $settings = $folder->getSettings(['acl', 'folder']); | ||||
$entry['cn'] = $folder->name; | $entry['cn'] = $folder->name; | ||||
$entry['kolabfoldertype'] = $folder->type; | $entry['kolabfoldertype'] = $folder->type; | ||||
$entry['kolabtargetfolder'] = $settings['folder'] ?? ''; | $entry['kolabtargetfolder'] = $settings['folder'] ?? ''; | ||||
$entry['acl'] = !empty($settings['acl']) ? json_decode($settings['acl'], true) : ''; | $entry['acl'] = !empty($settings['acl']) ? json_decode($settings['acl'], true) : ''; | ||||
$entry['alias'] = $folder->aliases()->pluck('alias')->all(); | |||||
} | } | ||||
/** | /** | ||||
* Set common user attributes | * Set common user attributes | ||||
*/ | */ | ||||
private static function setUserAttributes(User $user, array &$entry) | private static function setUserAttributes(User $user, array &$entry) | ||||
{ | { | ||||
$isDegraded = $user->isDegraded(true); | $isDegraded = $user->isDegraded(true); | ||||
Show All 26 Lines | private static function setUserAttributes(User $user, array &$entry) | ||||
$entry['cn'] = $cn; | $entry['cn'] = $cn; | ||||
$entry['displayname'] = $displayname; | $entry['displayname'] = $displayname; | ||||
$entry['givenname'] = $firstName; | $entry['givenname'] = $firstName; | ||||
$entry['sn'] = $lastName; | $entry['sn'] = $lastName; | ||||
$entry['userpassword'] = $user->password_ldap; | $entry['userpassword'] = $user->password_ldap; | ||||
$entry['inetuserstatus'] = $user->status; | $entry['inetuserstatus'] = $user->status; | ||||
$entry['o'] = $settings['organization']; | $entry['o'] = $settings['organization']; | ||||
$entry['mailquota'] = 0; | $entry['mailquota'] = 0; | ||||
$entry['alias'] = $user->aliases->pluck('alias')->toArray(); | $entry['alias'] = $user->aliases()->pluck('alias')->all(); | ||||
$roles = []; | $roles = []; | ||||
foreach ($user->entitlements as $entitlement) { | foreach ($user->entitlements as $entitlement) { | ||||
\Log::debug("Examining {$entitlement->sku->title}"); | \Log::debug("Examining {$entitlement->sku->title}"); | ||||
switch ($entitlement->sku->title) { | switch ($entitlement->sku->title) { | ||||
case "mailbox": | case "mailbox": | ||||
▲ Show 20 Lines • Show All 103 Lines • ▼ Show 20 Lines | |||||
* | * | ||||
* @return null|array Shared folder entry, NULL if not found | * @return null|array Shared folder entry, NULL if not found | ||||
*/ | */ | ||||
private static function getSharedFolderEntry($ldap, $email, &$dn = null) | private static function getSharedFolderEntry($ldap, $email, &$dn = null) | ||||
{ | { | ||||
$domainName = explode('@', $email, 2)[1]; | $domainName = explode('@', $email, 2)[1]; | ||||
$base_dn = self::baseDN($ldap, $domainName, 'Shared Folders'); | $base_dn = self::baseDN($ldap, $domainName, 'Shared Folders'); | ||||
$attrs = ['dn', 'cn', 'mail', 'objectclass', 'kolabtargetfolder', 'kolabfoldertype', 'acl']; | $attrs = ['dn', 'cn', 'mail', 'objectclass', 'kolabtargetfolder', 'kolabfoldertype', 'acl', 'alias']; | ||||
// For shared folders we're using search() instead of get_entry() because | // For shared folders we're using search() instead of get_entry() because | ||||
// a folder name is not constant, so e.g. on update we might have | // a folder name is not constant, so e.g. on update we might have | ||||
// the new name, but not the old one. Email address is constant. | // the new name, but not the old one. Email address is constant. | ||||
return self::searchEntry($ldap, $base_dn, "(mail=$email)", $attrs, $dn); | return self::searchEntry($ldap, $base_dn, "(mail=$email)", $attrs, $dn); | ||||
} | } | ||||
/** | /** | ||||
▲ Show 20 Lines • Show All 145 Lines • ▼ Show 20 Lines | |||||
* | * | ||||
* @param \Net_LDAP3 $ldap Ldap connection | * @param \Net_LDAP3 $ldap Ldap connection | ||||
* @param string $message Exception message | * @param string $message Exception message | ||||
* | * | ||||
* @throws \Exception | * @throws \Exception | ||||
*/ | */ | ||||
private static function throwException($ldap, string $message): void | private static function throwException($ldap, string $message): void | ||||
{ | { | ||||
if (empty(self::$ldap) && !empty($ldap)) { | if (empty(self::$ldap)) { | ||||
$ldap->close(); | $ldap->close(); | ||||
} | } | ||||
throw new \Exception($message); | throw new \Exception($message); | ||||
} | } | ||||
/** | /** | ||||
* Create a base DN string for a specified object. | * Create a base DN string for a specified object. | ||||
Show All 19 Lines |