Completed
Pull Request — master (#7057)
by Blizzz
16:13
created
apps/user_ldap/composer/composer/autoload_classmap.php 1 patch
Spacing   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -6,55 +6,55 @@
 block discarded – undo
6 6
 $baseDir = $vendorDir;
7 7
 
8 8
 return array(
9
-    'OCA\\User_LDAP\\Access' => $baseDir . '/../lib/Access.php',
10
-    'OCA\\User_LDAP\\AppInfo\\Application' => $baseDir . '/../lib/AppInfo/Application.php',
11
-    'OCA\\User_LDAP\\BackendUtility' => $baseDir . '/../lib/BackendUtility.php',
12
-    'OCA\\User_LDAP\\Command\\CheckUser' => $baseDir . '/../lib/Command/CheckUser.php',
13
-    'OCA\\User_LDAP\\Command\\CreateEmptyConfig' => $baseDir . '/../lib/Command/CreateEmptyConfig.php',
14
-    'OCA\\User_LDAP\\Command\\DeleteConfig' => $baseDir . '/../lib/Command/DeleteConfig.php',
15
-    'OCA\\User_LDAP\\Command\\Search' => $baseDir . '/../lib/Command/Search.php',
16
-    'OCA\\User_LDAP\\Command\\SetConfig' => $baseDir . '/../lib/Command/SetConfig.php',
17
-    'OCA\\User_LDAP\\Command\\ShowConfig' => $baseDir . '/../lib/Command/ShowConfig.php',
18
-    'OCA\\User_LDAP\\Command\\ShowRemnants' => $baseDir . '/../lib/Command/ShowRemnants.php',
19
-    'OCA\\User_LDAP\\Command\\TestConfig' => $baseDir . '/../lib/Command/TestConfig.php',
20
-    'OCA\\User_LDAP\\Configuration' => $baseDir . '/../lib/Configuration.php',
21
-    'OCA\\User_LDAP\\Connection' => $baseDir . '/../lib/Connection.php',
22
-    'OCA\\User_LDAP\\Controller\\ConfigAPIController' => $baseDir . '/../lib/Controller/ConfigAPIController.php',
23
-    'OCA\\User_LDAP\\Controller\\RenewPasswordController' => $baseDir . '/../lib/Controller/RenewPasswordController.php',
24
-    'OCA\\User_LDAP\\Exceptions\\ConstraintViolationException' => $baseDir . '/../lib/Exceptions/ConstraintViolationException.php',
25
-    'OCA\\User_LDAP\\Exceptions\\NotOnLDAP' => $baseDir . '/../lib/Exceptions/NotOnLDAP.php',
26
-    'OCA\\User_LDAP\\FilesystemHelper' => $baseDir . '/../lib/FilesystemHelper.php',
27
-    'OCA\\User_LDAP\\Group_LDAP' => $baseDir . '/../lib/Group_LDAP.php',
28
-    'OCA\\User_LDAP\\Group_Proxy' => $baseDir . '/../lib/Group_Proxy.php',
29
-    'OCA\\User_LDAP\\Helper' => $baseDir . '/../lib/Helper.php',
30
-    'OCA\\User_LDAP\\ILDAPWrapper' => $baseDir . '/../lib/ILDAPWrapper.php',
31
-    'OCA\\User_LDAP\\IUserLDAP' => $baseDir . '/../lib/IUserLDAP.php',
32
-    'OCA\\User_LDAP\\Jobs\\CleanUp' => $baseDir . '/../lib/Jobs/CleanUp.php',
33
-    'OCA\\User_LDAP\\Jobs\\Sync' => $baseDir . '/../lib/Jobs/Sync.php',
34
-    'OCA\\User_LDAP\\Jobs\\UpdateGroups' => $baseDir . '/../lib/Jobs/UpdateGroups.php',
35
-    'OCA\\User_LDAP\\LDAP' => $baseDir . '/../lib/LDAP.php',
36
-    'OCA\\User_LDAP\\LDAPProvider' => $baseDir . '/../lib/LDAPProvider.php',
37
-    'OCA\\User_LDAP\\LDAPProviderFactory' => $baseDir . '/../lib/LDAPProviderFactory.php',
38
-    'OCA\\User_LDAP\\LDAPUtility' => $baseDir . '/../lib/LDAPUtility.php',
39
-    'OCA\\User_LDAP\\LogWrapper' => $baseDir . '/../lib/LogWrapper.php',
40
-    'OCA\\User_LDAP\\Mapping\\AbstractMapping' => $baseDir . '/../lib/Mapping/AbstractMapping.php',
41
-    'OCA\\User_LDAP\\Mapping\\GroupMapping' => $baseDir . '/../lib/Mapping/GroupMapping.php',
42
-    'OCA\\User_LDAP\\Mapping\\UserMapping' => $baseDir . '/../lib/Mapping/UserMapping.php',
43
-    'OCA\\User_LDAP\\Migration\\UUIDFix' => $baseDir . '/../lib/Migration/UUIDFix.php',
44
-    'OCA\\User_LDAP\\Migration\\UUIDFixGroup' => $baseDir . '/../lib/Migration/UUIDFixGroup.php',
45
-    'OCA\\User_LDAP\\Migration\\UUIDFixInsert' => $baseDir . '/../lib/Migration/UUIDFixInsert.php',
46
-    'OCA\\User_LDAP\\Migration\\UUIDFixUser' => $baseDir . '/../lib/Migration/UUIDFixUser.php',
47
-    'OCA\\User_LDAP\\Notification\\Notifier' => $baseDir . '/../lib/Notification/Notifier.php',
48
-    'OCA\\User_LDAP\\Proxy' => $baseDir . '/../lib/Proxy.php',
49
-    'OCA\\User_LDAP\\Settings\\Admin' => $baseDir . '/../lib/Settings/Admin.php',
50
-    'OCA\\User_LDAP\\Settings\\Section' => $baseDir . '/../lib/Settings/Section.php',
51
-    'OCA\\User_LDAP\\User\\DeletedUsersIndex' => $baseDir . '/../lib/User/DeletedUsersIndex.php',
52
-    'OCA\\User_LDAP\\User\\IUserTools' => $baseDir . '/../lib/User/IUserTools.php',
53
-    'OCA\\User_LDAP\\User\\Manager' => $baseDir . '/../lib/User/Manager.php',
54
-    'OCA\\User_LDAP\\User\\OfflineUser' => $baseDir . '/../lib/User/OfflineUser.php',
55
-    'OCA\\User_LDAP\\User\\User' => $baseDir . '/../lib/User/User.php',
56
-    'OCA\\User_LDAP\\User_LDAP' => $baseDir . '/../lib/User_LDAP.php',
57
-    'OCA\\User_LDAP\\User_Proxy' => $baseDir . '/../lib/User_Proxy.php',
58
-    'OCA\\User_LDAP\\Wizard' => $baseDir . '/../lib/Wizard.php',
59
-    'OCA\\User_LDAP\\WizardResult' => $baseDir . '/../lib/WizardResult.php',
9
+    'OCA\\User_LDAP\\Access' => $baseDir.'/../lib/Access.php',
10
+    'OCA\\User_LDAP\\AppInfo\\Application' => $baseDir.'/../lib/AppInfo/Application.php',
11
+    'OCA\\User_LDAP\\BackendUtility' => $baseDir.'/../lib/BackendUtility.php',
12
+    'OCA\\User_LDAP\\Command\\CheckUser' => $baseDir.'/../lib/Command/CheckUser.php',
13
+    'OCA\\User_LDAP\\Command\\CreateEmptyConfig' => $baseDir.'/../lib/Command/CreateEmptyConfig.php',
14
+    'OCA\\User_LDAP\\Command\\DeleteConfig' => $baseDir.'/../lib/Command/DeleteConfig.php',
15
+    'OCA\\User_LDAP\\Command\\Search' => $baseDir.'/../lib/Command/Search.php',
16
+    'OCA\\User_LDAP\\Command\\SetConfig' => $baseDir.'/../lib/Command/SetConfig.php',
17
+    'OCA\\User_LDAP\\Command\\ShowConfig' => $baseDir.'/../lib/Command/ShowConfig.php',
18
+    'OCA\\User_LDAP\\Command\\ShowRemnants' => $baseDir.'/../lib/Command/ShowRemnants.php',
19
+    'OCA\\User_LDAP\\Command\\TestConfig' => $baseDir.'/../lib/Command/TestConfig.php',
20
+    'OCA\\User_LDAP\\Configuration' => $baseDir.'/../lib/Configuration.php',
21
+    'OCA\\User_LDAP\\Connection' => $baseDir.'/../lib/Connection.php',
22
+    'OCA\\User_LDAP\\Controller\\ConfigAPIController' => $baseDir.'/../lib/Controller/ConfigAPIController.php',
23
+    'OCA\\User_LDAP\\Controller\\RenewPasswordController' => $baseDir.'/../lib/Controller/RenewPasswordController.php',
24
+    'OCA\\User_LDAP\\Exceptions\\ConstraintViolationException' => $baseDir.'/../lib/Exceptions/ConstraintViolationException.php',
25
+    'OCA\\User_LDAP\\Exceptions\\NotOnLDAP' => $baseDir.'/../lib/Exceptions/NotOnLDAP.php',
26
+    'OCA\\User_LDAP\\FilesystemHelper' => $baseDir.'/../lib/FilesystemHelper.php',
27
+    'OCA\\User_LDAP\\Group_LDAP' => $baseDir.'/../lib/Group_LDAP.php',
28
+    'OCA\\User_LDAP\\Group_Proxy' => $baseDir.'/../lib/Group_Proxy.php',
29
+    'OCA\\User_LDAP\\Helper' => $baseDir.'/../lib/Helper.php',
30
+    'OCA\\User_LDAP\\ILDAPWrapper' => $baseDir.'/../lib/ILDAPWrapper.php',
31
+    'OCA\\User_LDAP\\IUserLDAP' => $baseDir.'/../lib/IUserLDAP.php',
32
+    'OCA\\User_LDAP\\Jobs\\CleanUp' => $baseDir.'/../lib/Jobs/CleanUp.php',
33
+    'OCA\\User_LDAP\\Jobs\\Sync' => $baseDir.'/../lib/Jobs/Sync.php',
34
+    'OCA\\User_LDAP\\Jobs\\UpdateGroups' => $baseDir.'/../lib/Jobs/UpdateGroups.php',
35
+    'OCA\\User_LDAP\\LDAP' => $baseDir.'/../lib/LDAP.php',
36
+    'OCA\\User_LDAP\\LDAPProvider' => $baseDir.'/../lib/LDAPProvider.php',
37
+    'OCA\\User_LDAP\\LDAPProviderFactory' => $baseDir.'/../lib/LDAPProviderFactory.php',
38
+    'OCA\\User_LDAP\\LDAPUtility' => $baseDir.'/../lib/LDAPUtility.php',
39
+    'OCA\\User_LDAP\\LogWrapper' => $baseDir.'/../lib/LogWrapper.php',
40
+    'OCA\\User_LDAP\\Mapping\\AbstractMapping' => $baseDir.'/../lib/Mapping/AbstractMapping.php',
41
+    'OCA\\User_LDAP\\Mapping\\GroupMapping' => $baseDir.'/../lib/Mapping/GroupMapping.php',
42
+    'OCA\\User_LDAP\\Mapping\\UserMapping' => $baseDir.'/../lib/Mapping/UserMapping.php',
43
+    'OCA\\User_LDAP\\Migration\\UUIDFix' => $baseDir.'/../lib/Migration/UUIDFix.php',
44
+    'OCA\\User_LDAP\\Migration\\UUIDFixGroup' => $baseDir.'/../lib/Migration/UUIDFixGroup.php',
45
+    'OCA\\User_LDAP\\Migration\\UUIDFixInsert' => $baseDir.'/../lib/Migration/UUIDFixInsert.php',
46
+    'OCA\\User_LDAP\\Migration\\UUIDFixUser' => $baseDir.'/../lib/Migration/UUIDFixUser.php',
47
+    'OCA\\User_LDAP\\Notification\\Notifier' => $baseDir.'/../lib/Notification/Notifier.php',
48
+    'OCA\\User_LDAP\\Proxy' => $baseDir.'/../lib/Proxy.php',
49
+    'OCA\\User_LDAP\\Settings\\Admin' => $baseDir.'/../lib/Settings/Admin.php',
50
+    'OCA\\User_LDAP\\Settings\\Section' => $baseDir.'/../lib/Settings/Section.php',
51
+    'OCA\\User_LDAP\\User\\DeletedUsersIndex' => $baseDir.'/../lib/User/DeletedUsersIndex.php',
52
+    'OCA\\User_LDAP\\User\\IUserTools' => $baseDir.'/../lib/User/IUserTools.php',
53
+    'OCA\\User_LDAP\\User\\Manager' => $baseDir.'/../lib/User/Manager.php',
54
+    'OCA\\User_LDAP\\User\\OfflineUser' => $baseDir.'/../lib/User/OfflineUser.php',
55
+    'OCA\\User_LDAP\\User\\User' => $baseDir.'/../lib/User/User.php',
56
+    'OCA\\User_LDAP\\User_LDAP' => $baseDir.'/../lib/User_LDAP.php',
57
+    'OCA\\User_LDAP\\User_Proxy' => $baseDir.'/../lib/User_Proxy.php',
58
+    'OCA\\User_LDAP\\Wizard' => $baseDir.'/../lib/Wizard.php',
59
+    'OCA\\User_LDAP\\WizardResult' => $baseDir.'/../lib/WizardResult.php',
60 60
 );
Please login to merge, or discard this patch.
apps/user_ldap/composer/composer/autoload_static.php 1 patch
Spacing   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -6,77 +6,77 @@
 block discarded – undo
6 6
 
7 7
 class ComposerStaticInitUser_LDAP
8 8
 {
9
-    public static $prefixLengthsPsr4 = array (
9
+    public static $prefixLengthsPsr4 = array(
10 10
         'O' => 
11
-        array (
11
+        array(
12 12
             'OCA\\User_LDAP\\' => 14,
13 13
         ),
14 14
     );
15 15
 
16
-    public static $prefixDirsPsr4 = array (
16
+    public static $prefixDirsPsr4 = array(
17 17
         'OCA\\User_LDAP\\' => 
18
-        array (
19
-            0 => __DIR__ . '/..' . '/../lib',
18
+        array(
19
+            0 => __DIR__.'/..'.'/../lib',
20 20
         ),
21 21
     );
22 22
 
23
-    public static $classMap = array (
24
-        'OCA\\User_LDAP\\Access' => __DIR__ . '/..' . '/../lib/Access.php',
25
-        'OCA\\User_LDAP\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php',
26
-        'OCA\\User_LDAP\\BackendUtility' => __DIR__ . '/..' . '/../lib/BackendUtility.php',
27
-        'OCA\\User_LDAP\\Command\\CheckUser' => __DIR__ . '/..' . '/../lib/Command/CheckUser.php',
28
-        'OCA\\User_LDAP\\Command\\CreateEmptyConfig' => __DIR__ . '/..' . '/../lib/Command/CreateEmptyConfig.php',
29
-        'OCA\\User_LDAP\\Command\\DeleteConfig' => __DIR__ . '/..' . '/../lib/Command/DeleteConfig.php',
30
-        'OCA\\User_LDAP\\Command\\Search' => __DIR__ . '/..' . '/../lib/Command/Search.php',
31
-        'OCA\\User_LDAP\\Command\\SetConfig' => __DIR__ . '/..' . '/../lib/Command/SetConfig.php',
32
-        'OCA\\User_LDAP\\Command\\ShowConfig' => __DIR__ . '/..' . '/../lib/Command/ShowConfig.php',
33
-        'OCA\\User_LDAP\\Command\\ShowRemnants' => __DIR__ . '/..' . '/../lib/Command/ShowRemnants.php',
34
-        'OCA\\User_LDAP\\Command\\TestConfig' => __DIR__ . '/..' . '/../lib/Command/TestConfig.php',
35
-        'OCA\\User_LDAP\\Configuration' => __DIR__ . '/..' . '/../lib/Configuration.php',
36
-        'OCA\\User_LDAP\\Connection' => __DIR__ . '/..' . '/../lib/Connection.php',
37
-        'OCA\\User_LDAP\\Controller\\ConfigAPIController' => __DIR__ . '/..' . '/../lib/Controller/ConfigAPIController.php',
38
-        'OCA\\User_LDAP\\Controller\\RenewPasswordController' => __DIR__ . '/..' . '/../lib/Controller/RenewPasswordController.php',
39
-        'OCA\\User_LDAP\\Exceptions\\ConstraintViolationException' => __DIR__ . '/..' . '/../lib/Exceptions/ConstraintViolationException.php',
40
-        'OCA\\User_LDAP\\Exceptions\\NotOnLDAP' => __DIR__ . '/..' . '/../lib/Exceptions/NotOnLDAP.php',
41
-        'OCA\\User_LDAP\\FilesystemHelper' => __DIR__ . '/..' . '/../lib/FilesystemHelper.php',
42
-        'OCA\\User_LDAP\\Group_LDAP' => __DIR__ . '/..' . '/../lib/Group_LDAP.php',
43
-        'OCA\\User_LDAP\\Group_Proxy' => __DIR__ . '/..' . '/../lib/Group_Proxy.php',
44
-        'OCA\\User_LDAP\\Helper' => __DIR__ . '/..' . '/../lib/Helper.php',
45
-        'OCA\\User_LDAP\\ILDAPWrapper' => __DIR__ . '/..' . '/../lib/ILDAPWrapper.php',
46
-        'OCA\\User_LDAP\\IUserLDAP' => __DIR__ . '/..' . '/../lib/IUserLDAP.php',
47
-        'OCA\\User_LDAP\\Jobs\\CleanUp' => __DIR__ . '/..' . '/../lib/Jobs/CleanUp.php',
48
-        'OCA\\User_LDAP\\Jobs\\Sync' => __DIR__ . '/..' . '/../lib/Jobs/Sync.php',
49
-        'OCA\\User_LDAP\\Jobs\\UpdateGroups' => __DIR__ . '/..' . '/../lib/Jobs/UpdateGroups.php',
50
-        'OCA\\User_LDAP\\LDAP' => __DIR__ . '/..' . '/../lib/LDAP.php',
51
-        'OCA\\User_LDAP\\LDAPProvider' => __DIR__ . '/..' . '/../lib/LDAPProvider.php',
52
-        'OCA\\User_LDAP\\LDAPProviderFactory' => __DIR__ . '/..' . '/../lib/LDAPProviderFactory.php',
53
-        'OCA\\User_LDAP\\LDAPUtility' => __DIR__ . '/..' . '/../lib/LDAPUtility.php',
54
-        'OCA\\User_LDAP\\LogWrapper' => __DIR__ . '/..' . '/../lib/LogWrapper.php',
55
-        'OCA\\User_LDAP\\Mapping\\AbstractMapping' => __DIR__ . '/..' . '/../lib/Mapping/AbstractMapping.php',
56
-        'OCA\\User_LDAP\\Mapping\\GroupMapping' => __DIR__ . '/..' . '/../lib/Mapping/GroupMapping.php',
57
-        'OCA\\User_LDAP\\Mapping\\UserMapping' => __DIR__ . '/..' . '/../lib/Mapping/UserMapping.php',
58
-        'OCA\\User_LDAP\\Migration\\UUIDFix' => __DIR__ . '/..' . '/../lib/Migration/UUIDFix.php',
59
-        'OCA\\User_LDAP\\Migration\\UUIDFixGroup' => __DIR__ . '/..' . '/../lib/Migration/UUIDFixGroup.php',
60
-        'OCA\\User_LDAP\\Migration\\UUIDFixInsert' => __DIR__ . '/..' . '/../lib/Migration/UUIDFixInsert.php',
61
-        'OCA\\User_LDAP\\Migration\\UUIDFixUser' => __DIR__ . '/..' . '/../lib/Migration/UUIDFixUser.php',
62
-        'OCA\\User_LDAP\\Notification\\Notifier' => __DIR__ . '/..' . '/../lib/Notification/Notifier.php',
63
-        'OCA\\User_LDAP\\Proxy' => __DIR__ . '/..' . '/../lib/Proxy.php',
64
-        'OCA\\User_LDAP\\Settings\\Admin' => __DIR__ . '/..' . '/../lib/Settings/Admin.php',
65
-        'OCA\\User_LDAP\\Settings\\Section' => __DIR__ . '/..' . '/../lib/Settings/Section.php',
66
-        'OCA\\User_LDAP\\User\\DeletedUsersIndex' => __DIR__ . '/..' . '/../lib/User/DeletedUsersIndex.php',
67
-        'OCA\\User_LDAP\\User\\IUserTools' => __DIR__ . '/..' . '/../lib/User/IUserTools.php',
68
-        'OCA\\User_LDAP\\User\\Manager' => __DIR__ . '/..' . '/../lib/User/Manager.php',
69
-        'OCA\\User_LDAP\\User\\OfflineUser' => __DIR__ . '/..' . '/../lib/User/OfflineUser.php',
70
-        'OCA\\User_LDAP\\User\\User' => __DIR__ . '/..' . '/../lib/User/User.php',
71
-        'OCA\\User_LDAP\\User_LDAP' => __DIR__ . '/..' . '/../lib/User_LDAP.php',
72
-        'OCA\\User_LDAP\\User_Proxy' => __DIR__ . '/..' . '/../lib/User_Proxy.php',
73
-        'OCA\\User_LDAP\\Wizard' => __DIR__ . '/..' . '/../lib/Wizard.php',
74
-        'OCA\\User_LDAP\\WizardResult' => __DIR__ . '/..' . '/../lib/WizardResult.php',
23
+    public static $classMap = array(
24
+        'OCA\\User_LDAP\\Access' => __DIR__.'/..'.'/../lib/Access.php',
25
+        'OCA\\User_LDAP\\AppInfo\\Application' => __DIR__.'/..'.'/../lib/AppInfo/Application.php',
26
+        'OCA\\User_LDAP\\BackendUtility' => __DIR__.'/..'.'/../lib/BackendUtility.php',
27
+        'OCA\\User_LDAP\\Command\\CheckUser' => __DIR__.'/..'.'/../lib/Command/CheckUser.php',
28
+        'OCA\\User_LDAP\\Command\\CreateEmptyConfig' => __DIR__.'/..'.'/../lib/Command/CreateEmptyConfig.php',
29
+        'OCA\\User_LDAP\\Command\\DeleteConfig' => __DIR__.'/..'.'/../lib/Command/DeleteConfig.php',
30
+        'OCA\\User_LDAP\\Command\\Search' => __DIR__.'/..'.'/../lib/Command/Search.php',
31
+        'OCA\\User_LDAP\\Command\\SetConfig' => __DIR__.'/..'.'/../lib/Command/SetConfig.php',
32
+        'OCA\\User_LDAP\\Command\\ShowConfig' => __DIR__.'/..'.'/../lib/Command/ShowConfig.php',
33
+        'OCA\\User_LDAP\\Command\\ShowRemnants' => __DIR__.'/..'.'/../lib/Command/ShowRemnants.php',
34
+        'OCA\\User_LDAP\\Command\\TestConfig' => __DIR__.'/..'.'/../lib/Command/TestConfig.php',
35
+        'OCA\\User_LDAP\\Configuration' => __DIR__.'/..'.'/../lib/Configuration.php',
36
+        'OCA\\User_LDAP\\Connection' => __DIR__.'/..'.'/../lib/Connection.php',
37
+        'OCA\\User_LDAP\\Controller\\ConfigAPIController' => __DIR__.'/..'.'/../lib/Controller/ConfigAPIController.php',
38
+        'OCA\\User_LDAP\\Controller\\RenewPasswordController' => __DIR__.'/..'.'/../lib/Controller/RenewPasswordController.php',
39
+        'OCA\\User_LDAP\\Exceptions\\ConstraintViolationException' => __DIR__.'/..'.'/../lib/Exceptions/ConstraintViolationException.php',
40
+        'OCA\\User_LDAP\\Exceptions\\NotOnLDAP' => __DIR__.'/..'.'/../lib/Exceptions/NotOnLDAP.php',
41
+        'OCA\\User_LDAP\\FilesystemHelper' => __DIR__.'/..'.'/../lib/FilesystemHelper.php',
42
+        'OCA\\User_LDAP\\Group_LDAP' => __DIR__.'/..'.'/../lib/Group_LDAP.php',
43
+        'OCA\\User_LDAP\\Group_Proxy' => __DIR__.'/..'.'/../lib/Group_Proxy.php',
44
+        'OCA\\User_LDAP\\Helper' => __DIR__.'/..'.'/../lib/Helper.php',
45
+        'OCA\\User_LDAP\\ILDAPWrapper' => __DIR__.'/..'.'/../lib/ILDAPWrapper.php',
46
+        'OCA\\User_LDAP\\IUserLDAP' => __DIR__.'/..'.'/../lib/IUserLDAP.php',
47
+        'OCA\\User_LDAP\\Jobs\\CleanUp' => __DIR__.'/..'.'/../lib/Jobs/CleanUp.php',
48
+        'OCA\\User_LDAP\\Jobs\\Sync' => __DIR__.'/..'.'/../lib/Jobs/Sync.php',
49
+        'OCA\\User_LDAP\\Jobs\\UpdateGroups' => __DIR__.'/..'.'/../lib/Jobs/UpdateGroups.php',
50
+        'OCA\\User_LDAP\\LDAP' => __DIR__.'/..'.'/../lib/LDAP.php',
51
+        'OCA\\User_LDAP\\LDAPProvider' => __DIR__.'/..'.'/../lib/LDAPProvider.php',
52
+        'OCA\\User_LDAP\\LDAPProviderFactory' => __DIR__.'/..'.'/../lib/LDAPProviderFactory.php',
53
+        'OCA\\User_LDAP\\LDAPUtility' => __DIR__.'/..'.'/../lib/LDAPUtility.php',
54
+        'OCA\\User_LDAP\\LogWrapper' => __DIR__.'/..'.'/../lib/LogWrapper.php',
55
+        'OCA\\User_LDAP\\Mapping\\AbstractMapping' => __DIR__.'/..'.'/../lib/Mapping/AbstractMapping.php',
56
+        'OCA\\User_LDAP\\Mapping\\GroupMapping' => __DIR__.'/..'.'/../lib/Mapping/GroupMapping.php',
57
+        'OCA\\User_LDAP\\Mapping\\UserMapping' => __DIR__.'/..'.'/../lib/Mapping/UserMapping.php',
58
+        'OCA\\User_LDAP\\Migration\\UUIDFix' => __DIR__.'/..'.'/../lib/Migration/UUIDFix.php',
59
+        'OCA\\User_LDAP\\Migration\\UUIDFixGroup' => __DIR__.'/..'.'/../lib/Migration/UUIDFixGroup.php',
60
+        'OCA\\User_LDAP\\Migration\\UUIDFixInsert' => __DIR__.'/..'.'/../lib/Migration/UUIDFixInsert.php',
61
+        'OCA\\User_LDAP\\Migration\\UUIDFixUser' => __DIR__.'/..'.'/../lib/Migration/UUIDFixUser.php',
62
+        'OCA\\User_LDAP\\Notification\\Notifier' => __DIR__.'/..'.'/../lib/Notification/Notifier.php',
63
+        'OCA\\User_LDAP\\Proxy' => __DIR__.'/..'.'/../lib/Proxy.php',
64
+        'OCA\\User_LDAP\\Settings\\Admin' => __DIR__.'/..'.'/../lib/Settings/Admin.php',
65
+        'OCA\\User_LDAP\\Settings\\Section' => __DIR__.'/..'.'/../lib/Settings/Section.php',
66
+        'OCA\\User_LDAP\\User\\DeletedUsersIndex' => __DIR__.'/..'.'/../lib/User/DeletedUsersIndex.php',
67
+        'OCA\\User_LDAP\\User\\IUserTools' => __DIR__.'/..'.'/../lib/User/IUserTools.php',
68
+        'OCA\\User_LDAP\\User\\Manager' => __DIR__.'/..'.'/../lib/User/Manager.php',
69
+        'OCA\\User_LDAP\\User\\OfflineUser' => __DIR__.'/..'.'/../lib/User/OfflineUser.php',
70
+        'OCA\\User_LDAP\\User\\User' => __DIR__.'/..'.'/../lib/User/User.php',
71
+        'OCA\\User_LDAP\\User_LDAP' => __DIR__.'/..'.'/../lib/User_LDAP.php',
72
+        'OCA\\User_LDAP\\User_Proxy' => __DIR__.'/..'.'/../lib/User_Proxy.php',
73
+        'OCA\\User_LDAP\\Wizard' => __DIR__.'/..'.'/../lib/Wizard.php',
74
+        'OCA\\User_LDAP\\WizardResult' => __DIR__.'/..'.'/../lib/WizardResult.php',
75 75
     );
76 76
 
77 77
     public static function getInitializer(ClassLoader $loader)
78 78
     {
79
-        return \Closure::bind(function () use ($loader) {
79
+        return \Closure::bind(function() use ($loader) {
80 80
             $loader->prefixLengthsPsr4 = ComposerStaticInitUser_LDAP::$prefixLengthsPsr4;
81 81
             $loader->prefixDirsPsr4 = ComposerStaticInitUser_LDAP::$prefixDirsPsr4;
82 82
             $loader->classMap = ComposerStaticInitUser_LDAP::$classMap;
Please login to merge, or discard this patch.
apps/user_ldap/lib/Proxy.php 1 patch
Indentation   +166 added lines, -166 removed lines patch added patch discarded remove patch
@@ -35,170 +35,170 @@
 block discarded – undo
35 35
 use OCA\User_LDAP\User\Manager;
36 36
 
37 37
 abstract class Proxy {
38
-	static private $accesses = array();
39
-	private $ldap = null;
40
-
41
-	/** @var \OCP\ICache|null */
42
-	private $cache;
43
-
44
-	/**
45
-	 * @param ILDAPWrapper $ldap
46
-	 */
47
-	public function __construct(ILDAPWrapper $ldap) {
48
-		$this->ldap = $ldap;
49
-		$memcache = \OC::$server->getMemCacheFactory();
50
-		if($memcache->isAvailable()) {
51
-			$this->cache = $memcache->create();
52
-		}
53
-	}
54
-
55
-	/**
56
-	 * @param string $configPrefix
57
-	 */
58
-	private function addAccess($configPrefix) {
59
-		static $ocConfig;
60
-		static $fs;
61
-		static $log;
62
-		static $avatarM;
63
-		static $userMap;
64
-		static $groupMap;
65
-		static $db;
66
-		static $coreUserManager;
67
-		static $coreNotificationManager;
68
-		if($fs === null) {
69
-			$ocConfig = \OC::$server->getConfig();
70
-			$fs       = new FilesystemHelper();
71
-			$log      = new LogWrapper();
72
-			$avatarM  = \OC::$server->getAvatarManager();
73
-			$db       = \OC::$server->getDatabaseConnection();
74
-			$userMap  = new UserMapping($db);
75
-			$groupMap = new GroupMapping($db);
76
-			$coreUserManager = \OC::$server->getUserManager();
77
-			$coreNotificationManager = \OC::$server->getNotificationManager();
78
-		}
79
-		$userManager =
80
-			new Manager($ocConfig, $fs, $log, $avatarM, new \OCP\Image(), $db,
81
-				$coreUserManager, $coreNotificationManager);
82
-		$connector = new Connection($this->ldap, $configPrefix);
83
-		$access = new Access($connector, $this->ldap, $userManager, new Helper(\OC::$server->getConfig()), \OC::$server);
84
-		$access->setUserMapper($userMap);
85
-		$access->setGroupMapper($groupMap);
86
-		self::$accesses[$configPrefix] = $access;
87
-	}
88
-
89
-	/**
90
-	 * @param string $configPrefix
91
-	 * @return mixed
92
-	 */
93
-	protected function getAccess($configPrefix) {
94
-		if(!isset(self::$accesses[$configPrefix])) {
95
-			$this->addAccess($configPrefix);
96
-		}
97
-		return self::$accesses[$configPrefix];
98
-	}
99
-
100
-	/**
101
-	 * @param string $uid
102
-	 * @return string
103
-	 */
104
-	protected function getUserCacheKey($uid) {
105
-		return 'user-'.$uid.'-lastSeenOn';
106
-	}
107
-
108
-	/**
109
-	 * @param string $gid
110
-	 * @return string
111
-	 */
112
-	protected function getGroupCacheKey($gid) {
113
-		return 'group-'.$gid.'-lastSeenOn';
114
-	}
115
-
116
-	/**
117
-	 * @param string $id
118
-	 * @param string $method
119
-	 * @param array $parameters
120
-	 * @param bool $passOnWhen
121
-	 * @return mixed
122
-	 */
123
-	abstract protected function callOnLastSeenOn($id, $method, $parameters, $passOnWhen);
124
-
125
-	/**
126
-	 * @param string $id
127
-	 * @param string $method
128
-	 * @param array $parameters
129
-	 * @return mixed
130
-	 */
131
-	abstract protected function walkBackends($id, $method, $parameters);
132
-
133
-	/**
134
-	 * @param string $id
135
-	 * @return Access
136
-	 */
137
-	abstract public function getLDAPAccess($id);
138
-
139
-	/**
140
-	 * Takes care of the request to the User backend
141
-	 * @param string $id
142
-	 * @param string $method string, the method of the user backend that shall be called
143
-	 * @param array $parameters an array of parameters to be passed
144
-	 * @param bool $passOnWhen
145
-	 * @return mixed, the result of the specified method
146
-	 */
147
-	protected function handleRequest($id, $method, $parameters, $passOnWhen = false) {
148
-		$result = $this->callOnLastSeenOn($id,  $method, $parameters, $passOnWhen);
149
-		if($result === $passOnWhen) {
150
-			$result = $this->walkBackends($id, $method, $parameters);
151
-		}
152
-		return $result;
153
-	}
154
-
155
-	/**
156
-	 * @param string|null $key
157
-	 * @return string
158
-	 */
159
-	private function getCacheKey($key) {
160
-		$prefix = 'LDAP-Proxy-';
161
-		if($key === null) {
162
-			return $prefix;
163
-		}
164
-		return $prefix.md5($key);
165
-	}
166
-
167
-	/**
168
-	 * @param string $key
169
-	 * @return mixed|null
170
-	 */
171
-	public function getFromCache($key) {
172
-		if($this->cache === null) {
173
-			return null;
174
-		}
175
-
176
-		$key = $this->getCacheKey($key);
177
-		$value = $this->cache->get($key);
178
-		if ($value === null) {
179
-			return null;
180
-		}
181
-
182
-		return json_decode(base64_decode($value));
183
-	}
184
-
185
-	/**
186
-	 * @param string $key
187
-	 * @param mixed $value
188
-	 */
189
-	public function writeToCache($key, $value) {
190
-		if($this->cache === null) {
191
-			return;
192
-		}
193
-		$key   = $this->getCacheKey($key);
194
-		$value = base64_encode(json_encode($value));
195
-		$this->cache->set($key, $value, 2592000);
196
-	}
197
-
198
-	public function clearCache() {
199
-		if($this->cache === null) {
200
-			return;
201
-		}
202
-		$this->cache->clear($this->getCacheKey(null));
203
-	}
38
+    static private $accesses = array();
39
+    private $ldap = null;
40
+
41
+    /** @var \OCP\ICache|null */
42
+    private $cache;
43
+
44
+    /**
45
+     * @param ILDAPWrapper $ldap
46
+     */
47
+    public function __construct(ILDAPWrapper $ldap) {
48
+        $this->ldap = $ldap;
49
+        $memcache = \OC::$server->getMemCacheFactory();
50
+        if($memcache->isAvailable()) {
51
+            $this->cache = $memcache->create();
52
+        }
53
+    }
54
+
55
+    /**
56
+     * @param string $configPrefix
57
+     */
58
+    private function addAccess($configPrefix) {
59
+        static $ocConfig;
60
+        static $fs;
61
+        static $log;
62
+        static $avatarM;
63
+        static $userMap;
64
+        static $groupMap;
65
+        static $db;
66
+        static $coreUserManager;
67
+        static $coreNotificationManager;
68
+        if($fs === null) {
69
+            $ocConfig = \OC::$server->getConfig();
70
+            $fs       = new FilesystemHelper();
71
+            $log      = new LogWrapper();
72
+            $avatarM  = \OC::$server->getAvatarManager();
73
+            $db       = \OC::$server->getDatabaseConnection();
74
+            $userMap  = new UserMapping($db);
75
+            $groupMap = new GroupMapping($db);
76
+            $coreUserManager = \OC::$server->getUserManager();
77
+            $coreNotificationManager = \OC::$server->getNotificationManager();
78
+        }
79
+        $userManager =
80
+            new Manager($ocConfig, $fs, $log, $avatarM, new \OCP\Image(), $db,
81
+                $coreUserManager, $coreNotificationManager);
82
+        $connector = new Connection($this->ldap, $configPrefix);
83
+        $access = new Access($connector, $this->ldap, $userManager, new Helper(\OC::$server->getConfig()), \OC::$server);
84
+        $access->setUserMapper($userMap);
85
+        $access->setGroupMapper($groupMap);
86
+        self::$accesses[$configPrefix] = $access;
87
+    }
88
+
89
+    /**
90
+     * @param string $configPrefix
91
+     * @return mixed
92
+     */
93
+    protected function getAccess($configPrefix) {
94
+        if(!isset(self::$accesses[$configPrefix])) {
95
+            $this->addAccess($configPrefix);
96
+        }
97
+        return self::$accesses[$configPrefix];
98
+    }
99
+
100
+    /**
101
+     * @param string $uid
102
+     * @return string
103
+     */
104
+    protected function getUserCacheKey($uid) {
105
+        return 'user-'.$uid.'-lastSeenOn';
106
+    }
107
+
108
+    /**
109
+     * @param string $gid
110
+     * @return string
111
+     */
112
+    protected function getGroupCacheKey($gid) {
113
+        return 'group-'.$gid.'-lastSeenOn';
114
+    }
115
+
116
+    /**
117
+     * @param string $id
118
+     * @param string $method
119
+     * @param array $parameters
120
+     * @param bool $passOnWhen
121
+     * @return mixed
122
+     */
123
+    abstract protected function callOnLastSeenOn($id, $method, $parameters, $passOnWhen);
124
+
125
+    /**
126
+     * @param string $id
127
+     * @param string $method
128
+     * @param array $parameters
129
+     * @return mixed
130
+     */
131
+    abstract protected function walkBackends($id, $method, $parameters);
132
+
133
+    /**
134
+     * @param string $id
135
+     * @return Access
136
+     */
137
+    abstract public function getLDAPAccess($id);
138
+
139
+    /**
140
+     * Takes care of the request to the User backend
141
+     * @param string $id
142
+     * @param string $method string, the method of the user backend that shall be called
143
+     * @param array $parameters an array of parameters to be passed
144
+     * @param bool $passOnWhen
145
+     * @return mixed, the result of the specified method
146
+     */
147
+    protected function handleRequest($id, $method, $parameters, $passOnWhen = false) {
148
+        $result = $this->callOnLastSeenOn($id,  $method, $parameters, $passOnWhen);
149
+        if($result === $passOnWhen) {
150
+            $result = $this->walkBackends($id, $method, $parameters);
151
+        }
152
+        return $result;
153
+    }
154
+
155
+    /**
156
+     * @param string|null $key
157
+     * @return string
158
+     */
159
+    private function getCacheKey($key) {
160
+        $prefix = 'LDAP-Proxy-';
161
+        if($key === null) {
162
+            return $prefix;
163
+        }
164
+        return $prefix.md5($key);
165
+    }
166
+
167
+    /**
168
+     * @param string $key
169
+     * @return mixed|null
170
+     */
171
+    public function getFromCache($key) {
172
+        if($this->cache === null) {
173
+            return null;
174
+        }
175
+
176
+        $key = $this->getCacheKey($key);
177
+        $value = $this->cache->get($key);
178
+        if ($value === null) {
179
+            return null;
180
+        }
181
+
182
+        return json_decode(base64_decode($value));
183
+    }
184
+
185
+    /**
186
+     * @param string $key
187
+     * @param mixed $value
188
+     */
189
+    public function writeToCache($key, $value) {
190
+        if($this->cache === null) {
191
+            return;
192
+        }
193
+        $key   = $this->getCacheKey($key);
194
+        $value = base64_encode(json_encode($value));
195
+        $this->cache->set($key, $value, 2592000);
196
+    }
197
+
198
+    public function clearCache() {
199
+        if($this->cache === null) {
200
+            return;
201
+        }
202
+        $this->cache->clear($this->getCacheKey(null));
203
+    }
204 204
 }
Please login to merge, or discard this patch.
apps/user_ldap/lib/User_LDAP.php 1 patch
Indentation   +511 added lines, -511 removed lines patch added patch discarded remove patch
@@ -47,518 +47,518 @@
 block discarded – undo
47 47
 use OCP\Util;
48 48
 
49 49
 class User_LDAP extends BackendUtility implements \OCP\IUserBackend, \OCP\UserInterface, IUserLDAP {
50
-	/** @var \OCP\IConfig */
51
-	protected $ocConfig;
52
-
53
-	/** @var INotificationManager */
54
-	protected $notificationManager;
55
-
56
-	/** @var string */
57
-	protected $currentUserInDeletionProcess;
58
-
59
-	/**
60
-	 * @param Access $access
61
-	 * @param \OCP\IConfig $ocConfig
62
-	 * @param \OCP\Notification\IManager $notificationManager
63
-	 * @param IUserSession $userSession
64
-	 */
65
-	public function __construct(Access $access, IConfig $ocConfig, INotificationManager $notificationManager, IUserSession $userSession) {
66
-		parent::__construct($access);
67
-		$this->ocConfig = $ocConfig;
68
-		$this->notificationManager = $notificationManager;
69
-		$this->registerHooks($userSession);
70
-	}
71
-
72
-	protected function registerHooks(IUserSession $userSession) {
73
-		$userSession->listen('\OC\User', 'preDelete', [$this, 'preDeleteUser']);
74
-		$userSession->listen('\OC\User', 'postDelete', [$this, 'postDeleteUser']);
75
-	}
76
-
77
-	public function preDeleteUser(IUser $user) {
78
-		$this->currentUserInDeletionProcess = $user->getUID();
79
-	}
80
-
81
-	public function postDeleteUser() {
82
-		$this->currentUserInDeletionProcess = null;
83
-	}
84
-
85
-	/**
86
-	 * checks whether the user is allowed to change his avatar in Nextcloud
87
-	 * @param string $uid the Nextcloud user name
88
-	 * @return boolean either the user can or cannot
89
-	 */
90
-	public function canChangeAvatar($uid) {
91
-		$user = $this->access->userManager->get($uid);
92
-		if(!$user instanceof User) {
93
-			return false;
94
-		}
95
-		if($user->getAvatarImage() === false) {
96
-			return true;
97
-		}
98
-
99
-		return false;
100
-	}
101
-
102
-	/**
103
-	 * returns the username for the given login name, if available
104
-	 *
105
-	 * @param string $loginName
106
-	 * @return string|false
107
-	 */
108
-	public function loginName2UserName($loginName) {
109
-		$cacheKey = 'loginName2UserName-'.$loginName;
110
-		$username = $this->access->connection->getFromCache($cacheKey);
111
-		if(!is_null($username)) {
112
-			return $username;
113
-		}
114
-
115
-		try {
116
-			$ldapRecord = $this->getLDAPUserByLoginName($loginName);
117
-			$user = $this->access->userManager->get($ldapRecord['dn'][0]);
118
-			if($user instanceof OfflineUser) {
119
-				// this path is not really possible, however get() is documented
120
-				// to return User or OfflineUser so we are very defensive here.
121
-				$this->access->connection->writeToCache($cacheKey, false);
122
-				return false;
123
-			}
124
-			$username = $user->getUsername();
125
-			$this->access->connection->writeToCache($cacheKey, $username);
126
-			return $username;
127
-		} catch (NotOnLDAP $e) {
128
-			$this->access->connection->writeToCache($cacheKey, false);
129
-			return false;
130
-		}
131
-	}
50
+    /** @var \OCP\IConfig */
51
+    protected $ocConfig;
52
+
53
+    /** @var INotificationManager */
54
+    protected $notificationManager;
55
+
56
+    /** @var string */
57
+    protected $currentUserInDeletionProcess;
58
+
59
+    /**
60
+     * @param Access $access
61
+     * @param \OCP\IConfig $ocConfig
62
+     * @param \OCP\Notification\IManager $notificationManager
63
+     * @param IUserSession $userSession
64
+     */
65
+    public function __construct(Access $access, IConfig $ocConfig, INotificationManager $notificationManager, IUserSession $userSession) {
66
+        parent::__construct($access);
67
+        $this->ocConfig = $ocConfig;
68
+        $this->notificationManager = $notificationManager;
69
+        $this->registerHooks($userSession);
70
+    }
71
+
72
+    protected function registerHooks(IUserSession $userSession) {
73
+        $userSession->listen('\OC\User', 'preDelete', [$this, 'preDeleteUser']);
74
+        $userSession->listen('\OC\User', 'postDelete', [$this, 'postDeleteUser']);
75
+    }
76
+
77
+    public function preDeleteUser(IUser $user) {
78
+        $this->currentUserInDeletionProcess = $user->getUID();
79
+    }
80
+
81
+    public function postDeleteUser() {
82
+        $this->currentUserInDeletionProcess = null;
83
+    }
84
+
85
+    /**
86
+     * checks whether the user is allowed to change his avatar in Nextcloud
87
+     * @param string $uid the Nextcloud user name
88
+     * @return boolean either the user can or cannot
89
+     */
90
+    public function canChangeAvatar($uid) {
91
+        $user = $this->access->userManager->get($uid);
92
+        if(!$user instanceof User) {
93
+            return false;
94
+        }
95
+        if($user->getAvatarImage() === false) {
96
+            return true;
97
+        }
98
+
99
+        return false;
100
+    }
101
+
102
+    /**
103
+     * returns the username for the given login name, if available
104
+     *
105
+     * @param string $loginName
106
+     * @return string|false
107
+     */
108
+    public function loginName2UserName($loginName) {
109
+        $cacheKey = 'loginName2UserName-'.$loginName;
110
+        $username = $this->access->connection->getFromCache($cacheKey);
111
+        if(!is_null($username)) {
112
+            return $username;
113
+        }
114
+
115
+        try {
116
+            $ldapRecord = $this->getLDAPUserByLoginName($loginName);
117
+            $user = $this->access->userManager->get($ldapRecord['dn'][0]);
118
+            if($user instanceof OfflineUser) {
119
+                // this path is not really possible, however get() is documented
120
+                // to return User or OfflineUser so we are very defensive here.
121
+                $this->access->connection->writeToCache($cacheKey, false);
122
+                return false;
123
+            }
124
+            $username = $user->getUsername();
125
+            $this->access->connection->writeToCache($cacheKey, $username);
126
+            return $username;
127
+        } catch (NotOnLDAP $e) {
128
+            $this->access->connection->writeToCache($cacheKey, false);
129
+            return false;
130
+        }
131
+    }
132 132
 	
133
-	/**
134
-	 * returns the username for the given LDAP DN, if available
135
-	 *
136
-	 * @param string $dn
137
-	 * @return string|false with the username
138
-	 */
139
-	public function dn2UserName($dn) {
140
-		return $this->access->dn2username($dn);
141
-	}
142
-
143
-	/**
144
-	 * returns an LDAP record based on a given login name
145
-	 *
146
-	 * @param string $loginName
147
-	 * @return array
148
-	 * @throws NotOnLDAP
149
-	 */
150
-	public function getLDAPUserByLoginName($loginName) {
151
-		//find out dn of the user name
152
-		$attrs = $this->access->userManager->getAttributes();
153
-		$users = $this->access->fetchUsersByLoginName($loginName, $attrs);
154
-		if(count($users) < 1) {
155
-			throw new NotOnLDAP('No user available for the given login name on ' .
156
-				$this->access->connection->ldapHost . ':' . $this->access->connection->ldapPort);
157
-		}
158
-		return $users[0];
159
-	}
160
-
161
-	/**
162
-	 * Check if the password is correct without logging in the user
163
-	 *
164
-	 * @param string $uid The username
165
-	 * @param string $password The password
166
-	 * @return false|string
167
-	 */
168
-	public function checkPassword($uid, $password) {
169
-		try {
170
-			$ldapRecord = $this->getLDAPUserByLoginName($uid);
171
-		} catch(NotOnLDAP $e) {
172
-			if($this->ocConfig->getSystemValue('loglevel', Util::WARN) === Util::DEBUG) {
173
-				\OC::$server->getLogger()->logException($e, ['app' => 'user_ldap']);
174
-			}
175
-			return false;
176
-		}
177
-		$dn = $ldapRecord['dn'][0];
178
-		$user = $this->access->userManager->get($dn);
179
-
180
-		if(!$user instanceof User) {
181
-			Util::writeLog('user_ldap',
182
-				'LDAP Login: Could not get user object for DN ' . $dn .
183
-				'. Maybe the LDAP entry has no set display name attribute?',
184
-				Util::WARN);
185
-			return false;
186
-		}
187
-		if($user->getUsername() !== false) {
188
-			//are the credentials OK?
189
-			if(!$this->access->areCredentialsValid($dn, $password)) {
190
-				return false;
191
-			}
192
-
193
-			$this->access->cacheUserExists($user->getUsername());
194
-			$user->processAttributes($ldapRecord);
195
-			$user->markLogin();
196
-
197
-			return $user->getUsername();
198
-		}
199
-
200
-		return false;
201
-	}
202
-
203
-	/**
204
-	 * Set password
205
-	 * @param string $uid The username
206
-	 * @param string $password The new password
207
-	 * @return bool
208
-	 */
209
-	public function setPassword($uid, $password) {
210
-		$user = $this->access->userManager->get($uid);
211
-
212
-		if(!$user instanceof User) {
213
-			throw new \Exception('LDAP setPassword: Could not get user object for uid ' . $uid .
214
-				'. Maybe the LDAP entry has no set display name attribute?');
215
-		}
216
-		if($user->getUsername() !== false && $this->access->setPassword($user->getDN(), $password)) {
217
-			$ldapDefaultPPolicyDN = $this->access->connection->ldapDefaultPPolicyDN;
218
-			$turnOnPasswordChange = $this->access->connection->turnOnPasswordChange;
219
-			if (!empty($ldapDefaultPPolicyDN) && (intval($turnOnPasswordChange) === 1)) {
220
-				//remove last password expiry warning if any
221
-				$notification = $this->notificationManager->createNotification();
222
-				$notification->setApp('user_ldap')
223
-					->setUser($uid)
224
-					->setObject('pwd_exp_warn', $uid)
225
-				;
226
-				$this->notificationManager->markProcessed($notification);
227
-			}
228
-			return true;
229
-		}
230
-
231
-		return false;
232
-	}
233
-
234
-	/**
235
-	 * Get a list of all users
236
-	 *
237
-	 * @param string $search
238
-	 * @param integer $limit
239
-	 * @param integer $offset
240
-	 * @return string[] an array of all uids
241
-	 */
242
-	public function getUsers($search = '', $limit = 10, $offset = 0) {
243
-		$search = $this->access->escapeFilterPart($search, true);
244
-		$cachekey = 'getUsers-'.$search.'-'.$limit.'-'.$offset;
245
-
246
-		//check if users are cached, if so return
247
-		$ldap_users = $this->access->connection->getFromCache($cachekey);
248
-		if(!is_null($ldap_users)) {
249
-			return $ldap_users;
250
-		}
251
-
252
-		// if we'd pass -1 to LDAP search, we'd end up in a Protocol
253
-		// error. With a limit of 0, we get 0 results. So we pass null.
254
-		if($limit <= 0) {
255
-			$limit = null;
256
-		}
257
-		$filter = $this->access->combineFilterWithAnd(array(
258
-			$this->access->connection->ldapUserFilter,
259
-			$this->access->connection->ldapUserDisplayName . '=*',
260
-			$this->access->getFilterPartForUserSearch($search)
261
-		));
262
-
263
-		Util::writeLog('user_ldap',
264
-			'getUsers: Options: search '.$search.' limit '.$limit.' offset '.$offset.' Filter: '.$filter,
265
-			Util::DEBUG);
266
-		//do the search and translate results to Nextcloud names
267
-		$ldap_users = $this->access->fetchListOfUsers(
268
-			$filter,
269
-			$this->access->userManager->getAttributes(true),
270
-			$limit, $offset);
271
-		$ldap_users = $this->access->nextcloudUserNames($ldap_users);
272
-		Util::writeLog('user_ldap', 'getUsers: '.count($ldap_users). ' Users found', Util::DEBUG);
273
-
274
-		$this->access->connection->writeToCache($cachekey, $ldap_users);
275
-		return $ldap_users;
276
-	}
277
-
278
-	/**
279
-	 * checks whether a user is still available on LDAP
280
-	 *
281
-	 * @param string|\OCA\User_LDAP\User\User $user either the Nextcloud user
282
-	 * name or an instance of that user
283
-	 * @return bool
284
-	 * @throws \Exception
285
-	 * @throws \OC\ServerNotAvailableException
286
-	 */
287
-	public function userExistsOnLDAP($user) {
288
-		if(is_string($user)) {
289
-			$user = $this->access->userManager->get($user);
290
-		}
291
-		if(is_null($user)) {
292
-			return false;
293
-		}
294
-
295
-		$dn = $user->getDN();
296
-		//check if user really still exists by reading its entry
297
-		if(!is_array($this->access->readAttribute($dn, '', $this->access->connection->ldapUserFilter))) {
298
-			$lcr = $this->access->connection->getConnectionResource();
299
-			if(is_null($lcr)) {
300
-				throw new \Exception('No LDAP Connection to server ' . $this->access->connection->ldapHost);
301
-			}
302
-
303
-			try {
304
-				$uuid = $this->access->getUserMapper()->getUUIDByDN($dn);
305
-				if(!$uuid) {
306
-					return false;
307
-				}
308
-				$newDn = $this->access->getUserDnByUuid($uuid);
309
-				//check if renamed user is still valid by reapplying the ldap filter
310
-				if(!is_array($this->access->readAttribute($newDn, '', $this->access->connection->ldapUserFilter))) {
311
-					return false;
312
-				}
313
-				$this->access->getUserMapper()->setDNbyUUID($newDn, $uuid);
314
-				return true;
315
-			} catch (\Exception $e) {
316
-				return false;
317
-			}
318
-		}
319
-
320
-		if($user instanceof OfflineUser) {
321
-			$user->unmark();
322
-		}
323
-
324
-		return true;
325
-	}
326
-
327
-	/**
328
-	 * check if a user exists
329
-	 * @param string $uid the username
330
-	 * @return boolean
331
-	 * @throws \Exception when connection could not be established
332
-	 */
333
-	public function userExists($uid) {
334
-		$userExists = $this->access->connection->getFromCache('userExists'.$uid);
335
-		if(!is_null($userExists)) {
336
-			return (bool)$userExists;
337
-		}
338
-		//getting dn, if false the user does not exist. If dn, he may be mapped only, requires more checking.
339
-		$user = $this->access->userManager->get($uid);
340
-
341
-		if(is_null($user)) {
342
-			Util::writeLog('user_ldap', 'No DN found for '.$uid.' on '.
343
-				$this->access->connection->ldapHost, Util::DEBUG);
344
-			$this->access->connection->writeToCache('userExists'.$uid, false);
345
-			return false;
346
-		} else if($user instanceof OfflineUser) {
347
-			//express check for users marked as deleted. Returning true is
348
-			//necessary for cleanup
349
-			return true;
350
-		}
351
-
352
-		$result = $this->userExistsOnLDAP($user);
353
-		$this->access->connection->writeToCache('userExists'.$uid, $result);
354
-		if($result === true) {
355
-			$user->update();
356
-		}
357
-		return $result;
358
-	}
359
-
360
-	/**
361
-	* returns whether a user was deleted in LDAP
362
-	*
363
-	* @param string $uid The username of the user to delete
364
-	* @return bool
365
-	*/
366
-	public function deleteUser($uid) {
367
-		$marked = $this->ocConfig->getUserValue($uid, 'user_ldap', 'isDeleted', 0);
368
-		if(intval($marked) === 0) {
369
-			\OC::$server->getLogger()->notice(
370
-				'User '.$uid . ' is not marked as deleted, not cleaning up.',
371
-				array('app' => 'user_ldap'));
372
-			return false;
373
-		}
374
-		\OC::$server->getLogger()->info('Cleaning up after user ' . $uid,
375
-			array('app' => 'user_ldap'));
376
-
377
-		$this->access->getUserMapper()->unmap($uid);
378
-		$this->access->userManager->invalidate($uid);
379
-		return true;
380
-	}
381
-
382
-	/**
383
-	 * get the user's home directory
384
-	 *
385
-	 * @param string $uid the username
386
-	 * @return bool|string
387
-	 * @throws NoUserException
388
-	 * @throws \Exception
389
-	 */
390
-	public function getHome($uid) {
391
-		// user Exists check required as it is not done in user proxy!
392
-		if(!$this->userExists($uid)) {
393
-			return false;
394
-		}
395
-
396
-		$cacheKey = 'getHome'.$uid;
397
-		$path = $this->access->connection->getFromCache($cacheKey);
398
-		if(!is_null($path)) {
399
-			return $path;
400
-		}
401
-
402
-		// early return path if it is a deleted user
403
-		$user = $this->access->userManager->get($uid);
404
-		if($user instanceof OfflineUser) {
405
-			if($this->currentUserInDeletionProcess !== null
406
-				&& $this->currentUserInDeletionProcess === $user->getOCName()
407
-			) {
408
-				return $user->getHomePath();
409
-			} else {
410
-				throw new NoUserException($uid . ' is not a valid user anymore');
411
-			}
412
-		} else if ($user === null) {
413
-			throw new NoUserException($uid . ' is not a valid user anymore');
414
-		}
415
-
416
-		$path = $user->getHomePath();
417
-		$this->access->cacheUserHome($uid, $path);
418
-
419
-		return $path;
420
-	}
421
-
422
-	/**
423
-	 * get display name of the user
424
-	 * @param string $uid user ID of the user
425
-	 * @return string|false display name
426
-	 */
427
-	public function getDisplayName($uid) {
428
-		if(!$this->userExists($uid)) {
429
-			return false;
430
-		}
431
-
432
-		$cacheKey = 'getDisplayName'.$uid;
433
-		if(!is_null($displayName = $this->access->connection->getFromCache($cacheKey))) {
434
-			return $displayName;
435
-		}
436
-
437
-		//Check whether the display name is configured to have a 2nd feature
438
-		$additionalAttribute = $this->access->connection->ldapUserDisplayName2;
439
-		$displayName2 = '';
440
-		if ($additionalAttribute !== '') {
441
-			$displayName2 = $this->access->readAttribute(
442
-				$this->access->username2dn($uid),
443
-				$additionalAttribute);
444
-		}
445
-
446
-		$displayName = $this->access->readAttribute(
447
-			$this->access->username2dn($uid),
448
-			$this->access->connection->ldapUserDisplayName);
449
-
450
-		if($displayName && (count($displayName) > 0)) {
451
-			$displayName = $displayName[0];
452
-
453
-			if (is_array($displayName2)){
454
-				$displayName2 = count($displayName2) > 0 ? $displayName2[0] : '';
455
-			}
456
-
457
-			$user = $this->access->userManager->get($uid);
458
-			if ($user instanceof User) {
459
-				$displayName = $user->composeAndStoreDisplayName($displayName, $displayName2);
460
-				$this->access->connection->writeToCache($cacheKey, $displayName);
461
-			}
462
-			if ($user instanceof OfflineUser) {
463
-				/** @var OfflineUser $user*/
464
-				$displayName = $user->getDisplayName();
465
-			}
466
-			return $displayName;
467
-		}
468
-
469
-		return null;
470
-	}
471
-
472
-	/**
473
-	 * Get a list of all display names
474
-	 *
475
-	 * @param string $search
476
-	 * @param string|null $limit
477
-	 * @param string|null $offset
478
-	 * @return array an array of all displayNames (value) and the corresponding uids (key)
479
-	 */
480
-	public function getDisplayNames($search = '', $limit = null, $offset = null) {
481
-		$cacheKey = 'getDisplayNames-'.$search.'-'.$limit.'-'.$offset;
482
-		if(!is_null($displayNames = $this->access->connection->getFromCache($cacheKey))) {
483
-			return $displayNames;
484
-		}
485
-
486
-		$displayNames = array();
487
-		$users = $this->getUsers($search, $limit, $offset);
488
-		foreach ($users as $user) {
489
-			$displayNames[$user] = $this->getDisplayName($user);
490
-		}
491
-		$this->access->connection->writeToCache($cacheKey, $displayNames);
492
-		return $displayNames;
493
-	}
494
-
495
-	/**
496
-	* Check if backend implements actions
497
-	* @param int $actions bitwise-or'ed actions
498
-	* @return boolean
499
-	*
500
-	* Returns the supported actions as int to be
501
-	* compared with \OC\User\Backend::CREATE_USER etc.
502
-	*/
503
-	public function implementsActions($actions) {
504
-		return (bool)((Backend::CHECK_PASSWORD
505
-			| Backend::GET_HOME
506
-			| Backend::GET_DISPLAYNAME
507
-			| Backend::PROVIDE_AVATAR
508
-			| Backend::COUNT_USERS
509
-			| ((intval($this->access->connection->turnOnPasswordChange) === 1)?(Backend::SET_PASSWORD):0))
510
-			& $actions);
511
-	}
512
-
513
-	/**
514
-	 * @return bool
515
-	 */
516
-	public function hasUserListings() {
517
-		return true;
518
-	}
519
-
520
-	/**
521
-	 * counts the users in LDAP
522
-	 *
523
-	 * @return int|bool
524
-	 */
525
-	public function countUsers() {
526
-		$filter = $this->access->getFilterForUserCount();
527
-		$cacheKey = 'countUsers-'.$filter;
528
-		if(!is_null($entries = $this->access->connection->getFromCache($cacheKey))) {
529
-			return $entries;
530
-		}
531
-		$entries = $this->access->countUsers($filter);
532
-		$this->access->connection->writeToCache($cacheKey, $entries);
533
-		return $entries;
534
-	}
535
-
536
-	/**
537
-	 * Backend name to be shown in user management
538
-	 * @return string the name of the backend to be shown
539
-	 */
540
-	public function getBackendName(){
541
-		return 'LDAP';
542
-	}
133
+    /**
134
+     * returns the username for the given LDAP DN, if available
135
+     *
136
+     * @param string $dn
137
+     * @return string|false with the username
138
+     */
139
+    public function dn2UserName($dn) {
140
+        return $this->access->dn2username($dn);
141
+    }
142
+
143
+    /**
144
+     * returns an LDAP record based on a given login name
145
+     *
146
+     * @param string $loginName
147
+     * @return array
148
+     * @throws NotOnLDAP
149
+     */
150
+    public function getLDAPUserByLoginName($loginName) {
151
+        //find out dn of the user name
152
+        $attrs = $this->access->userManager->getAttributes();
153
+        $users = $this->access->fetchUsersByLoginName($loginName, $attrs);
154
+        if(count($users) < 1) {
155
+            throw new NotOnLDAP('No user available for the given login name on ' .
156
+                $this->access->connection->ldapHost . ':' . $this->access->connection->ldapPort);
157
+        }
158
+        return $users[0];
159
+    }
160
+
161
+    /**
162
+     * Check if the password is correct without logging in the user
163
+     *
164
+     * @param string $uid The username
165
+     * @param string $password The password
166
+     * @return false|string
167
+     */
168
+    public function checkPassword($uid, $password) {
169
+        try {
170
+            $ldapRecord = $this->getLDAPUserByLoginName($uid);
171
+        } catch(NotOnLDAP $e) {
172
+            if($this->ocConfig->getSystemValue('loglevel', Util::WARN) === Util::DEBUG) {
173
+                \OC::$server->getLogger()->logException($e, ['app' => 'user_ldap']);
174
+            }
175
+            return false;
176
+        }
177
+        $dn = $ldapRecord['dn'][0];
178
+        $user = $this->access->userManager->get($dn);
179
+
180
+        if(!$user instanceof User) {
181
+            Util::writeLog('user_ldap',
182
+                'LDAP Login: Could not get user object for DN ' . $dn .
183
+                '. Maybe the LDAP entry has no set display name attribute?',
184
+                Util::WARN);
185
+            return false;
186
+        }
187
+        if($user->getUsername() !== false) {
188
+            //are the credentials OK?
189
+            if(!$this->access->areCredentialsValid($dn, $password)) {
190
+                return false;
191
+            }
192
+
193
+            $this->access->cacheUserExists($user->getUsername());
194
+            $user->processAttributes($ldapRecord);
195
+            $user->markLogin();
196
+
197
+            return $user->getUsername();
198
+        }
199
+
200
+        return false;
201
+    }
202
+
203
+    /**
204
+     * Set password
205
+     * @param string $uid The username
206
+     * @param string $password The new password
207
+     * @return bool
208
+     */
209
+    public function setPassword($uid, $password) {
210
+        $user = $this->access->userManager->get($uid);
211
+
212
+        if(!$user instanceof User) {
213
+            throw new \Exception('LDAP setPassword: Could not get user object for uid ' . $uid .
214
+                '. Maybe the LDAP entry has no set display name attribute?');
215
+        }
216
+        if($user->getUsername() !== false && $this->access->setPassword($user->getDN(), $password)) {
217
+            $ldapDefaultPPolicyDN = $this->access->connection->ldapDefaultPPolicyDN;
218
+            $turnOnPasswordChange = $this->access->connection->turnOnPasswordChange;
219
+            if (!empty($ldapDefaultPPolicyDN) && (intval($turnOnPasswordChange) === 1)) {
220
+                //remove last password expiry warning if any
221
+                $notification = $this->notificationManager->createNotification();
222
+                $notification->setApp('user_ldap')
223
+                    ->setUser($uid)
224
+                    ->setObject('pwd_exp_warn', $uid)
225
+                ;
226
+                $this->notificationManager->markProcessed($notification);
227
+            }
228
+            return true;
229
+        }
230
+
231
+        return false;
232
+    }
233
+
234
+    /**
235
+     * Get a list of all users
236
+     *
237
+     * @param string $search
238
+     * @param integer $limit
239
+     * @param integer $offset
240
+     * @return string[] an array of all uids
241
+     */
242
+    public function getUsers($search = '', $limit = 10, $offset = 0) {
243
+        $search = $this->access->escapeFilterPart($search, true);
244
+        $cachekey = 'getUsers-'.$search.'-'.$limit.'-'.$offset;
245
+
246
+        //check if users are cached, if so return
247
+        $ldap_users = $this->access->connection->getFromCache($cachekey);
248
+        if(!is_null($ldap_users)) {
249
+            return $ldap_users;
250
+        }
251
+
252
+        // if we'd pass -1 to LDAP search, we'd end up in a Protocol
253
+        // error. With a limit of 0, we get 0 results. So we pass null.
254
+        if($limit <= 0) {
255
+            $limit = null;
256
+        }
257
+        $filter = $this->access->combineFilterWithAnd(array(
258
+            $this->access->connection->ldapUserFilter,
259
+            $this->access->connection->ldapUserDisplayName . '=*',
260
+            $this->access->getFilterPartForUserSearch($search)
261
+        ));
262
+
263
+        Util::writeLog('user_ldap',
264
+            'getUsers: Options: search '.$search.' limit '.$limit.' offset '.$offset.' Filter: '.$filter,
265
+            Util::DEBUG);
266
+        //do the search and translate results to Nextcloud names
267
+        $ldap_users = $this->access->fetchListOfUsers(
268
+            $filter,
269
+            $this->access->userManager->getAttributes(true),
270
+            $limit, $offset);
271
+        $ldap_users = $this->access->nextcloudUserNames($ldap_users);
272
+        Util::writeLog('user_ldap', 'getUsers: '.count($ldap_users). ' Users found', Util::DEBUG);
273
+
274
+        $this->access->connection->writeToCache($cachekey, $ldap_users);
275
+        return $ldap_users;
276
+    }
277
+
278
+    /**
279
+     * checks whether a user is still available on LDAP
280
+     *
281
+     * @param string|\OCA\User_LDAP\User\User $user either the Nextcloud user
282
+     * name or an instance of that user
283
+     * @return bool
284
+     * @throws \Exception
285
+     * @throws \OC\ServerNotAvailableException
286
+     */
287
+    public function userExistsOnLDAP($user) {
288
+        if(is_string($user)) {
289
+            $user = $this->access->userManager->get($user);
290
+        }
291
+        if(is_null($user)) {
292
+            return false;
293
+        }
294
+
295
+        $dn = $user->getDN();
296
+        //check if user really still exists by reading its entry
297
+        if(!is_array($this->access->readAttribute($dn, '', $this->access->connection->ldapUserFilter))) {
298
+            $lcr = $this->access->connection->getConnectionResource();
299
+            if(is_null($lcr)) {
300
+                throw new \Exception('No LDAP Connection to server ' . $this->access->connection->ldapHost);
301
+            }
302
+
303
+            try {
304
+                $uuid = $this->access->getUserMapper()->getUUIDByDN($dn);
305
+                if(!$uuid) {
306
+                    return false;
307
+                }
308
+                $newDn = $this->access->getUserDnByUuid($uuid);
309
+                //check if renamed user is still valid by reapplying the ldap filter
310
+                if(!is_array($this->access->readAttribute($newDn, '', $this->access->connection->ldapUserFilter))) {
311
+                    return false;
312
+                }
313
+                $this->access->getUserMapper()->setDNbyUUID($newDn, $uuid);
314
+                return true;
315
+            } catch (\Exception $e) {
316
+                return false;
317
+            }
318
+        }
319
+
320
+        if($user instanceof OfflineUser) {
321
+            $user->unmark();
322
+        }
323
+
324
+        return true;
325
+    }
326
+
327
+    /**
328
+     * check if a user exists
329
+     * @param string $uid the username
330
+     * @return boolean
331
+     * @throws \Exception when connection could not be established
332
+     */
333
+    public function userExists($uid) {
334
+        $userExists = $this->access->connection->getFromCache('userExists'.$uid);
335
+        if(!is_null($userExists)) {
336
+            return (bool)$userExists;
337
+        }
338
+        //getting dn, if false the user does not exist. If dn, he may be mapped only, requires more checking.
339
+        $user = $this->access->userManager->get($uid);
340
+
341
+        if(is_null($user)) {
342
+            Util::writeLog('user_ldap', 'No DN found for '.$uid.' on '.
343
+                $this->access->connection->ldapHost, Util::DEBUG);
344
+            $this->access->connection->writeToCache('userExists'.$uid, false);
345
+            return false;
346
+        } else if($user instanceof OfflineUser) {
347
+            //express check for users marked as deleted. Returning true is
348
+            //necessary for cleanup
349
+            return true;
350
+        }
351
+
352
+        $result = $this->userExistsOnLDAP($user);
353
+        $this->access->connection->writeToCache('userExists'.$uid, $result);
354
+        if($result === true) {
355
+            $user->update();
356
+        }
357
+        return $result;
358
+    }
359
+
360
+    /**
361
+     * returns whether a user was deleted in LDAP
362
+     *
363
+     * @param string $uid The username of the user to delete
364
+     * @return bool
365
+     */
366
+    public function deleteUser($uid) {
367
+        $marked = $this->ocConfig->getUserValue($uid, 'user_ldap', 'isDeleted', 0);
368
+        if(intval($marked) === 0) {
369
+            \OC::$server->getLogger()->notice(
370
+                'User '.$uid . ' is not marked as deleted, not cleaning up.',
371
+                array('app' => 'user_ldap'));
372
+            return false;
373
+        }
374
+        \OC::$server->getLogger()->info('Cleaning up after user ' . $uid,
375
+            array('app' => 'user_ldap'));
376
+
377
+        $this->access->getUserMapper()->unmap($uid);
378
+        $this->access->userManager->invalidate($uid);
379
+        return true;
380
+    }
381
+
382
+    /**
383
+     * get the user's home directory
384
+     *
385
+     * @param string $uid the username
386
+     * @return bool|string
387
+     * @throws NoUserException
388
+     * @throws \Exception
389
+     */
390
+    public function getHome($uid) {
391
+        // user Exists check required as it is not done in user proxy!
392
+        if(!$this->userExists($uid)) {
393
+            return false;
394
+        }
395
+
396
+        $cacheKey = 'getHome'.$uid;
397
+        $path = $this->access->connection->getFromCache($cacheKey);
398
+        if(!is_null($path)) {
399
+            return $path;
400
+        }
401
+
402
+        // early return path if it is a deleted user
403
+        $user = $this->access->userManager->get($uid);
404
+        if($user instanceof OfflineUser) {
405
+            if($this->currentUserInDeletionProcess !== null
406
+                && $this->currentUserInDeletionProcess === $user->getOCName()
407
+            ) {
408
+                return $user->getHomePath();
409
+            } else {
410
+                throw new NoUserException($uid . ' is not a valid user anymore');
411
+            }
412
+        } else if ($user === null) {
413
+            throw new NoUserException($uid . ' is not a valid user anymore');
414
+        }
415
+
416
+        $path = $user->getHomePath();
417
+        $this->access->cacheUserHome($uid, $path);
418
+
419
+        return $path;
420
+    }
421
+
422
+    /**
423
+     * get display name of the user
424
+     * @param string $uid user ID of the user
425
+     * @return string|false display name
426
+     */
427
+    public function getDisplayName($uid) {
428
+        if(!$this->userExists($uid)) {
429
+            return false;
430
+        }
431
+
432
+        $cacheKey = 'getDisplayName'.$uid;
433
+        if(!is_null($displayName = $this->access->connection->getFromCache($cacheKey))) {
434
+            return $displayName;
435
+        }
436
+
437
+        //Check whether the display name is configured to have a 2nd feature
438
+        $additionalAttribute = $this->access->connection->ldapUserDisplayName2;
439
+        $displayName2 = '';
440
+        if ($additionalAttribute !== '') {
441
+            $displayName2 = $this->access->readAttribute(
442
+                $this->access->username2dn($uid),
443
+                $additionalAttribute);
444
+        }
445
+
446
+        $displayName = $this->access->readAttribute(
447
+            $this->access->username2dn($uid),
448
+            $this->access->connection->ldapUserDisplayName);
449
+
450
+        if($displayName && (count($displayName) > 0)) {
451
+            $displayName = $displayName[0];
452
+
453
+            if (is_array($displayName2)){
454
+                $displayName2 = count($displayName2) > 0 ? $displayName2[0] : '';
455
+            }
456
+
457
+            $user = $this->access->userManager->get($uid);
458
+            if ($user instanceof User) {
459
+                $displayName = $user->composeAndStoreDisplayName($displayName, $displayName2);
460
+                $this->access->connection->writeToCache($cacheKey, $displayName);
461
+            }
462
+            if ($user instanceof OfflineUser) {
463
+                /** @var OfflineUser $user*/
464
+                $displayName = $user->getDisplayName();
465
+            }
466
+            return $displayName;
467
+        }
468
+
469
+        return null;
470
+    }
471
+
472
+    /**
473
+     * Get a list of all display names
474
+     *
475
+     * @param string $search
476
+     * @param string|null $limit
477
+     * @param string|null $offset
478
+     * @return array an array of all displayNames (value) and the corresponding uids (key)
479
+     */
480
+    public function getDisplayNames($search = '', $limit = null, $offset = null) {
481
+        $cacheKey = 'getDisplayNames-'.$search.'-'.$limit.'-'.$offset;
482
+        if(!is_null($displayNames = $this->access->connection->getFromCache($cacheKey))) {
483
+            return $displayNames;
484
+        }
485
+
486
+        $displayNames = array();
487
+        $users = $this->getUsers($search, $limit, $offset);
488
+        foreach ($users as $user) {
489
+            $displayNames[$user] = $this->getDisplayName($user);
490
+        }
491
+        $this->access->connection->writeToCache($cacheKey, $displayNames);
492
+        return $displayNames;
493
+    }
494
+
495
+    /**
496
+     * Check if backend implements actions
497
+     * @param int $actions bitwise-or'ed actions
498
+     * @return boolean
499
+     *
500
+     * Returns the supported actions as int to be
501
+     * compared with \OC\User\Backend::CREATE_USER etc.
502
+     */
503
+    public function implementsActions($actions) {
504
+        return (bool)((Backend::CHECK_PASSWORD
505
+            | Backend::GET_HOME
506
+            | Backend::GET_DISPLAYNAME
507
+            | Backend::PROVIDE_AVATAR
508
+            | Backend::COUNT_USERS
509
+            | ((intval($this->access->connection->turnOnPasswordChange) === 1)?(Backend::SET_PASSWORD):0))
510
+            & $actions);
511
+    }
512
+
513
+    /**
514
+     * @return bool
515
+     */
516
+    public function hasUserListings() {
517
+        return true;
518
+    }
519
+
520
+    /**
521
+     * counts the users in LDAP
522
+     *
523
+     * @return int|bool
524
+     */
525
+    public function countUsers() {
526
+        $filter = $this->access->getFilterForUserCount();
527
+        $cacheKey = 'countUsers-'.$filter;
528
+        if(!is_null($entries = $this->access->connection->getFromCache($cacheKey))) {
529
+            return $entries;
530
+        }
531
+        $entries = $this->access->countUsers($filter);
532
+        $this->access->connection->writeToCache($cacheKey, $entries);
533
+        return $entries;
534
+    }
535
+
536
+    /**
537
+     * Backend name to be shown in user management
538
+     * @return string the name of the backend to be shown
539
+     */
540
+    public function getBackendName(){
541
+        return 'LDAP';
542
+    }
543 543
 	
544
-	/**
545
-	 * Return access for LDAP interaction.
546
-	 * @param string $uid
547
-	 * @return Access instance of Access for LDAP interaction
548
-	 */
549
-	public function getLDAPAccess($uid) {
550
-		return $this->access;
551
-	}
544
+    /**
545
+     * Return access for LDAP interaction.
546
+     * @param string $uid
547
+     * @return Access instance of Access for LDAP interaction
548
+     */
549
+    public function getLDAPAccess($uid) {
550
+        return $this->access;
551
+    }
552 552
 	
553
-	/**
554
-	 * Return LDAP connection resource from a cloned connection.
555
-	 * The cloned connection needs to be closed manually.
556
-	 * of the current access.
557
-	 * @param string $uid
558
-	 * @return resource of the LDAP connection
559
-	 */
560
-	public function getNewLDAPConnection($uid) {
561
-		$connection = clone $this->access->getConnection();
562
-		return $connection->getConnectionResource();
563
-	}
553
+    /**
554
+     * Return LDAP connection resource from a cloned connection.
555
+     * The cloned connection needs to be closed manually.
556
+     * of the current access.
557
+     * @param string $uid
558
+     * @return resource of the LDAP connection
559
+     */
560
+    public function getNewLDAPConnection($uid) {
561
+        $connection = clone $this->access->getConnection();
562
+        return $connection->getConnectionResource();
563
+    }
564 564
 }
Please login to merge, or discard this patch.
apps/user_ldap/lib/User/Manager.php 1 patch
Indentation   +193 added lines, -193 removed lines patch added patch discarded remove patch
@@ -44,223 +44,223 @@
 block discarded – undo
44 44
  * cache
45 45
  */
46 46
 class Manager {
47
-	/** @var IUserTools */
48
-	protected $access;
47
+    /** @var IUserTools */
48
+    protected $access;
49 49
 
50
-	/** @var IConfig */
51
-	protected $ocConfig;
50
+    /** @var IConfig */
51
+    protected $ocConfig;
52 52
 
53
-	/** @var IDBConnection */
54
-	protected $db;
53
+    /** @var IDBConnection */
54
+    protected $db;
55 55
 
56
-	/** @var IUserManager */
57
-	protected $userManager;
56
+    /** @var IUserManager */
57
+    protected $userManager;
58 58
 
59
-	/** @var INotificationManager */
60
-	protected $notificationManager;
59
+    /** @var INotificationManager */
60
+    protected $notificationManager;
61 61
 
62
-	/** @var FilesystemHelper */
63
-	protected $ocFilesystem;
62
+    /** @var FilesystemHelper */
63
+    protected $ocFilesystem;
64 64
 
65
-	/** @var LogWrapper */
66
-	protected $ocLog;
65
+    /** @var LogWrapper */
66
+    protected $ocLog;
67 67
 
68
-	/** @var Image */
69
-	protected $image;
68
+    /** @var Image */
69
+    protected $image;
70 70
 
71
-	/** @param \OCP\IAvatarManager */
72
-	protected $avatarManager;
71
+    /** @param \OCP\IAvatarManager */
72
+    protected $avatarManager;
73 73
 
74
-	/**
75
-	 * @var CappedMemoryCache $usersByDN
76
-	 */
77
-	protected $usersByDN;
78
-	/**
79
-	 * @var CappedMemoryCache $usersByUid
80
-	 */
81
-	protected $usersByUid;
74
+    /**
75
+     * @var CappedMemoryCache $usersByDN
76
+     */
77
+    protected $usersByDN;
78
+    /**
79
+     * @var CappedMemoryCache $usersByUid
80
+     */
81
+    protected $usersByUid;
82 82
 
83
-	/**
84
-	 * @param IConfig $ocConfig
85
-	 * @param \OCA\User_LDAP\FilesystemHelper $ocFilesystem object that
86
-	 * gives access to necessary functions from the OC filesystem
87
-	 * @param  \OCA\User_LDAP\LogWrapper $ocLog
88
-	 * @param IAvatarManager $avatarManager
89
-	 * @param Image $image an empty image instance
90
-	 * @param IDBConnection $db
91
-	 * @throws \Exception when the methods mentioned above do not exist
92
-	 */
93
-	public function __construct(IConfig $ocConfig,
94
-								FilesystemHelper $ocFilesystem, LogWrapper $ocLog,
95
-								IAvatarManager $avatarManager, Image $image,
96
-								IDBConnection $db, IUserManager $userManager,
97
-								INotificationManager $notificationManager) {
83
+    /**
84
+     * @param IConfig $ocConfig
85
+     * @param \OCA\User_LDAP\FilesystemHelper $ocFilesystem object that
86
+     * gives access to necessary functions from the OC filesystem
87
+     * @param  \OCA\User_LDAP\LogWrapper $ocLog
88
+     * @param IAvatarManager $avatarManager
89
+     * @param Image $image an empty image instance
90
+     * @param IDBConnection $db
91
+     * @throws \Exception when the methods mentioned above do not exist
92
+     */
93
+    public function __construct(IConfig $ocConfig,
94
+                                FilesystemHelper $ocFilesystem, LogWrapper $ocLog,
95
+                                IAvatarManager $avatarManager, Image $image,
96
+                                IDBConnection $db, IUserManager $userManager,
97
+                                INotificationManager $notificationManager) {
98 98
 
99
-		$this->ocConfig            = $ocConfig;
100
-		$this->ocFilesystem        = $ocFilesystem;
101
-		$this->ocLog               = $ocLog;
102
-		$this->avatarManager       = $avatarManager;
103
-		$this->image               = $image;
104
-		$this->db                  = $db;
105
-		$this->userManager         = $userManager;
106
-		$this->notificationManager = $notificationManager;
107
-		$this->usersByDN           = new CappedMemoryCache();
108
-		$this->usersByUid          = new CappedMemoryCache();
109
-	}
99
+        $this->ocConfig            = $ocConfig;
100
+        $this->ocFilesystem        = $ocFilesystem;
101
+        $this->ocLog               = $ocLog;
102
+        $this->avatarManager       = $avatarManager;
103
+        $this->image               = $image;
104
+        $this->db                  = $db;
105
+        $this->userManager         = $userManager;
106
+        $this->notificationManager = $notificationManager;
107
+        $this->usersByDN           = new CappedMemoryCache();
108
+        $this->usersByUid          = new CappedMemoryCache();
109
+    }
110 110
 
111
-	/**
112
-	 * @brief binds manager to an instance of IUserTools (implemented by
113
-	 * Access). It needs to be assigned first before the manager can be used.
114
-	 * @param IUserTools
115
-	 */
116
-	public function setLdapAccess(IUserTools $access) {
117
-		$this->access = $access;
118
-	}
111
+    /**
112
+     * @brief binds manager to an instance of IUserTools (implemented by
113
+     * Access). It needs to be assigned first before the manager can be used.
114
+     * @param IUserTools
115
+     */
116
+    public function setLdapAccess(IUserTools $access) {
117
+        $this->access = $access;
118
+    }
119 119
 
120
-	/**
121
-	 * @brief creates an instance of User and caches (just runtime) it in the
122
-	 * property array
123
-	 * @param string $dn the DN of the user
124
-	 * @param string $uid the internal (owncloud) username
125
-	 * @return \OCA\User_LDAP\User\User
126
-	 */
127
-	private function createAndCache($dn, $uid) {
128
-		$this->checkAccess();
129
-		$user = new User($uid, $dn, $this->access, $this->ocConfig,
130
-			$this->ocFilesystem, clone $this->image, $this->ocLog,
131
-			$this->avatarManager, $this->userManager, 
132
-			$this->notificationManager);
133
-		$this->usersByDN[$dn]   = $user;
134
-		$this->usersByUid[$uid] = $user;
135
-		return $user;
136
-	}
120
+    /**
121
+     * @brief creates an instance of User and caches (just runtime) it in the
122
+     * property array
123
+     * @param string $dn the DN of the user
124
+     * @param string $uid the internal (owncloud) username
125
+     * @return \OCA\User_LDAP\User\User
126
+     */
127
+    private function createAndCache($dn, $uid) {
128
+        $this->checkAccess();
129
+        $user = new User($uid, $dn, $this->access, $this->ocConfig,
130
+            $this->ocFilesystem, clone $this->image, $this->ocLog,
131
+            $this->avatarManager, $this->userManager, 
132
+            $this->notificationManager);
133
+        $this->usersByDN[$dn]   = $user;
134
+        $this->usersByUid[$uid] = $user;
135
+        return $user;
136
+    }
137 137
 
138
-	/**
139
-	 * removes a user entry from the cache
140
-	 * @param $uid
141
-	 */
142
-	public function invalidate($uid) {
143
-		if(!isset($this->usersByUid[$uid])) {
144
-			return;
145
-		}
146
-		$dn = $this->usersByUid[$uid]->getDN();
147
-		unset($this->usersByUid[$uid]);
148
-		unset($this->usersByDN[$dn]);
149
-	}
138
+    /**
139
+     * removes a user entry from the cache
140
+     * @param $uid
141
+     */
142
+    public function invalidate($uid) {
143
+        if(!isset($this->usersByUid[$uid])) {
144
+            return;
145
+        }
146
+        $dn = $this->usersByUid[$uid]->getDN();
147
+        unset($this->usersByUid[$uid]);
148
+        unset($this->usersByDN[$dn]);
149
+    }
150 150
 
151
-	/**
152
-	 * @brief checks whether the Access instance has been set
153
-	 * @throws \Exception if Access has not been set
154
-	 * @return null
155
-	 */
156
-	private function checkAccess() {
157
-		if(is_null($this->access)) {
158
-			throw new \Exception('LDAP Access instance must be set first');
159
-		}
160
-	}
151
+    /**
152
+     * @brief checks whether the Access instance has been set
153
+     * @throws \Exception if Access has not been set
154
+     * @return null
155
+     */
156
+    private function checkAccess() {
157
+        if(is_null($this->access)) {
158
+            throw new \Exception('LDAP Access instance must be set first');
159
+        }
160
+    }
161 161
 
162
-	/**
163
-	 * returns a list of attributes that will be processed further, e.g. quota,
164
-	 * email, displayname, or others.
165
-	 * @param bool $minimal - optional, set to true to skip attributes with big
166
-	 * payload
167
-	 * @return string[]
168
-	 */
169
-	public function getAttributes($minimal = false) {
170
-		$attributes = array_merge(Access::UUID_ATTRIBUTES, ['dn', 'uid', 'samaccountname', 'memberof']);
171
-		$possible = array(
172
-			$this->access->getConnection()->ldapExpertUUIDUserAttr,
173
-			$this->access->getConnection()->ldapQuotaAttribute,
174
-			$this->access->getConnection()->ldapEmailAttribute,
175
-			$this->access->getConnection()->ldapUserDisplayName,
176
-			$this->access->getConnection()->ldapUserDisplayName2,
177
-		);
178
-		foreach($possible as $attr) {
179
-			if(!is_null($attr)) {
180
-				$attributes[] = $attr;
181
-			}
182
-		}
162
+    /**
163
+     * returns a list of attributes that will be processed further, e.g. quota,
164
+     * email, displayname, or others.
165
+     * @param bool $minimal - optional, set to true to skip attributes with big
166
+     * payload
167
+     * @return string[]
168
+     */
169
+    public function getAttributes($minimal = false) {
170
+        $attributes = array_merge(Access::UUID_ATTRIBUTES, ['dn', 'uid', 'samaccountname', 'memberof']);
171
+        $possible = array(
172
+            $this->access->getConnection()->ldapExpertUUIDUserAttr,
173
+            $this->access->getConnection()->ldapQuotaAttribute,
174
+            $this->access->getConnection()->ldapEmailAttribute,
175
+            $this->access->getConnection()->ldapUserDisplayName,
176
+            $this->access->getConnection()->ldapUserDisplayName2,
177
+        );
178
+        foreach($possible as $attr) {
179
+            if(!is_null($attr)) {
180
+                $attributes[] = $attr;
181
+            }
182
+        }
183 183
 
184
-		$homeRule = $this->access->getConnection()->homeFolderNamingRule;
185
-		if(strpos($homeRule, 'attr:') === 0) {
186
-			$attributes[] = substr($homeRule, strlen('attr:'));
187
-		}
184
+        $homeRule = $this->access->getConnection()->homeFolderNamingRule;
185
+        if(strpos($homeRule, 'attr:') === 0) {
186
+            $attributes[] = substr($homeRule, strlen('attr:'));
187
+        }
188 188
 
189
-		if(!$minimal) {
190
-			// attributes that are not really important but may come with big
191
-			// payload.
192
-			$attributes = array_merge($attributes, array(
193
-				'jpegphoto',
194
-				'thumbnailphoto'
195
-			));
196
-		}
189
+        if(!$minimal) {
190
+            // attributes that are not really important but may come with big
191
+            // payload.
192
+            $attributes = array_merge($attributes, array(
193
+                'jpegphoto',
194
+                'thumbnailphoto'
195
+            ));
196
+        }
197 197
 
198
-		return $attributes;
199
-	}
198
+        return $attributes;
199
+    }
200 200
 
201
-	/**
202
-	 * Checks whether the specified user is marked as deleted
203
-	 * @param string $id the Nextcloud user name
204
-	 * @return bool
205
-	 */
206
-	public function isDeletedUser($id) {
207
-		$isDeleted = $this->ocConfig->getUserValue(
208
-			$id, 'user_ldap', 'isDeleted', 0);
209
-		return intval($isDeleted) === 1;
210
-	}
201
+    /**
202
+     * Checks whether the specified user is marked as deleted
203
+     * @param string $id the Nextcloud user name
204
+     * @return bool
205
+     */
206
+    public function isDeletedUser($id) {
207
+        $isDeleted = $this->ocConfig->getUserValue(
208
+            $id, 'user_ldap', 'isDeleted', 0);
209
+        return intval($isDeleted) === 1;
210
+    }
211 211
 
212
-	/**
213
-	 * creates and returns an instance of OfflineUser for the specified user
214
-	 * @param string $id
215
-	 * @return \OCA\User_LDAP\User\OfflineUser
216
-	 */
217
-	public function getDeletedUser($id) {
218
-		return new OfflineUser(
219
-			$id,
220
-			$this->ocConfig,
221
-			$this->db,
222
-			$this->access->getUserMapper());
223
-	}
212
+    /**
213
+     * creates and returns an instance of OfflineUser for the specified user
214
+     * @param string $id
215
+     * @return \OCA\User_LDAP\User\OfflineUser
216
+     */
217
+    public function getDeletedUser($id) {
218
+        return new OfflineUser(
219
+            $id,
220
+            $this->ocConfig,
221
+            $this->db,
222
+            $this->access->getUserMapper());
223
+    }
224 224
 
225
-	/**
226
-	 * @brief returns a User object by it's Nextcloud username
227
-	 * @param string $id the DN or username of the user
228
-	 * @return \OCA\User_LDAP\User\User|\OCA\User_LDAP\User\OfflineUser|null
229
-	 */
230
-	protected function createInstancyByUserName($id) {
231
-		//most likely a uid. Check whether it is a deleted user
232
-		if($this->isDeletedUser($id)) {
233
-			return $this->getDeletedUser($id);
234
-		}
235
-		$dn = $this->access->username2dn($id);
236
-		if($dn !== false) {
237
-			return $this->createAndCache($dn, $id);
238
-		}
239
-		return null;
240
-	}
225
+    /**
226
+     * @brief returns a User object by it's Nextcloud username
227
+     * @param string $id the DN or username of the user
228
+     * @return \OCA\User_LDAP\User\User|\OCA\User_LDAP\User\OfflineUser|null
229
+     */
230
+    protected function createInstancyByUserName($id) {
231
+        //most likely a uid. Check whether it is a deleted user
232
+        if($this->isDeletedUser($id)) {
233
+            return $this->getDeletedUser($id);
234
+        }
235
+        $dn = $this->access->username2dn($id);
236
+        if($dn !== false) {
237
+            return $this->createAndCache($dn, $id);
238
+        }
239
+        return null;
240
+    }
241 241
 
242
-	/**
243
-	 * @brief returns a User object by it's DN or Nextcloud username
244
-	 * @param string $id the DN or username of the user
245
-	 * @return \OCA\User_LDAP\User\User|\OCA\User_LDAP\User\OfflineUser|null
246
-	 * @throws \Exception when connection could not be established
247
-	 */
248
-	public function get($id) {
249
-		$this->checkAccess();
250
-		if(isset($this->usersByDN[$id])) {
251
-			return $this->usersByDN[$id];
252
-		} else if(isset($this->usersByUid[$id])) {
253
-			return $this->usersByUid[$id];
254
-		}
242
+    /**
243
+     * @brief returns a User object by it's DN or Nextcloud username
244
+     * @param string $id the DN or username of the user
245
+     * @return \OCA\User_LDAP\User\User|\OCA\User_LDAP\User\OfflineUser|null
246
+     * @throws \Exception when connection could not be established
247
+     */
248
+    public function get($id) {
249
+        $this->checkAccess();
250
+        if(isset($this->usersByDN[$id])) {
251
+            return $this->usersByDN[$id];
252
+        } else if(isset($this->usersByUid[$id])) {
253
+            return $this->usersByUid[$id];
254
+        }
255 255
 
256
-		if($this->access->stringResemblesDN($id) ) {
257
-			$uid = $this->access->dn2username($id);
258
-			if($uid !== false) {
259
-				return $this->createAndCache($id, $uid);
260
-			}
261
-		}
256
+        if($this->access->stringResemblesDN($id) ) {
257
+            $uid = $this->access->dn2username($id);
258
+            if($uid !== false) {
259
+                return $this->createAndCache($id, $uid);
260
+            }
261
+        }
262 262
 
263
-		return $this->createInstancyByUserName($id);
264
-	}
263
+        return $this->createInstancyByUserName($id);
264
+    }
265 265
 
266 266
 }
Please login to merge, or discard this patch.
apps/user_ldap/lib/User/User.php 2 patches
Indentation   +644 added lines, -644 removed lines patch added patch discarded remove patch
@@ -43,654 +43,654 @@
 block discarded – undo
43 43
  * represents an LDAP user, gets and holds user-specific information from LDAP
44 44
  */
45 45
 class User {
46
-	/**
47
-	 * @var IUserTools
48
-	 */
49
-	protected $access;
50
-	/**
51
-	 * @var Connection
52
-	 */
53
-	protected $connection;
54
-	/**
55
-	 * @var IConfig
56
-	 */
57
-	protected $config;
58
-	/**
59
-	 * @var FilesystemHelper
60
-	 */
61
-	protected $fs;
62
-	/**
63
-	 * @var Image
64
-	 */
65
-	protected $image;
66
-	/**
67
-	 * @var LogWrapper
68
-	 */
69
-	protected $log;
70
-	/**
71
-	 * @var IAvatarManager
72
-	 */
73
-	protected $avatarManager;
74
-	/**
75
-	 * @var IUserManager
76
-	 */
77
-	protected $userManager;
78
-	/**
79
-	 * @var INotificationManager
80
-	 */
81
-	protected $notificationManager;
82
-	/**
83
-	 * @var string
84
-	 */
85
-	protected $dn;
86
-	/**
87
-	 * @var string
88
-	 */
89
-	protected $uid;
90
-	/**
91
-	 * @var string[]
92
-	 */
93
-	protected $refreshedFeatures = array();
94
-	/**
95
-	 * @var string
96
-	 */
97
-	protected $avatarImage;
98
-
99
-	/**
100
-	 * DB config keys for user preferences
101
-	 */
102
-	const USER_PREFKEY_FIRSTLOGIN  = 'firstLoginAccomplished';
103
-	const USER_PREFKEY_LASTREFRESH = 'lastFeatureRefresh';
104
-
105
-	/**
106
-	 * @brief constructor, make sure the subclasses call this one!
107
-	 * @param string $username the internal username
108
-	 * @param string $dn the LDAP DN
109
-	 * @param IUserTools $access an instance that implements IUserTools for
110
-	 * LDAP interaction
111
-	 * @param IConfig $config
112
-	 * @param FilesystemHelper $fs
113
-	 * @param Image $image any empty instance
114
-	 * @param LogWrapper $log
115
-	 * @param IAvatarManager $avatarManager
116
-	 * @param IUserManager $userManager
117
-	 * @param INotificationManager $notificationManager
118
-	 */
119
-	public function __construct($username, $dn, IUserTools $access,
120
-		IConfig $config, FilesystemHelper $fs, Image $image,
121
-		LogWrapper $log, IAvatarManager $avatarManager, IUserManager $userManager,
122
-		INotificationManager $notificationManager) {
46
+    /**
47
+     * @var IUserTools
48
+     */
49
+    protected $access;
50
+    /**
51
+     * @var Connection
52
+     */
53
+    protected $connection;
54
+    /**
55
+     * @var IConfig
56
+     */
57
+    protected $config;
58
+    /**
59
+     * @var FilesystemHelper
60
+     */
61
+    protected $fs;
62
+    /**
63
+     * @var Image
64
+     */
65
+    protected $image;
66
+    /**
67
+     * @var LogWrapper
68
+     */
69
+    protected $log;
70
+    /**
71
+     * @var IAvatarManager
72
+     */
73
+    protected $avatarManager;
74
+    /**
75
+     * @var IUserManager
76
+     */
77
+    protected $userManager;
78
+    /**
79
+     * @var INotificationManager
80
+     */
81
+    protected $notificationManager;
82
+    /**
83
+     * @var string
84
+     */
85
+    protected $dn;
86
+    /**
87
+     * @var string
88
+     */
89
+    protected $uid;
90
+    /**
91
+     * @var string[]
92
+     */
93
+    protected $refreshedFeatures = array();
94
+    /**
95
+     * @var string
96
+     */
97
+    protected $avatarImage;
98
+
99
+    /**
100
+     * DB config keys for user preferences
101
+     */
102
+    const USER_PREFKEY_FIRSTLOGIN  = 'firstLoginAccomplished';
103
+    const USER_PREFKEY_LASTREFRESH = 'lastFeatureRefresh';
104
+
105
+    /**
106
+     * @brief constructor, make sure the subclasses call this one!
107
+     * @param string $username the internal username
108
+     * @param string $dn the LDAP DN
109
+     * @param IUserTools $access an instance that implements IUserTools for
110
+     * LDAP interaction
111
+     * @param IConfig $config
112
+     * @param FilesystemHelper $fs
113
+     * @param Image $image any empty instance
114
+     * @param LogWrapper $log
115
+     * @param IAvatarManager $avatarManager
116
+     * @param IUserManager $userManager
117
+     * @param INotificationManager $notificationManager
118
+     */
119
+    public function __construct($username, $dn, IUserTools $access,
120
+        IConfig $config, FilesystemHelper $fs, Image $image,
121
+        LogWrapper $log, IAvatarManager $avatarManager, IUserManager $userManager,
122
+        INotificationManager $notificationManager) {
123 123
 	
124
-		if ($username === null) {
125
-			$log->log("uid for '$dn' must not be null!", Util::ERROR);
126
-			throw new \InvalidArgumentException('uid must not be null!');
127
-		} else if ($username === '') {
128
-			$log->log("uid for '$dn' must not be an empty string", Util::ERROR);
129
-			throw new \InvalidArgumentException('uid must not be an empty string!');
130
-		}
131
-
132
-		$this->access              = $access;
133
-		$this->connection          = $access->getConnection();
134
-		$this->config              = $config;
135
-		$this->fs                  = $fs;
136
-		$this->dn                  = $dn;
137
-		$this->uid                 = $username;
138
-		$this->image               = $image;
139
-		$this->log                 = $log;
140
-		$this->avatarManager       = $avatarManager;
141
-		$this->userManager         = $userManager;
142
-		$this->notificationManager = $notificationManager;
143
-
144
-		\OCP\Util::connectHook('OC_User', 'post_login', $this, 'handlePasswordExpiry');
145
-	}
146
-
147
-	/**
148
-	 * @brief updates properties like email, quota or avatar provided by LDAP
149
-	 * @return null
150
-	 */
151
-	public function update() {
152
-		if(is_null($this->dn)) {
153
-			return null;
154
-		}
155
-
156
-		$hasLoggedIn = $this->config->getUserValue($this->uid, 'user_ldap',
157
-				self::USER_PREFKEY_FIRSTLOGIN, 0);
158
-
159
-		if($this->needsRefresh()) {
160
-			$this->updateEmail();
161
-			$this->updateQuota();
162
-			if($hasLoggedIn !== 0) {
163
-				//we do not need to try it, when the user has not been logged in
164
-				//before, because the file system will not be ready.
165
-				$this->updateAvatar();
166
-				//in order to get an avatar as soon as possible, mark the user
167
-				//as refreshed only when updating the avatar did happen
168
-				$this->markRefreshTime();
169
-			}
170
-		}
171
-	}
172
-
173
-	/**
174
-	 * processes results from LDAP for attributes as returned by getAttributesToRead()
175
-	 * @param array $ldapEntry the user entry as retrieved from LDAP
176
-	 */
177
-	public function processAttributes($ldapEntry) {
178
-		$this->markRefreshTime();
179
-		//Quota
180
-		$attr = strtolower($this->connection->ldapQuotaAttribute);
181
-		if(isset($ldapEntry[$attr])) {
182
-			$this->updateQuota($ldapEntry[$attr][0]);
183
-		} else {
184
-			if ($this->connection->ldapQuotaDefault !== '') {
185
-				$this->updateQuota();
186
-			}
187
-		}
188
-		unset($attr);
189
-
190
-		//displayName
191
-		$displayName = $displayName2 = '';
192
-		$attr = strtolower($this->connection->ldapUserDisplayName);
193
-		if(isset($ldapEntry[$attr])) {
194
-			$displayName = strval($ldapEntry[$attr][0]);
195
-		}
196
-		$attr = strtolower($this->connection->ldapUserDisplayName2);
197
-		if(isset($ldapEntry[$attr])) {
198
-			$displayName2 = strval($ldapEntry[$attr][0]);
199
-		}
200
-		if ($displayName !== '') {
201
-			$this->composeAndStoreDisplayName($displayName);
202
-			$this->access->cacheUserDisplayName(
203
-				$this->getUsername(),
204
-				$displayName,
205
-				$displayName2
206
-			);
207
-		}
208
-		unset($attr);
209
-
210
-		//Email
211
-		//email must be stored after displayname, because it would cause a user
212
-		//change event that will trigger fetching the display name again
213
-		$attr = strtolower($this->connection->ldapEmailAttribute);
214
-		if(isset($ldapEntry[$attr])) {
215
-			$this->updateEmail($ldapEntry[$attr][0]);
216
-		}
217
-		unset($attr);
218
-
219
-		// LDAP Username, needed for s2s sharing
220
-		if(isset($ldapEntry['uid'])) {
221
-			$this->storeLDAPUserName($ldapEntry['uid'][0]);
222
-		} else if(isset($ldapEntry['samaccountname'])) {
223
-			$this->storeLDAPUserName($ldapEntry['samaccountname'][0]);
224
-		}
225
-
226
-		//homePath
227
-		if(strpos($this->connection->homeFolderNamingRule, 'attr:') === 0) {
228
-			$attr = strtolower(substr($this->connection->homeFolderNamingRule, strlen('attr:')));
229
-			if(isset($ldapEntry[$attr])) {
230
-				$this->access->cacheUserHome(
231
-					$this->getUsername(), $this->getHomePath($ldapEntry[$attr][0]));
232
-			}
233
-		}
234
-
235
-		//memberOf groups
236
-		$cacheKey = 'getMemberOf'.$this->getUsername();
237
-		$groups = false;
238
-		if(isset($ldapEntry['memberof'])) {
239
-			$groups = $ldapEntry['memberof'];
240
-		}
241
-		$this->connection->writeToCache($cacheKey, $groups);
242
-
243
-		//Avatar
244
-		$attrs = array('jpegphoto', 'thumbnailphoto');
245
-		foreach ($attrs as $attr)  {
246
-			if(isset($ldapEntry[$attr])) {
247
-				$this->avatarImage = $ldapEntry[$attr][0];
248
-				// the call to the method that saves the avatar in the file
249
-				// system must be postponed after the login. It is to ensure
250
-				// external mounts are mounted properly (e.g. with login
251
-				// credentials from the session).
252
-				\OCP\Util::connectHook('OC_User', 'post_login', $this, 'updateAvatarPostLogin');
253
-				break;
254
-			}
255
-		}
256
-	}
257
-
258
-	/**
259
-	 * @brief returns the LDAP DN of the user
260
-	 * @return string
261
-	 */
262
-	public function getDN() {
263
-		return $this->dn;
264
-	}
265
-
266
-	/**
267
-	 * @brief returns the Nextcloud internal username of the user
268
-	 * @return string
269
-	 */
270
-	public function getUsername() {
271
-		return $this->uid;
272
-	}
273
-
274
-	/**
275
-	 * returns the home directory of the user if specified by LDAP settings
276
-	 * @param string $valueFromLDAP
277
-	 * @return bool|string
278
-	 * @throws \Exception
279
-	 */
280
-	public function getHomePath($valueFromLDAP = null) {
281
-		$path = strval($valueFromLDAP);
282
-		$attr = null;
283
-
284
-		if (is_null($valueFromLDAP)
285
-		   && strpos($this->access->connection->homeFolderNamingRule, 'attr:') === 0
286
-		   && $this->access->connection->homeFolderNamingRule !== 'attr:')
287
-		{
288
-			$attr = substr($this->access->connection->homeFolderNamingRule, strlen('attr:'));
289
-			$homedir = $this->access->readAttribute(
290
-				$this->access->username2dn($this->getUsername()), $attr);
291
-			if ($homedir && isset($homedir[0])) {
292
-				$path = $homedir[0];
293
-			}
294
-		}
295
-
296
-		if ($path !== '') {
297
-			//if attribute's value is an absolute path take this, otherwise append it to data dir
298
-			//check for / at the beginning or pattern c:\ resp. c:/
299
-			if(   '/' !== $path[0]
300
-			   && !(3 < strlen($path) && ctype_alpha($path[0])
301
-			       && $path[1] === ':' && ('\\' === $path[2] || '/' === $path[2]))
302
-			) {
303
-				$path = $this->config->getSystemValue('datadirectory',
304
-						\OC::$SERVERROOT.'/data' ) . '/' . $path;
305
-			}
306
-			//we need it to store it in the DB as well in case a user gets
307
-			//deleted so we can clean up afterwards
308
-			$this->config->setUserValue(
309
-				$this->getUsername(), 'user_ldap', 'homePath', $path
310
-			);
311
-			return $path;
312
-		}
313
-
314
-		if(    !is_null($attr)
315
-			&& $this->config->getAppValue('user_ldap', 'enforce_home_folder_naming_rule', true)
316
-		) {
317
-			// a naming rule attribute is defined, but it doesn't exist for that LDAP user
318
-			throw new \Exception('Home dir attribute can\'t be read from LDAP for uid: ' . $this->getUsername());
319
-		}
320
-
321
-		//false will apply default behaviour as defined and done by OC_User
322
-		$this->config->setUserValue($this->getUsername(), 'user_ldap', 'homePath', '');
323
-		return false;
324
-	}
325
-
326
-	public function getMemberOfGroups() {
327
-		$cacheKey = 'getMemberOf'.$this->getUsername();
328
-		$memberOfGroups = $this->connection->getFromCache($cacheKey);
329
-		if(!is_null($memberOfGroups)) {
330
-			return $memberOfGroups;
331
-		}
332
-		$groupDNs = $this->access->readAttribute($this->getDN(), 'memberOf');
333
-		$this->connection->writeToCache($cacheKey, $groupDNs);
334
-		return $groupDNs;
335
-	}
336
-
337
-	/**
338
-	 * @brief reads the image from LDAP that shall be used as Avatar
339
-	 * @return string data (provided by LDAP) | false
340
-	 */
341
-	public function getAvatarImage() {
342
-		if(!is_null($this->avatarImage)) {
343
-			return $this->avatarImage;
344
-		}
345
-
346
-		$this->avatarImage = false;
347
-		$attributes = array('jpegPhoto', 'thumbnailPhoto');
348
-		foreach($attributes as $attribute) {
349
-			$result = $this->access->readAttribute($this->dn, $attribute);
350
-			if($result !== false && is_array($result) && isset($result[0])) {
351
-				$this->avatarImage = $result[0];
352
-				break;
353
-			}
354
-		}
355
-
356
-		return $this->avatarImage;
357
-	}
358
-
359
-	/**
360
-	 * @brief marks the user as having logged in at least once
361
-	 * @return null
362
-	 */
363
-	public function markLogin() {
364
-		$this->config->setUserValue(
365
-			$this->uid, 'user_ldap', self::USER_PREFKEY_FIRSTLOGIN, 1);
366
-	}
367
-
368
-	/**
369
-	 * @brief marks the time when user features like email have been updated
370
-	 * @return null
371
-	 */
372
-	public function markRefreshTime() {
373
-		$this->config->setUserValue(
374
-			$this->uid, 'user_ldap', self::USER_PREFKEY_LASTREFRESH, time());
375
-	}
376
-
377
-	/**
378
-	 * @brief checks whether user features needs to be updated again by
379
-	 * comparing the difference of time of the last refresh to now with the
380
-	 * desired interval
381
-	 * @return bool
382
-	 */
383
-	private function needsRefresh() {
384
-		$lastChecked = $this->config->getUserValue($this->uid, 'user_ldap',
385
-			self::USER_PREFKEY_LASTREFRESH, 0);
386
-
387
-		//TODO make interval configurable
388
-		if((time() - intval($lastChecked)) < 86400 ) {
389
-			return false;
390
-		}
391
-		return  true;
392
-	}
393
-
394
-	/**
395
-	 * Stores a key-value pair in relation to this user
396
-	 *
397
-	 * @param string $key
398
-	 * @param string $value
399
-	 */
400
-	private function store($key, $value) {
401
-		$this->config->setUserValue($this->uid, 'user_ldap', $key, $value);
402
-	}
403
-
404
-	/**
405
-	 * Composes the display name and stores it in the database. The final
406
-	 * display name is returned.
407
-	 *
408
-	 * @param string $displayName
409
-	 * @param string $displayName2
410
-	 * @returns string the effective display name
411
-	 */
412
-	public function composeAndStoreDisplayName($displayName, $displayName2 = '') {
413
-		$displayName2 = strval($displayName2);
414
-		if($displayName2 !== '') {
415
-			$displayName .= ' (' . $displayName2 . ')';
416
-		}
417
-		$this->store('displayName', $displayName);
418
-		return $displayName;
419
-	}
420
-
421
-	/**
422
-	 * Stores the LDAP Username in the Database
423
-	 * @param string $userName
424
-	 */
425
-	public function storeLDAPUserName($userName) {
426
-		$this->store('uid', $userName);
427
-	}
428
-
429
-	/**
430
-	 * @brief checks whether an update method specified by feature was run
431
-	 * already. If not, it will marked like this, because it is expected that
432
-	 * the method will be run, when false is returned.
433
-	 * @param string $feature email | quota | avatar (can be extended)
434
-	 * @return bool
435
-	 */
436
-	private function wasRefreshed($feature) {
437
-		if(isset($this->refreshedFeatures[$feature])) {
438
-			return true;
439
-		}
440
-		$this->refreshedFeatures[$feature] = 1;
441
-		return false;
442
-	}
443
-
444
-	/**
445
-	 * fetches the email from LDAP and stores it as Nextcloud user value
446
-	 * @param string $valueFromLDAP if known, to save an LDAP read request
447
-	 * @return null
448
-	 */
449
-	public function updateEmail($valueFromLDAP = null) {
450
-		if($this->wasRefreshed('email')) {
451
-			return;
452
-		}
453
-		$email = strval($valueFromLDAP);
454
-		if(is_null($valueFromLDAP)) {
455
-			$emailAttribute = $this->connection->ldapEmailAttribute;
456
-			if ($emailAttribute !== '') {
457
-				$aEmail = $this->access->readAttribute($this->dn, $emailAttribute);
458
-				if(is_array($aEmail) && (count($aEmail) > 0)) {
459
-					$email = strval($aEmail[0]);
460
-				}
461
-			}
462
-		}
463
-		if ($email !== '') {
464
-			$user = $this->userManager->get($this->uid);
465
-			if (!is_null($user)) {
466
-				$currentEmail = strval($user->getEMailAddress());
467
-				if ($currentEmail !== $email) {
468
-					$user->setEMailAddress($email);
469
-				}
470
-			}
471
-		}
472
-	}
473
-
474
-	/**
475
-	 * Overall process goes as follow:
476
-	 * 1. fetch the quota from LDAP and check if it's parseable with the "verifyQuotaValue" function
477
-	 * 2. if the value can't be fetched, is empty or not parseable, use the default LDAP quota
478
-	 * 3. if the default LDAP quota can't be parsed, use the Nextcloud's default quota (use 'default')
479
-	 * 4. check if the target user exists and set the quota for the user.
480
-	 *
481
-	 * In order to improve performance and prevent an unwanted extra LDAP call, the $valueFromLDAP
482
-	 * parameter can be passed with the value of the attribute. This value will be considered as the
483
-	 * quota for the user coming from the LDAP server (step 1 of the process) It can be useful to
484
-	 * fetch all the user's attributes in one call and use the fetched values in this function.
485
-	 * The expected value for that parameter is a string describing the quota for the user. Valid
486
-	 * values are 'none' (unlimited), 'default' (the Nextcloud's default quota), '1234' (quota in
487
-	 * bytes), '1234 MB' (quota in MB - check the \OC_Helper::computerFileSize method for more info)
488
-	 *
489
-	 * fetches the quota from LDAP and stores it as Nextcloud user value
490
-	 * @param string $valueFromLDAP the quota attribute's value can be passed,
491
-	 * to save the readAttribute request
492
-	 * @return null
493
-	 */
494
-	public function updateQuota($valueFromLDAP = null) {
495
-		if($this->wasRefreshed('quota')) {
496
-			return;
497
-		}
498
-
499
-		$quota = false;
500
-		if(is_null($valueFromLDAP)) {
501
-			$quotaAttribute = $this->connection->ldapQuotaAttribute;
502
-			if ($quotaAttribute !== '') {
503
-				$aQuota = $this->access->readAttribute($this->dn, $quotaAttribute);
504
-				if($aQuota && (count($aQuota) > 0)) {
505
-					if ($this->verifyQuotaValue($aQuota[0])) {
506
-						$quota = $aQuota[0];
507
-					} else {
508
-						$this->log->log('not suitable LDAP quota found for user ' . $this->uid . ': [' . $aQuota[0] . ']', \OCP\Util::WARN);
509
-					}
510
-				}
511
-			}
512
-		} else {
513
-			if ($this->verifyQuotaValue($valueFromLDAP)) {
514
-				$quota = $valueFromLDAP;
515
-			} else {
516
-				$this->log->log('not suitable LDAP quota found for user ' . $this->uid . ': [' . $valueFromLDAP . ']', \OCP\Util::WARN);
517
-			}
518
-		}
519
-
520
-		if ($quota === false) {
521
-			// quota not found using the LDAP attribute (or not parseable). Try the default quota
522
-			$defaultQuota = $this->connection->ldapQuotaDefault;
523
-			if ($this->verifyQuotaValue($defaultQuota)) {
524
-				$quota = $defaultQuota;
525
-			}
526
-		}
527
-
528
-		$targetUser = $this->userManager->get($this->uid);
529
-		if ($targetUser) {
530
-			if($quota !== false) {
531
-				$targetUser->setQuota($quota);
532
-			} else {
533
-				$this->log->log('not suitable default quota found for user ' . $this->uid . ': [' . $defaultQuota . ']', \OCP\Util::WARN);
534
-			}
535
-		} else {
536
-			$this->log->log('trying to set a quota for user ' . $this->uid . ' but the user is missing', \OCP\Util::ERROR);
537
-		}
538
-	}
539
-
540
-	private function verifyQuotaValue($quotaValue) {
541
-		return $quotaValue === 'none' || $quotaValue === 'default' || \OC_Helper::computerFileSize($quotaValue) !== false;
542
-	}
543
-
544
-	/**
545
-	 * called by a post_login hook to save the avatar picture
546
-	 *
547
-	 * @param array $params
548
-	 */
549
-	public function updateAvatarPostLogin($params) {
550
-		if(isset($params['uid']) && $params['uid'] === $this->getUsername()) {
551
-			$this->updateAvatar();
552
-		}
553
-	}
554
-
555
-	/**
556
-	 * @brief attempts to get an image from LDAP and sets it as Nextcloud avatar
557
-	 * @return null
558
-	 */
559
-	public function updateAvatar() {
560
-		if($this->wasRefreshed('avatar')) {
561
-			return;
562
-		}
563
-		$avatarImage = $this->getAvatarImage();
564
-		if($avatarImage === false) {
565
-			//not set, nothing left to do;
566
-			return;
567
-		}
568
-		$this->image->loadFromBase64(base64_encode($avatarImage));
569
-		$this->setOwnCloudAvatar();
570
-	}
571
-
572
-	/**
573
-	 * @brief sets an image as Nextcloud avatar
574
-	 * @return null
575
-	 */
576
-	private function setOwnCloudAvatar() {
577
-		if(!$this->image->valid()) {
578
-			$this->log->log('jpegPhoto data invalid for '.$this->dn, \OCP\Util::ERROR);
579
-			return;
580
-		}
581
-		//make sure it is a square and not bigger than 128x128
582
-		$size = min(array($this->image->width(), $this->image->height(), 128));
583
-		if(!$this->image->centerCrop($size)) {
584
-			$this->log->log('croping image for avatar failed for '.$this->dn, \OCP\Util::ERROR);
585
-			return;
586
-		}
587
-
588
-		if(!$this->fs->isLoaded()) {
589
-			$this->fs->setup($this->uid);
590
-		}
591
-
592
-		try {
593
-			$avatar = $this->avatarManager->getAvatar($this->uid);
594
-			$avatar->set($this->image);
595
-		} catch (\Exception $e) {
596
-			\OC::$server->getLogger()->notice(
597
-				'Could not set avatar for ' . $this->dn	. ', because: ' . $e->getMessage(),
598
-				['app' => 'user_ldap']);
599
-		}
600
-	}
601
-
602
-	/**
603
-	 * called by a post_login hook to handle password expiry
604
-	 *
605
-	 * @param array $params
606
-	 */
607
-	public function handlePasswordExpiry($params) {
608
-		$ppolicyDN = $this->connection->ldapDefaultPPolicyDN;
609
-		if (empty($ppolicyDN) || (intval($this->connection->turnOnPasswordChange) !== 1)) {
610
-			return;//password expiry handling disabled
611
-		}
612
-		$uid = $params['uid'];
613
-		if(isset($uid) && $uid === $this->getUsername()) {
614
-			//retrieve relevant user attributes
615
-			$result = $this->access->search('objectclass=*', $this->dn, ['pwdpolicysubentry', 'pwdgraceusetime', 'pwdreset', 'pwdchangedtime']);
124
+        if ($username === null) {
125
+            $log->log("uid for '$dn' must not be null!", Util::ERROR);
126
+            throw new \InvalidArgumentException('uid must not be null!');
127
+        } else if ($username === '') {
128
+            $log->log("uid for '$dn' must not be an empty string", Util::ERROR);
129
+            throw new \InvalidArgumentException('uid must not be an empty string!');
130
+        }
131
+
132
+        $this->access              = $access;
133
+        $this->connection          = $access->getConnection();
134
+        $this->config              = $config;
135
+        $this->fs                  = $fs;
136
+        $this->dn                  = $dn;
137
+        $this->uid                 = $username;
138
+        $this->image               = $image;
139
+        $this->log                 = $log;
140
+        $this->avatarManager       = $avatarManager;
141
+        $this->userManager         = $userManager;
142
+        $this->notificationManager = $notificationManager;
143
+
144
+        \OCP\Util::connectHook('OC_User', 'post_login', $this, 'handlePasswordExpiry');
145
+    }
146
+
147
+    /**
148
+     * @brief updates properties like email, quota or avatar provided by LDAP
149
+     * @return null
150
+     */
151
+    public function update() {
152
+        if(is_null($this->dn)) {
153
+            return null;
154
+        }
155
+
156
+        $hasLoggedIn = $this->config->getUserValue($this->uid, 'user_ldap',
157
+                self::USER_PREFKEY_FIRSTLOGIN, 0);
158
+
159
+        if($this->needsRefresh()) {
160
+            $this->updateEmail();
161
+            $this->updateQuota();
162
+            if($hasLoggedIn !== 0) {
163
+                //we do not need to try it, when the user has not been logged in
164
+                //before, because the file system will not be ready.
165
+                $this->updateAvatar();
166
+                //in order to get an avatar as soon as possible, mark the user
167
+                //as refreshed only when updating the avatar did happen
168
+                $this->markRefreshTime();
169
+            }
170
+        }
171
+    }
172
+
173
+    /**
174
+     * processes results from LDAP for attributes as returned by getAttributesToRead()
175
+     * @param array $ldapEntry the user entry as retrieved from LDAP
176
+     */
177
+    public function processAttributes($ldapEntry) {
178
+        $this->markRefreshTime();
179
+        //Quota
180
+        $attr = strtolower($this->connection->ldapQuotaAttribute);
181
+        if(isset($ldapEntry[$attr])) {
182
+            $this->updateQuota($ldapEntry[$attr][0]);
183
+        } else {
184
+            if ($this->connection->ldapQuotaDefault !== '') {
185
+                $this->updateQuota();
186
+            }
187
+        }
188
+        unset($attr);
189
+
190
+        //displayName
191
+        $displayName = $displayName2 = '';
192
+        $attr = strtolower($this->connection->ldapUserDisplayName);
193
+        if(isset($ldapEntry[$attr])) {
194
+            $displayName = strval($ldapEntry[$attr][0]);
195
+        }
196
+        $attr = strtolower($this->connection->ldapUserDisplayName2);
197
+        if(isset($ldapEntry[$attr])) {
198
+            $displayName2 = strval($ldapEntry[$attr][0]);
199
+        }
200
+        if ($displayName !== '') {
201
+            $this->composeAndStoreDisplayName($displayName);
202
+            $this->access->cacheUserDisplayName(
203
+                $this->getUsername(),
204
+                $displayName,
205
+                $displayName2
206
+            );
207
+        }
208
+        unset($attr);
209
+
210
+        //Email
211
+        //email must be stored after displayname, because it would cause a user
212
+        //change event that will trigger fetching the display name again
213
+        $attr = strtolower($this->connection->ldapEmailAttribute);
214
+        if(isset($ldapEntry[$attr])) {
215
+            $this->updateEmail($ldapEntry[$attr][0]);
216
+        }
217
+        unset($attr);
218
+
219
+        // LDAP Username, needed for s2s sharing
220
+        if(isset($ldapEntry['uid'])) {
221
+            $this->storeLDAPUserName($ldapEntry['uid'][0]);
222
+        } else if(isset($ldapEntry['samaccountname'])) {
223
+            $this->storeLDAPUserName($ldapEntry['samaccountname'][0]);
224
+        }
225
+
226
+        //homePath
227
+        if(strpos($this->connection->homeFolderNamingRule, 'attr:') === 0) {
228
+            $attr = strtolower(substr($this->connection->homeFolderNamingRule, strlen('attr:')));
229
+            if(isset($ldapEntry[$attr])) {
230
+                $this->access->cacheUserHome(
231
+                    $this->getUsername(), $this->getHomePath($ldapEntry[$attr][0]));
232
+            }
233
+        }
234
+
235
+        //memberOf groups
236
+        $cacheKey = 'getMemberOf'.$this->getUsername();
237
+        $groups = false;
238
+        if(isset($ldapEntry['memberof'])) {
239
+            $groups = $ldapEntry['memberof'];
240
+        }
241
+        $this->connection->writeToCache($cacheKey, $groups);
242
+
243
+        //Avatar
244
+        $attrs = array('jpegphoto', 'thumbnailphoto');
245
+        foreach ($attrs as $attr)  {
246
+            if(isset($ldapEntry[$attr])) {
247
+                $this->avatarImage = $ldapEntry[$attr][0];
248
+                // the call to the method that saves the avatar in the file
249
+                // system must be postponed after the login. It is to ensure
250
+                // external mounts are mounted properly (e.g. with login
251
+                // credentials from the session).
252
+                \OCP\Util::connectHook('OC_User', 'post_login', $this, 'updateAvatarPostLogin');
253
+                break;
254
+            }
255
+        }
256
+    }
257
+
258
+    /**
259
+     * @brief returns the LDAP DN of the user
260
+     * @return string
261
+     */
262
+    public function getDN() {
263
+        return $this->dn;
264
+    }
265
+
266
+    /**
267
+     * @brief returns the Nextcloud internal username of the user
268
+     * @return string
269
+     */
270
+    public function getUsername() {
271
+        return $this->uid;
272
+    }
273
+
274
+    /**
275
+     * returns the home directory of the user if specified by LDAP settings
276
+     * @param string $valueFromLDAP
277
+     * @return bool|string
278
+     * @throws \Exception
279
+     */
280
+    public function getHomePath($valueFromLDAP = null) {
281
+        $path = strval($valueFromLDAP);
282
+        $attr = null;
283
+
284
+        if (is_null($valueFromLDAP)
285
+           && strpos($this->access->connection->homeFolderNamingRule, 'attr:') === 0
286
+           && $this->access->connection->homeFolderNamingRule !== 'attr:')
287
+        {
288
+            $attr = substr($this->access->connection->homeFolderNamingRule, strlen('attr:'));
289
+            $homedir = $this->access->readAttribute(
290
+                $this->access->username2dn($this->getUsername()), $attr);
291
+            if ($homedir && isset($homedir[0])) {
292
+                $path = $homedir[0];
293
+            }
294
+        }
295
+
296
+        if ($path !== '') {
297
+            //if attribute's value is an absolute path take this, otherwise append it to data dir
298
+            //check for / at the beginning or pattern c:\ resp. c:/
299
+            if(   '/' !== $path[0]
300
+               && !(3 < strlen($path) && ctype_alpha($path[0])
301
+                   && $path[1] === ':' && ('\\' === $path[2] || '/' === $path[2]))
302
+            ) {
303
+                $path = $this->config->getSystemValue('datadirectory',
304
+                        \OC::$SERVERROOT.'/data' ) . '/' . $path;
305
+            }
306
+            //we need it to store it in the DB as well in case a user gets
307
+            //deleted so we can clean up afterwards
308
+            $this->config->setUserValue(
309
+                $this->getUsername(), 'user_ldap', 'homePath', $path
310
+            );
311
+            return $path;
312
+        }
313
+
314
+        if(    !is_null($attr)
315
+            && $this->config->getAppValue('user_ldap', 'enforce_home_folder_naming_rule', true)
316
+        ) {
317
+            // a naming rule attribute is defined, but it doesn't exist for that LDAP user
318
+            throw new \Exception('Home dir attribute can\'t be read from LDAP for uid: ' . $this->getUsername());
319
+        }
320
+
321
+        //false will apply default behaviour as defined and done by OC_User
322
+        $this->config->setUserValue($this->getUsername(), 'user_ldap', 'homePath', '');
323
+        return false;
324
+    }
325
+
326
+    public function getMemberOfGroups() {
327
+        $cacheKey = 'getMemberOf'.$this->getUsername();
328
+        $memberOfGroups = $this->connection->getFromCache($cacheKey);
329
+        if(!is_null($memberOfGroups)) {
330
+            return $memberOfGroups;
331
+        }
332
+        $groupDNs = $this->access->readAttribute($this->getDN(), 'memberOf');
333
+        $this->connection->writeToCache($cacheKey, $groupDNs);
334
+        return $groupDNs;
335
+    }
336
+
337
+    /**
338
+     * @brief reads the image from LDAP that shall be used as Avatar
339
+     * @return string data (provided by LDAP) | false
340
+     */
341
+    public function getAvatarImage() {
342
+        if(!is_null($this->avatarImage)) {
343
+            return $this->avatarImage;
344
+        }
345
+
346
+        $this->avatarImage = false;
347
+        $attributes = array('jpegPhoto', 'thumbnailPhoto');
348
+        foreach($attributes as $attribute) {
349
+            $result = $this->access->readAttribute($this->dn, $attribute);
350
+            if($result !== false && is_array($result) && isset($result[0])) {
351
+                $this->avatarImage = $result[0];
352
+                break;
353
+            }
354
+        }
355
+
356
+        return $this->avatarImage;
357
+    }
358
+
359
+    /**
360
+     * @brief marks the user as having logged in at least once
361
+     * @return null
362
+     */
363
+    public function markLogin() {
364
+        $this->config->setUserValue(
365
+            $this->uid, 'user_ldap', self::USER_PREFKEY_FIRSTLOGIN, 1);
366
+    }
367
+
368
+    /**
369
+     * @brief marks the time when user features like email have been updated
370
+     * @return null
371
+     */
372
+    public function markRefreshTime() {
373
+        $this->config->setUserValue(
374
+            $this->uid, 'user_ldap', self::USER_PREFKEY_LASTREFRESH, time());
375
+    }
376
+
377
+    /**
378
+     * @brief checks whether user features needs to be updated again by
379
+     * comparing the difference of time of the last refresh to now with the
380
+     * desired interval
381
+     * @return bool
382
+     */
383
+    private function needsRefresh() {
384
+        $lastChecked = $this->config->getUserValue($this->uid, 'user_ldap',
385
+            self::USER_PREFKEY_LASTREFRESH, 0);
386
+
387
+        //TODO make interval configurable
388
+        if((time() - intval($lastChecked)) < 86400 ) {
389
+            return false;
390
+        }
391
+        return  true;
392
+    }
393
+
394
+    /**
395
+     * Stores a key-value pair in relation to this user
396
+     *
397
+     * @param string $key
398
+     * @param string $value
399
+     */
400
+    private function store($key, $value) {
401
+        $this->config->setUserValue($this->uid, 'user_ldap', $key, $value);
402
+    }
403
+
404
+    /**
405
+     * Composes the display name and stores it in the database. The final
406
+     * display name is returned.
407
+     *
408
+     * @param string $displayName
409
+     * @param string $displayName2
410
+     * @returns string the effective display name
411
+     */
412
+    public function composeAndStoreDisplayName($displayName, $displayName2 = '') {
413
+        $displayName2 = strval($displayName2);
414
+        if($displayName2 !== '') {
415
+            $displayName .= ' (' . $displayName2 . ')';
416
+        }
417
+        $this->store('displayName', $displayName);
418
+        return $displayName;
419
+    }
420
+
421
+    /**
422
+     * Stores the LDAP Username in the Database
423
+     * @param string $userName
424
+     */
425
+    public function storeLDAPUserName($userName) {
426
+        $this->store('uid', $userName);
427
+    }
428
+
429
+    /**
430
+     * @brief checks whether an update method specified by feature was run
431
+     * already. If not, it will marked like this, because it is expected that
432
+     * the method will be run, when false is returned.
433
+     * @param string $feature email | quota | avatar (can be extended)
434
+     * @return bool
435
+     */
436
+    private function wasRefreshed($feature) {
437
+        if(isset($this->refreshedFeatures[$feature])) {
438
+            return true;
439
+        }
440
+        $this->refreshedFeatures[$feature] = 1;
441
+        return false;
442
+    }
443
+
444
+    /**
445
+     * fetches the email from LDAP and stores it as Nextcloud user value
446
+     * @param string $valueFromLDAP if known, to save an LDAP read request
447
+     * @return null
448
+     */
449
+    public function updateEmail($valueFromLDAP = null) {
450
+        if($this->wasRefreshed('email')) {
451
+            return;
452
+        }
453
+        $email = strval($valueFromLDAP);
454
+        if(is_null($valueFromLDAP)) {
455
+            $emailAttribute = $this->connection->ldapEmailAttribute;
456
+            if ($emailAttribute !== '') {
457
+                $aEmail = $this->access->readAttribute($this->dn, $emailAttribute);
458
+                if(is_array($aEmail) && (count($aEmail) > 0)) {
459
+                    $email = strval($aEmail[0]);
460
+                }
461
+            }
462
+        }
463
+        if ($email !== '') {
464
+            $user = $this->userManager->get($this->uid);
465
+            if (!is_null($user)) {
466
+                $currentEmail = strval($user->getEMailAddress());
467
+                if ($currentEmail !== $email) {
468
+                    $user->setEMailAddress($email);
469
+                }
470
+            }
471
+        }
472
+    }
473
+
474
+    /**
475
+     * Overall process goes as follow:
476
+     * 1. fetch the quota from LDAP and check if it's parseable with the "verifyQuotaValue" function
477
+     * 2. if the value can't be fetched, is empty or not parseable, use the default LDAP quota
478
+     * 3. if the default LDAP quota can't be parsed, use the Nextcloud's default quota (use 'default')
479
+     * 4. check if the target user exists and set the quota for the user.
480
+     *
481
+     * In order to improve performance and prevent an unwanted extra LDAP call, the $valueFromLDAP
482
+     * parameter can be passed with the value of the attribute. This value will be considered as the
483
+     * quota for the user coming from the LDAP server (step 1 of the process) It can be useful to
484
+     * fetch all the user's attributes in one call and use the fetched values in this function.
485
+     * The expected value for that parameter is a string describing the quota for the user. Valid
486
+     * values are 'none' (unlimited), 'default' (the Nextcloud's default quota), '1234' (quota in
487
+     * bytes), '1234 MB' (quota in MB - check the \OC_Helper::computerFileSize method for more info)
488
+     *
489
+     * fetches the quota from LDAP and stores it as Nextcloud user value
490
+     * @param string $valueFromLDAP the quota attribute's value can be passed,
491
+     * to save the readAttribute request
492
+     * @return null
493
+     */
494
+    public function updateQuota($valueFromLDAP = null) {
495
+        if($this->wasRefreshed('quota')) {
496
+            return;
497
+        }
498
+
499
+        $quota = false;
500
+        if(is_null($valueFromLDAP)) {
501
+            $quotaAttribute = $this->connection->ldapQuotaAttribute;
502
+            if ($quotaAttribute !== '') {
503
+                $aQuota = $this->access->readAttribute($this->dn, $quotaAttribute);
504
+                if($aQuota && (count($aQuota) > 0)) {
505
+                    if ($this->verifyQuotaValue($aQuota[0])) {
506
+                        $quota = $aQuota[0];
507
+                    } else {
508
+                        $this->log->log('not suitable LDAP quota found for user ' . $this->uid . ': [' . $aQuota[0] . ']', \OCP\Util::WARN);
509
+                    }
510
+                }
511
+            }
512
+        } else {
513
+            if ($this->verifyQuotaValue($valueFromLDAP)) {
514
+                $quota = $valueFromLDAP;
515
+            } else {
516
+                $this->log->log('not suitable LDAP quota found for user ' . $this->uid . ': [' . $valueFromLDAP . ']', \OCP\Util::WARN);
517
+            }
518
+        }
519
+
520
+        if ($quota === false) {
521
+            // quota not found using the LDAP attribute (or not parseable). Try the default quota
522
+            $defaultQuota = $this->connection->ldapQuotaDefault;
523
+            if ($this->verifyQuotaValue($defaultQuota)) {
524
+                $quota = $defaultQuota;
525
+            }
526
+        }
527
+
528
+        $targetUser = $this->userManager->get($this->uid);
529
+        if ($targetUser) {
530
+            if($quota !== false) {
531
+                $targetUser->setQuota($quota);
532
+            } else {
533
+                $this->log->log('not suitable default quota found for user ' . $this->uid . ': [' . $defaultQuota . ']', \OCP\Util::WARN);
534
+            }
535
+        } else {
536
+            $this->log->log('trying to set a quota for user ' . $this->uid . ' but the user is missing', \OCP\Util::ERROR);
537
+        }
538
+    }
539
+
540
+    private function verifyQuotaValue($quotaValue) {
541
+        return $quotaValue === 'none' || $quotaValue === 'default' || \OC_Helper::computerFileSize($quotaValue) !== false;
542
+    }
543
+
544
+    /**
545
+     * called by a post_login hook to save the avatar picture
546
+     *
547
+     * @param array $params
548
+     */
549
+    public function updateAvatarPostLogin($params) {
550
+        if(isset($params['uid']) && $params['uid'] === $this->getUsername()) {
551
+            $this->updateAvatar();
552
+        }
553
+    }
554
+
555
+    /**
556
+     * @brief attempts to get an image from LDAP and sets it as Nextcloud avatar
557
+     * @return null
558
+     */
559
+    public function updateAvatar() {
560
+        if($this->wasRefreshed('avatar')) {
561
+            return;
562
+        }
563
+        $avatarImage = $this->getAvatarImage();
564
+        if($avatarImage === false) {
565
+            //not set, nothing left to do;
566
+            return;
567
+        }
568
+        $this->image->loadFromBase64(base64_encode($avatarImage));
569
+        $this->setOwnCloudAvatar();
570
+    }
571
+
572
+    /**
573
+     * @brief sets an image as Nextcloud avatar
574
+     * @return null
575
+     */
576
+    private function setOwnCloudAvatar() {
577
+        if(!$this->image->valid()) {
578
+            $this->log->log('jpegPhoto data invalid for '.$this->dn, \OCP\Util::ERROR);
579
+            return;
580
+        }
581
+        //make sure it is a square and not bigger than 128x128
582
+        $size = min(array($this->image->width(), $this->image->height(), 128));
583
+        if(!$this->image->centerCrop($size)) {
584
+            $this->log->log('croping image for avatar failed for '.$this->dn, \OCP\Util::ERROR);
585
+            return;
586
+        }
587
+
588
+        if(!$this->fs->isLoaded()) {
589
+            $this->fs->setup($this->uid);
590
+        }
591
+
592
+        try {
593
+            $avatar = $this->avatarManager->getAvatar($this->uid);
594
+            $avatar->set($this->image);
595
+        } catch (\Exception $e) {
596
+            \OC::$server->getLogger()->notice(
597
+                'Could not set avatar for ' . $this->dn	. ', because: ' . $e->getMessage(),
598
+                ['app' => 'user_ldap']);
599
+        }
600
+    }
601
+
602
+    /**
603
+     * called by a post_login hook to handle password expiry
604
+     *
605
+     * @param array $params
606
+     */
607
+    public function handlePasswordExpiry($params) {
608
+        $ppolicyDN = $this->connection->ldapDefaultPPolicyDN;
609
+        if (empty($ppolicyDN) || (intval($this->connection->turnOnPasswordChange) !== 1)) {
610
+            return;//password expiry handling disabled
611
+        }
612
+        $uid = $params['uid'];
613
+        if(isset($uid) && $uid === $this->getUsername()) {
614
+            //retrieve relevant user attributes
615
+            $result = $this->access->search('objectclass=*', $this->dn, ['pwdpolicysubentry', 'pwdgraceusetime', 'pwdreset', 'pwdchangedtime']);
616 616
 			
617
-			if(array_key_exists('pwdpolicysubentry', $result[0])) {
618
-				$pwdPolicySubentry = $result[0]['pwdpolicysubentry'];
619
-				if($pwdPolicySubentry && (count($pwdPolicySubentry) > 0)){
620
-					$ppolicyDN = $pwdPolicySubentry[0];//custom ppolicy DN
621
-				}
622
-			}
617
+            if(array_key_exists('pwdpolicysubentry', $result[0])) {
618
+                $pwdPolicySubentry = $result[0]['pwdpolicysubentry'];
619
+                if($pwdPolicySubentry && (count($pwdPolicySubentry) > 0)){
620
+                    $ppolicyDN = $pwdPolicySubentry[0];//custom ppolicy DN
621
+                }
622
+            }
623 623
 			
624
-			$pwdGraceUseTime = array_key_exists('pwdgraceusetime', $result[0]) ? $result[0]['pwdgraceusetime'] : null;
625
-			$pwdReset = array_key_exists('pwdreset', $result[0]) ? $result[0]['pwdreset'] : null;
626
-			$pwdChangedTime = array_key_exists('pwdchangedtime', $result[0]) ? $result[0]['pwdchangedtime'] : null;
624
+            $pwdGraceUseTime = array_key_exists('pwdgraceusetime', $result[0]) ? $result[0]['pwdgraceusetime'] : null;
625
+            $pwdReset = array_key_exists('pwdreset', $result[0]) ? $result[0]['pwdreset'] : null;
626
+            $pwdChangedTime = array_key_exists('pwdchangedtime', $result[0]) ? $result[0]['pwdchangedtime'] : null;
627 627
 			
628
-			//retrieve relevant password policy attributes
629
-			$cacheKey = 'ppolicyAttributes' . $ppolicyDN;
630
-			$result = $this->connection->getFromCache($cacheKey);
631
-			if(is_null($result)) {
632
-				$result = $this->access->search('objectclass=*', $ppolicyDN, ['pwdgraceauthnlimit', 'pwdmaxage', 'pwdexpirewarning']);
633
-				$this->connection->writeToCache($cacheKey, $result);
634
-			}
628
+            //retrieve relevant password policy attributes
629
+            $cacheKey = 'ppolicyAttributes' . $ppolicyDN;
630
+            $result = $this->connection->getFromCache($cacheKey);
631
+            if(is_null($result)) {
632
+                $result = $this->access->search('objectclass=*', $ppolicyDN, ['pwdgraceauthnlimit', 'pwdmaxage', 'pwdexpirewarning']);
633
+                $this->connection->writeToCache($cacheKey, $result);
634
+            }
635 635
 			
636
-			$pwdGraceAuthNLimit = array_key_exists('pwdgraceauthnlimit', $result[0]) ? $result[0]['pwdgraceauthnlimit'] : null;
637
-			$pwdMaxAge = array_key_exists('pwdmaxage', $result[0]) ? $result[0]['pwdmaxage'] : null;
638
-			$pwdExpireWarning = array_key_exists('pwdexpirewarning', $result[0]) ? $result[0]['pwdexpirewarning'] : null;
636
+            $pwdGraceAuthNLimit = array_key_exists('pwdgraceauthnlimit', $result[0]) ? $result[0]['pwdgraceauthnlimit'] : null;
637
+            $pwdMaxAge = array_key_exists('pwdmaxage', $result[0]) ? $result[0]['pwdmaxage'] : null;
638
+            $pwdExpireWarning = array_key_exists('pwdexpirewarning', $result[0]) ? $result[0]['pwdexpirewarning'] : null;
639 639
 			
640
-			//handle grace login
641
-			$pwdGraceUseTimeCount = count($pwdGraceUseTime);
642
-			if($pwdGraceUseTime && $pwdGraceUseTimeCount > 0) { //was this a grace login?
643
-				if($pwdGraceAuthNLimit 
644
-					&& (count($pwdGraceAuthNLimit) > 0)
645
-					&&($pwdGraceUseTimeCount < intval($pwdGraceAuthNLimit[0]))) { //at least one more grace login available?
646
-					$this->config->setUserValue($uid, 'user_ldap', 'needsPasswordReset', 'true');
647
-					header('Location: '.\OC::$server->getURLGenerator()->linkToRouteAbsolute(
648
-					'user_ldap.renewPassword.showRenewPasswordForm', array('user' => $uid)));
649
-				} else { //no more grace login available
650
-					header('Location: '.\OC::$server->getURLGenerator()->linkToRouteAbsolute(
651
-					'user_ldap.renewPassword.showLoginFormInvalidPassword', array('user' => $uid)));
652
-				}
653
-				exit();
654
-			}
655
-			//handle pwdReset attribute
656
-			if($pwdReset && (count($pwdReset) > 0) && $pwdReset[0] === 'TRUE') { //user must change his password
657
-				$this->config->setUserValue($uid, 'user_ldap', 'needsPasswordReset', 'true');
658
-				header('Location: '.\OC::$server->getURLGenerator()->linkToRouteAbsolute(
659
-				'user_ldap.renewPassword.showRenewPasswordForm', array('user' => $uid)));
660
-				exit();
661
-			}
662
-			//handle password expiry warning
663
-			if($pwdChangedTime && (count($pwdChangedTime) > 0)) {
664
-				if($pwdMaxAge && (count($pwdMaxAge) > 0)
665
-					&& $pwdExpireWarning && (count($pwdExpireWarning) > 0)) {
666
-					$pwdMaxAgeInt = intval($pwdMaxAge[0]);
667
-					$pwdExpireWarningInt = intval($pwdExpireWarning[0]);
668
-					if($pwdMaxAgeInt > 0 && $pwdExpireWarningInt > 0){
669
-						$pwdChangedTimeDt = \DateTime::createFromFormat('YmdHisZ', $pwdChangedTime[0]);
670
-						$pwdChangedTimeDt->add(new \DateInterval('PT'.$pwdMaxAgeInt.'S'));
671
-						$currentDateTime = new \DateTime();
672
-						$secondsToExpiry = $pwdChangedTimeDt->getTimestamp() - $currentDateTime->getTimestamp();
673
-						if($secondsToExpiry <= $pwdExpireWarningInt) {
674
-							//remove last password expiry warning if any
675
-							$notification = $this->notificationManager->createNotification();
676
-							$notification->setApp('user_ldap')
677
-								->setUser($uid)
678
-								->setObject('pwd_exp_warn', $uid)
679
-							;
680
-							$this->notificationManager->markProcessed($notification);
681
-							//create new password expiry warning
682
-							$notification = $this->notificationManager->createNotification();
683
-							$notification->setApp('user_ldap')
684
-								->setUser($uid)
685
-								->setDateTime($currentDateTime)
686
-								->setObject('pwd_exp_warn', $uid) 
687
-								->setSubject('pwd_exp_warn_days', [(int) ceil($secondsToExpiry / 60 / 60 / 24)])
688
-							;
689
-							$this->notificationManager->notify($notification);
690
-						}
691
-					}
692
-				}
693
-			}
694
-		}
695
-	}
640
+            //handle grace login
641
+            $pwdGraceUseTimeCount = count($pwdGraceUseTime);
642
+            if($pwdGraceUseTime && $pwdGraceUseTimeCount > 0) { //was this a grace login?
643
+                if($pwdGraceAuthNLimit 
644
+                    && (count($pwdGraceAuthNLimit) > 0)
645
+                    &&($pwdGraceUseTimeCount < intval($pwdGraceAuthNLimit[0]))) { //at least one more grace login available?
646
+                    $this->config->setUserValue($uid, 'user_ldap', 'needsPasswordReset', 'true');
647
+                    header('Location: '.\OC::$server->getURLGenerator()->linkToRouteAbsolute(
648
+                    'user_ldap.renewPassword.showRenewPasswordForm', array('user' => $uid)));
649
+                } else { //no more grace login available
650
+                    header('Location: '.\OC::$server->getURLGenerator()->linkToRouteAbsolute(
651
+                    'user_ldap.renewPassword.showLoginFormInvalidPassword', array('user' => $uid)));
652
+                }
653
+                exit();
654
+            }
655
+            //handle pwdReset attribute
656
+            if($pwdReset && (count($pwdReset) > 0) && $pwdReset[0] === 'TRUE') { //user must change his password
657
+                $this->config->setUserValue($uid, 'user_ldap', 'needsPasswordReset', 'true');
658
+                header('Location: '.\OC::$server->getURLGenerator()->linkToRouteAbsolute(
659
+                'user_ldap.renewPassword.showRenewPasswordForm', array('user' => $uid)));
660
+                exit();
661
+            }
662
+            //handle password expiry warning
663
+            if($pwdChangedTime && (count($pwdChangedTime) > 0)) {
664
+                if($pwdMaxAge && (count($pwdMaxAge) > 0)
665
+                    && $pwdExpireWarning && (count($pwdExpireWarning) > 0)) {
666
+                    $pwdMaxAgeInt = intval($pwdMaxAge[0]);
667
+                    $pwdExpireWarningInt = intval($pwdExpireWarning[0]);
668
+                    if($pwdMaxAgeInt > 0 && $pwdExpireWarningInt > 0){
669
+                        $pwdChangedTimeDt = \DateTime::createFromFormat('YmdHisZ', $pwdChangedTime[0]);
670
+                        $pwdChangedTimeDt->add(new \DateInterval('PT'.$pwdMaxAgeInt.'S'));
671
+                        $currentDateTime = new \DateTime();
672
+                        $secondsToExpiry = $pwdChangedTimeDt->getTimestamp() - $currentDateTime->getTimestamp();
673
+                        if($secondsToExpiry <= $pwdExpireWarningInt) {
674
+                            //remove last password expiry warning if any
675
+                            $notification = $this->notificationManager->createNotification();
676
+                            $notification->setApp('user_ldap')
677
+                                ->setUser($uid)
678
+                                ->setObject('pwd_exp_warn', $uid)
679
+                            ;
680
+                            $this->notificationManager->markProcessed($notification);
681
+                            //create new password expiry warning
682
+                            $notification = $this->notificationManager->createNotification();
683
+                            $notification->setApp('user_ldap')
684
+                                ->setUser($uid)
685
+                                ->setDateTime($currentDateTime)
686
+                                ->setObject('pwd_exp_warn', $uid) 
687
+                                ->setSubject('pwd_exp_warn_days', [(int) ceil($secondsToExpiry / 60 / 60 / 24)])
688
+                            ;
689
+                            $this->notificationManager->notify($notification);
690
+                        }
691
+                    }
692
+                }
693
+            }
694
+        }
695
+    }
696 696
 }
Please login to merge, or discard this patch.
Spacing   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -149,17 +149,17 @@  discard block
 block discarded – undo
149 149
 	 * @return null
150 150
 	 */
151 151
 	public function update() {
152
-		if(is_null($this->dn)) {
152
+		if (is_null($this->dn)) {
153 153
 			return null;
154 154
 		}
155 155
 
156 156
 		$hasLoggedIn = $this->config->getUserValue($this->uid, 'user_ldap',
157 157
 				self::USER_PREFKEY_FIRSTLOGIN, 0);
158 158
 
159
-		if($this->needsRefresh()) {
159
+		if ($this->needsRefresh()) {
160 160
 			$this->updateEmail();
161 161
 			$this->updateQuota();
162
-			if($hasLoggedIn !== 0) {
162
+			if ($hasLoggedIn !== 0) {
163 163
 				//we do not need to try it, when the user has not been logged in
164 164
 				//before, because the file system will not be ready.
165 165
 				$this->updateAvatar();
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
 		$this->markRefreshTime();
179 179
 		//Quota
180 180
 		$attr = strtolower($this->connection->ldapQuotaAttribute);
181
-		if(isset($ldapEntry[$attr])) {
181
+		if (isset($ldapEntry[$attr])) {
182 182
 			$this->updateQuota($ldapEntry[$attr][0]);
183 183
 		} else {
184 184
 			if ($this->connection->ldapQuotaDefault !== '') {
@@ -190,11 +190,11 @@  discard block
 block discarded – undo
190 190
 		//displayName
191 191
 		$displayName = $displayName2 = '';
192 192
 		$attr = strtolower($this->connection->ldapUserDisplayName);
193
-		if(isset($ldapEntry[$attr])) {
193
+		if (isset($ldapEntry[$attr])) {
194 194
 			$displayName = strval($ldapEntry[$attr][0]);
195 195
 		}
196 196
 		$attr = strtolower($this->connection->ldapUserDisplayName2);
197
-		if(isset($ldapEntry[$attr])) {
197
+		if (isset($ldapEntry[$attr])) {
198 198
 			$displayName2 = strval($ldapEntry[$attr][0]);
199 199
 		}
200 200
 		if ($displayName !== '') {
@@ -211,22 +211,22 @@  discard block
 block discarded – undo
211 211
 		//email must be stored after displayname, because it would cause a user
212 212
 		//change event that will trigger fetching the display name again
213 213
 		$attr = strtolower($this->connection->ldapEmailAttribute);
214
-		if(isset($ldapEntry[$attr])) {
214
+		if (isset($ldapEntry[$attr])) {
215 215
 			$this->updateEmail($ldapEntry[$attr][0]);
216 216
 		}
217 217
 		unset($attr);
218 218
 
219 219
 		// LDAP Username, needed for s2s sharing
220
-		if(isset($ldapEntry['uid'])) {
220
+		if (isset($ldapEntry['uid'])) {
221 221
 			$this->storeLDAPUserName($ldapEntry['uid'][0]);
222
-		} else if(isset($ldapEntry['samaccountname'])) {
222
+		} else if (isset($ldapEntry['samaccountname'])) {
223 223
 			$this->storeLDAPUserName($ldapEntry['samaccountname'][0]);
224 224
 		}
225 225
 
226 226
 		//homePath
227
-		if(strpos($this->connection->homeFolderNamingRule, 'attr:') === 0) {
227
+		if (strpos($this->connection->homeFolderNamingRule, 'attr:') === 0) {
228 228
 			$attr = strtolower(substr($this->connection->homeFolderNamingRule, strlen('attr:')));
229
-			if(isset($ldapEntry[$attr])) {
229
+			if (isset($ldapEntry[$attr])) {
230 230
 				$this->access->cacheUserHome(
231 231
 					$this->getUsername(), $this->getHomePath($ldapEntry[$attr][0]));
232 232
 			}
@@ -235,15 +235,15 @@  discard block
 block discarded – undo
235 235
 		//memberOf groups
236 236
 		$cacheKey = 'getMemberOf'.$this->getUsername();
237 237
 		$groups = false;
238
-		if(isset($ldapEntry['memberof'])) {
238
+		if (isset($ldapEntry['memberof'])) {
239 239
 			$groups = $ldapEntry['memberof'];
240 240
 		}
241 241
 		$this->connection->writeToCache($cacheKey, $groups);
242 242
 
243 243
 		//Avatar
244 244
 		$attrs = array('jpegphoto', 'thumbnailphoto');
245
-		foreach ($attrs as $attr)  {
246
-			if(isset($ldapEntry[$attr])) {
245
+		foreach ($attrs as $attr) {
246
+			if (isset($ldapEntry[$attr])) {
247 247
 				$this->avatarImage = $ldapEntry[$attr][0];
248 248
 				// the call to the method that saves the avatar in the file
249 249
 				// system must be postponed after the login. It is to ensure
@@ -296,12 +296,12 @@  discard block
 block discarded – undo
296 296
 		if ($path !== '') {
297 297
 			//if attribute's value is an absolute path take this, otherwise append it to data dir
298 298
 			//check for / at the beginning or pattern c:\ resp. c:/
299
-			if(   '/' !== $path[0]
299
+			if ('/' !== $path[0]
300 300
 			   && !(3 < strlen($path) && ctype_alpha($path[0])
301 301
 			       && $path[1] === ':' && ('\\' === $path[2] || '/' === $path[2]))
302 302
 			) {
303 303
 				$path = $this->config->getSystemValue('datadirectory',
304
-						\OC::$SERVERROOT.'/data' ) . '/' . $path;
304
+						\OC::$SERVERROOT.'/data').'/'.$path;
305 305
 			}
306 306
 			//we need it to store it in the DB as well in case a user gets
307 307
 			//deleted so we can clean up afterwards
@@ -311,11 +311,11 @@  discard block
 block discarded – undo
311 311
 			return $path;
312 312
 		}
313 313
 
314
-		if(    !is_null($attr)
314
+		if (!is_null($attr)
315 315
 			&& $this->config->getAppValue('user_ldap', 'enforce_home_folder_naming_rule', true)
316 316
 		) {
317 317
 			// a naming rule attribute is defined, but it doesn't exist for that LDAP user
318
-			throw new \Exception('Home dir attribute can\'t be read from LDAP for uid: ' . $this->getUsername());
318
+			throw new \Exception('Home dir attribute can\'t be read from LDAP for uid: '.$this->getUsername());
319 319
 		}
320 320
 
321 321
 		//false will apply default behaviour as defined and done by OC_User
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
 	public function getMemberOfGroups() {
327 327
 		$cacheKey = 'getMemberOf'.$this->getUsername();
328 328
 		$memberOfGroups = $this->connection->getFromCache($cacheKey);
329
-		if(!is_null($memberOfGroups)) {
329
+		if (!is_null($memberOfGroups)) {
330 330
 			return $memberOfGroups;
331 331
 		}
332 332
 		$groupDNs = $this->access->readAttribute($this->getDN(), 'memberOf');
@@ -339,15 +339,15 @@  discard block
 block discarded – undo
339 339
 	 * @return string data (provided by LDAP) | false
340 340
 	 */
341 341
 	public function getAvatarImage() {
342
-		if(!is_null($this->avatarImage)) {
342
+		if (!is_null($this->avatarImage)) {
343 343
 			return $this->avatarImage;
344 344
 		}
345 345
 
346 346
 		$this->avatarImage = false;
347 347
 		$attributes = array('jpegPhoto', 'thumbnailPhoto');
348
-		foreach($attributes as $attribute) {
348
+		foreach ($attributes as $attribute) {
349 349
 			$result = $this->access->readAttribute($this->dn, $attribute);
350
-			if($result !== false && is_array($result) && isset($result[0])) {
350
+			if ($result !== false && is_array($result) && isset($result[0])) {
351 351
 				$this->avatarImage = $result[0];
352 352
 				break;
353 353
 			}
@@ -385,7 +385,7 @@  discard block
 block discarded – undo
385 385
 			self::USER_PREFKEY_LASTREFRESH, 0);
386 386
 
387 387
 		//TODO make interval configurable
388
-		if((time() - intval($lastChecked)) < 86400 ) {
388
+		if ((time() - intval($lastChecked)) < 86400) {
389 389
 			return false;
390 390
 		}
391 391
 		return  true;
@@ -411,8 +411,8 @@  discard block
 block discarded – undo
411 411
 	 */
412 412
 	public function composeAndStoreDisplayName($displayName, $displayName2 = '') {
413 413
 		$displayName2 = strval($displayName2);
414
-		if($displayName2 !== '') {
415
-			$displayName .= ' (' . $displayName2 . ')';
414
+		if ($displayName2 !== '') {
415
+			$displayName .= ' ('.$displayName2.')';
416 416
 		}
417 417
 		$this->store('displayName', $displayName);
418 418
 		return $displayName;
@@ -434,7 +434,7 @@  discard block
 block discarded – undo
434 434
 	 * @return bool
435 435
 	 */
436 436
 	private function wasRefreshed($feature) {
437
-		if(isset($this->refreshedFeatures[$feature])) {
437
+		if (isset($this->refreshedFeatures[$feature])) {
438 438
 			return true;
439 439
 		}
440 440
 		$this->refreshedFeatures[$feature] = 1;
@@ -447,15 +447,15 @@  discard block
 block discarded – undo
447 447
 	 * @return null
448 448
 	 */
449 449
 	public function updateEmail($valueFromLDAP = null) {
450
-		if($this->wasRefreshed('email')) {
450
+		if ($this->wasRefreshed('email')) {
451 451
 			return;
452 452
 		}
453 453
 		$email = strval($valueFromLDAP);
454
-		if(is_null($valueFromLDAP)) {
454
+		if (is_null($valueFromLDAP)) {
455 455
 			$emailAttribute = $this->connection->ldapEmailAttribute;
456 456
 			if ($emailAttribute !== '') {
457 457
 				$aEmail = $this->access->readAttribute($this->dn, $emailAttribute);
458
-				if(is_array($aEmail) && (count($aEmail) > 0)) {
458
+				if (is_array($aEmail) && (count($aEmail) > 0)) {
459 459
 					$email = strval($aEmail[0]);
460 460
 				}
461 461
 			}
@@ -492,20 +492,20 @@  discard block
 block discarded – undo
492 492
 	 * @return null
493 493
 	 */
494 494
 	public function updateQuota($valueFromLDAP = null) {
495
-		if($this->wasRefreshed('quota')) {
495
+		if ($this->wasRefreshed('quota')) {
496 496
 			return;
497 497
 		}
498 498
 
499 499
 		$quota = false;
500
-		if(is_null($valueFromLDAP)) {
500
+		if (is_null($valueFromLDAP)) {
501 501
 			$quotaAttribute = $this->connection->ldapQuotaAttribute;
502 502
 			if ($quotaAttribute !== '') {
503 503
 				$aQuota = $this->access->readAttribute($this->dn, $quotaAttribute);
504
-				if($aQuota && (count($aQuota) > 0)) {
504
+				if ($aQuota && (count($aQuota) > 0)) {
505 505
 					if ($this->verifyQuotaValue($aQuota[0])) {
506 506
 						$quota = $aQuota[0];
507 507
 					} else {
508
-						$this->log->log('not suitable LDAP quota found for user ' . $this->uid . ': [' . $aQuota[0] . ']', \OCP\Util::WARN);
508
+						$this->log->log('not suitable LDAP quota found for user '.$this->uid.': ['.$aQuota[0].']', \OCP\Util::WARN);
509 509
 					}
510 510
 				}
511 511
 			}
@@ -513,7 +513,7 @@  discard block
 block discarded – undo
513 513
 			if ($this->verifyQuotaValue($valueFromLDAP)) {
514 514
 				$quota = $valueFromLDAP;
515 515
 			} else {
516
-				$this->log->log('not suitable LDAP quota found for user ' . $this->uid . ': [' . $valueFromLDAP . ']', \OCP\Util::WARN);
516
+				$this->log->log('not suitable LDAP quota found for user '.$this->uid.': ['.$valueFromLDAP.']', \OCP\Util::WARN);
517 517
 			}
518 518
 		}
519 519
 
@@ -527,13 +527,13 @@  discard block
 block discarded – undo
527 527
 
528 528
 		$targetUser = $this->userManager->get($this->uid);
529 529
 		if ($targetUser) {
530
-			if($quota !== false) {
530
+			if ($quota !== false) {
531 531
 				$targetUser->setQuota($quota);
532 532
 			} else {
533
-				$this->log->log('not suitable default quota found for user ' . $this->uid . ': [' . $defaultQuota . ']', \OCP\Util::WARN);
533
+				$this->log->log('not suitable default quota found for user '.$this->uid.': ['.$defaultQuota.']', \OCP\Util::WARN);
534 534
 			}
535 535
 		} else {
536
-			$this->log->log('trying to set a quota for user ' . $this->uid . ' but the user is missing', \OCP\Util::ERROR);
536
+			$this->log->log('trying to set a quota for user '.$this->uid.' but the user is missing', \OCP\Util::ERROR);
537 537
 		}
538 538
 	}
539 539
 
@@ -547,7 +547,7 @@  discard block
 block discarded – undo
547 547
 	 * @param array $params
548 548
 	 */
549 549
 	public function updateAvatarPostLogin($params) {
550
-		if(isset($params['uid']) && $params['uid'] === $this->getUsername()) {
550
+		if (isset($params['uid']) && $params['uid'] === $this->getUsername()) {
551 551
 			$this->updateAvatar();
552 552
 		}
553 553
 	}
@@ -557,11 +557,11 @@  discard block
 block discarded – undo
557 557
 	 * @return null
558 558
 	 */
559 559
 	public function updateAvatar() {
560
-		if($this->wasRefreshed('avatar')) {
560
+		if ($this->wasRefreshed('avatar')) {
561 561
 			return;
562 562
 		}
563 563
 		$avatarImage = $this->getAvatarImage();
564
-		if($avatarImage === false) {
564
+		if ($avatarImage === false) {
565 565
 			//not set, nothing left to do;
566 566
 			return;
567 567
 		}
@@ -574,18 +574,18 @@  discard block
 block discarded – undo
574 574
 	 * @return null
575 575
 	 */
576 576
 	private function setOwnCloudAvatar() {
577
-		if(!$this->image->valid()) {
577
+		if (!$this->image->valid()) {
578 578
 			$this->log->log('jpegPhoto data invalid for '.$this->dn, \OCP\Util::ERROR);
579 579
 			return;
580 580
 		}
581 581
 		//make sure it is a square and not bigger than 128x128
582 582
 		$size = min(array($this->image->width(), $this->image->height(), 128));
583
-		if(!$this->image->centerCrop($size)) {
583
+		if (!$this->image->centerCrop($size)) {
584 584
 			$this->log->log('croping image for avatar failed for '.$this->dn, \OCP\Util::ERROR);
585 585
 			return;
586 586
 		}
587 587
 
588
-		if(!$this->fs->isLoaded()) {
588
+		if (!$this->fs->isLoaded()) {
589 589
 			$this->fs->setup($this->uid);
590 590
 		}
591 591
 
@@ -594,7 +594,7 @@  discard block
 block discarded – undo
594 594
 			$avatar->set($this->image);
595 595
 		} catch (\Exception $e) {
596 596
 			\OC::$server->getLogger()->notice(
597
-				'Could not set avatar for ' . $this->dn	. ', because: ' . $e->getMessage(),
597
+				'Could not set avatar for '.$this->dn.', because: '.$e->getMessage(),
598 598
 				['app' => 'user_ldap']);
599 599
 		}
600 600
 	}
@@ -607,17 +607,17 @@  discard block
 block discarded – undo
607 607
 	public function handlePasswordExpiry($params) {
608 608
 		$ppolicyDN = $this->connection->ldapDefaultPPolicyDN;
609 609
 		if (empty($ppolicyDN) || (intval($this->connection->turnOnPasswordChange) !== 1)) {
610
-			return;//password expiry handling disabled
610
+			return; //password expiry handling disabled
611 611
 		}
612 612
 		$uid = $params['uid'];
613
-		if(isset($uid) && $uid === $this->getUsername()) {
613
+		if (isset($uid) && $uid === $this->getUsername()) {
614 614
 			//retrieve relevant user attributes
615 615
 			$result = $this->access->search('objectclass=*', $this->dn, ['pwdpolicysubentry', 'pwdgraceusetime', 'pwdreset', 'pwdchangedtime']);
616 616
 			
617
-			if(array_key_exists('pwdpolicysubentry', $result[0])) {
617
+			if (array_key_exists('pwdpolicysubentry', $result[0])) {
618 618
 				$pwdPolicySubentry = $result[0]['pwdpolicysubentry'];
619
-				if($pwdPolicySubentry && (count($pwdPolicySubentry) > 0)){
620
-					$ppolicyDN = $pwdPolicySubentry[0];//custom ppolicy DN
619
+				if ($pwdPolicySubentry && (count($pwdPolicySubentry) > 0)) {
620
+					$ppolicyDN = $pwdPolicySubentry[0]; //custom ppolicy DN
621 621
 				}
622 622
 			}
623 623
 			
@@ -626,9 +626,9 @@  discard block
 block discarded – undo
626 626
 			$pwdChangedTime = array_key_exists('pwdchangedtime', $result[0]) ? $result[0]['pwdchangedtime'] : null;
627 627
 			
628 628
 			//retrieve relevant password policy attributes
629
-			$cacheKey = 'ppolicyAttributes' . $ppolicyDN;
629
+			$cacheKey = 'ppolicyAttributes'.$ppolicyDN;
630 630
 			$result = $this->connection->getFromCache($cacheKey);
631
-			if(is_null($result)) {
631
+			if (is_null($result)) {
632 632
 				$result = $this->access->search('objectclass=*', $ppolicyDN, ['pwdgraceauthnlimit', 'pwdmaxage', 'pwdexpirewarning']);
633 633
 				$this->connection->writeToCache($cacheKey, $result);
634 634
 			}
@@ -639,8 +639,8 @@  discard block
 block discarded – undo
639 639
 			
640 640
 			//handle grace login
641 641
 			$pwdGraceUseTimeCount = count($pwdGraceUseTime);
642
-			if($pwdGraceUseTime && $pwdGraceUseTimeCount > 0) { //was this a grace login?
643
-				if($pwdGraceAuthNLimit 
642
+			if ($pwdGraceUseTime && $pwdGraceUseTimeCount > 0) { //was this a grace login?
643
+				if ($pwdGraceAuthNLimit 
644 644
 					&& (count($pwdGraceAuthNLimit) > 0)
645 645
 					&&($pwdGraceUseTimeCount < intval($pwdGraceAuthNLimit[0]))) { //at least one more grace login available?
646 646
 					$this->config->setUserValue($uid, 'user_ldap', 'needsPasswordReset', 'true');
@@ -653,24 +653,24 @@  discard block
 block discarded – undo
653 653
 				exit();
654 654
 			}
655 655
 			//handle pwdReset attribute
656
-			if($pwdReset && (count($pwdReset) > 0) && $pwdReset[0] === 'TRUE') { //user must change his password
656
+			if ($pwdReset && (count($pwdReset) > 0) && $pwdReset[0] === 'TRUE') { //user must change his password
657 657
 				$this->config->setUserValue($uid, 'user_ldap', 'needsPasswordReset', 'true');
658 658
 				header('Location: '.\OC::$server->getURLGenerator()->linkToRouteAbsolute(
659 659
 				'user_ldap.renewPassword.showRenewPasswordForm', array('user' => $uid)));
660 660
 				exit();
661 661
 			}
662 662
 			//handle password expiry warning
663
-			if($pwdChangedTime && (count($pwdChangedTime) > 0)) {
664
-				if($pwdMaxAge && (count($pwdMaxAge) > 0)
663
+			if ($pwdChangedTime && (count($pwdChangedTime) > 0)) {
664
+				if ($pwdMaxAge && (count($pwdMaxAge) > 0)
665 665
 					&& $pwdExpireWarning && (count($pwdExpireWarning) > 0)) {
666 666
 					$pwdMaxAgeInt = intval($pwdMaxAge[0]);
667 667
 					$pwdExpireWarningInt = intval($pwdExpireWarning[0]);
668
-					if($pwdMaxAgeInt > 0 && $pwdExpireWarningInt > 0){
668
+					if ($pwdMaxAgeInt > 0 && $pwdExpireWarningInt > 0) {
669 669
 						$pwdChangedTimeDt = \DateTime::createFromFormat('YmdHisZ', $pwdChangedTime[0]);
670 670
 						$pwdChangedTimeDt->add(new \DateInterval('PT'.$pwdMaxAgeInt.'S'));
671 671
 						$currentDateTime = new \DateTime();
672 672
 						$secondsToExpiry = $pwdChangedTimeDt->getTimestamp() - $currentDateTime->getTimestamp();
673
-						if($secondsToExpiry <= $pwdExpireWarningInt) {
673
+						if ($secondsToExpiry <= $pwdExpireWarningInt) {
674 674
 							//remove last password expiry warning if any
675 675
 							$notification = $this->notificationManager->createNotification();
676 676
 							$notification->setApp('user_ldap')
Please login to merge, or discard this patch.
apps/user_ldap/lib/Jobs/Sync.php 2 patches
Indentation   +290 added lines, -290 removed lines patch added patch discarded remove patch
@@ -39,294 +39,294 @@
 block discarded – undo
39 39
 use OCP\IServerContainer;
40 40
 
41 41
 class Sync extends TimedJob {
42
-	/** @var IServerContainer */
43
-	protected $c;
44
-	/** @var  Helper */
45
-	protected $ldapHelper;
46
-	/** @var  LDAP */
47
-	protected $ldap;
48
-	/** @var  Manager */
49
-	protected $userManager;
50
-	/** @var UserMapping */
51
-	protected $mapper;
52
-	/** @var int */
53
-	protected $maxInterval = 12 * 60 * 60; // 12h
54
-	/** @var int */
55
-	protected $minInterval = 30 * 60; // 30min
56
-
57
-	public function __construct() {
58
-		$this->setInterval(
59
-			\OC::$server->getConfig()->getAppValue(
60
-				'user_ldap',
61
-				'background_sync_interval',
62
-				$this->minInterval
63
-			)
64
-		);
65
-	}
66
-
67
-	/**
68
-	 * updates the interval
69
-	 *
70
-	 * the idea is to adjust the interval depending on the amount of known users
71
-	 * and the attempt to update each user one day. At most it would run every
72
-	 * 30 minutes, and at least every 12 hours.
73
-	 */
74
-	public function updateInterval() {
75
-		$minPagingSize = $this->getMinPagingSize();
76
-		$mappedUsers = $this->mapper->count();
77
-
78
-		$runsPerDay = ($minPagingSize === 0) ? $this->maxInterval : $mappedUsers / $minPagingSize;
79
-		$interval = floor(24 * 60 * 60 / $runsPerDay);
80
-		$interval = min(max($interval, $this->minInterval), $this->maxInterval);
81
-
82
-		$this->c->getConfig()->setAppValue('user_ldap', 'background_sync_interval', $interval);
83
-	}
84
-
85
-	/**
86
-	 * returns the smallest configured paging size
87
-	 * @return int
88
-	 */
89
-	protected function getMinPagingSize() {
90
-		$config = $this->c->getConfig();
91
-		$configKeys = $config->getAppKeys('user_ldap');
92
-		$configKeys = array_filter($configKeys, function($key) {
93
-			return strpos($key, 'ldap_paging_size') !== false;
94
-		});
95
-		$minPagingSize = null;
96
-		foreach ($configKeys as $configKey) {
97
-			$pagingSize = $config->getAppValue('user_ldap', $configKey, $minPagingSize);
98
-			$minPagingSize = $minPagingSize === null ? $pagingSize : min($minPagingSize, $pagingSize);
99
-		}
100
-		return (int)$minPagingSize;
101
-	}
102
-
103
-	/**
104
-	 * @param array $argument
105
-	 */
106
-	protected function run($argument) {
107
-		$this->setArgument($argument);
108
-
109
-		$isBackgroundJobModeAjax = $this->c->getConfig()
110
-				->getAppValue('core', 'backgroundjobs_mode', 'ajax') === 'ajax';
111
-		if($isBackgroundJobModeAjax) {
112
-			return;
113
-		}
114
-
115
-		$cycleData = $this->getCycle();
116
-		if($cycleData === null) {
117
-			$cycleData = $this->determineNextCycle();
118
-			if($cycleData === null) {
119
-				$this->updateInterval();
120
-				return;
121
-			}
122
-		}
123
-
124
-		if(!$this->qualifiesToRun($cycleData)) {
125
-			$this->updateInterval();
126
-			return;
127
-		}
128
-
129
-		try {
130
-			$expectMoreResults = $this->runCycle($cycleData);
131
-			if ($expectMoreResults) {
132
-				$this->increaseOffset($cycleData);
133
-			} else {
134
-				$this->determineNextCycle();
135
-			}
136
-			$this->updateInterval();
137
-		} catch (ServerNotAvailableException $e) {
138
-			$this->determineNextCycle();
139
-		}
140
-	}
141
-
142
-	/**
143
-	 * @param array $cycleData
144
-	 * @return bool whether more results are expected from the same configuration
145
-	 */
146
-	public function runCycle($cycleData) {
147
-		$connection = new Connection($this->ldap, $cycleData['prefix']);
148
-		$access = new Access($connection, $this->ldap, $this->userManager, $this->ldapHelper, $this->c);
149
-		$access->setUserMapper($this->mapper);
150
-
151
-		$filter = $access->combineFilterWithAnd(array(
152
-			$access->connection->ldapUserFilter,
153
-			$access->connection->ldapUserDisplayName . '=*',
154
-			$access->getFilterPartForUserSearch('')
155
-		));
156
-		$results = $access->fetchListOfUsers(
157
-			$filter,
158
-			$access->userManager->getAttributes(),
159
-			$connection->ldapPagingSize,
160
-			$cycleData['offset'],
161
-			true
162
-		);
163
-
164
-		if($connection->ldapPagingSize === 0) {
165
-			return true;
166
-		}
167
-		return count($results) !== $connection->ldapPagingSize;
168
-	}
169
-
170
-	/**
171
-	 * returns the info about the current cycle that should be run, if any,
172
-	 * otherwise null
173
-	 *
174
-	 * @return array|null
175
-	 */
176
-	public function getCycle() {
177
-		$prefixes = $this->ldapHelper->getServerConfigurationPrefixes(true);
178
-		if(count($prefixes) === 0) {
179
-			return null;
180
-		}
181
-
182
-		$config = $this->c->getConfig();
183
-		$cycleData = [
184
-			'prefix' => $config->getAppValue('user_ldap', 'background_sync_prefix', null),
185
-			'offset' => (int)$config->getAppValue('user_ldap', 'background_sync_offset', 0),
186
-		];
187
-
188
-		if(
189
-			$cycleData['prefix'] !== null
190
-			&& in_array($cycleData['prefix'], $prefixes)
191
-		) {
192
-			return $cycleData;
193
-		}
194
-
195
-		return null;
196
-	}
197
-
198
-	/**
199
-	 * Save the provided cycle information in the DB
200
-	 *
201
-	 * @param array $cycleData
202
-	 */
203
-	public function setCycle(array $cycleData) {
204
-		$config = $this->c->getConfig();
205
-		$config->setAppValue('user_ldap', 'background_sync_prefix', $cycleData['prefix']);
206
-		$config->setAppValue('user_ldap', 'background_sync_offset', $cycleData['offset']);
207
-	}
208
-
209
-	/**
210
-	 * returns data about the next cycle that should run, if any, otherwise
211
-	 * null. It also always goes for the next LDAP configuration!
212
-	 *
213
-	 * @param array|null $cycleData the old cycle
214
-	 * @return array|null
215
-	 */
216
-	public function determineNextCycle(array $cycleData = null) {
217
-		$prefixes = $this->ldapHelper->getServerConfigurationPrefixes(true);
218
-		if(count($prefixes) === 0) {
219
-			return null;
220
-		}
221
-
222
-		// get the next prefix in line and remember it
223
-		$oldPrefix = $cycleData === null ? null : $cycleData['prefix'];
224
-		$prefix = $this->getNextPrefix($oldPrefix);
225
-		if($prefix === null) {
226
-			return null;
227
-		}
228
-		$cycleData['prefix'] = $prefix;
229
-		$cycleData['offset'] = 0;
230
-		$this->setCycle(['prefix' => $prefix, 'offset' => 0]);
231
-
232
-		return $cycleData;
233
-	}
234
-
235
-	/**
236
-	 * Checks whether the provided cycle should be run. Currently only the
237
-	 * last configuration change goes into account (at least one hour).
238
-	 *
239
-	 * @param $cycleData
240
-	 * @return bool
241
-	 */
242
-	protected function qualifiesToRun($cycleData) {
243
-		$config = $this->c->getConfig();
244
-		$lastChange = $config->getAppValue('user_ldap', $cycleData['prefix'] . '_lastChange', 0);
245
-		if((time() - $lastChange) > 60 * 30) {
246
-			return true;
247
-		}
248
-		return false;
249
-	}
250
-
251
-	/**
252
-	 * increases the offset of the current cycle for the next run
253
-	 *
254
-	 * @param $cycleData
255
-	 */
256
-	protected function increaseOffset($cycleData) {
257
-		$ldapConfig = new Configuration($cycleData['prefix']);
258
-		$cycleData['offset'] += (int)$ldapConfig->ldapPagingSize;
259
-		$this->setCycle($cycleData);
260
-	}
261
-
262
-	/**
263
-	 * determines the next configuration prefix based on the last one (if any)
264
-	 *
265
-	 * @param string|null $lastPrefix
266
-	 * @return string|null
267
-	 */
268
-	protected function getNextPrefix($lastPrefix) {
269
-		$prefixes = $this->ldapHelper->getServerConfigurationPrefixes(true);
270
-		$noOfPrefixes = count($prefixes);
271
-		if($noOfPrefixes === 0) {
272
-			return null;
273
-		}
274
-		$i = $lastPrefix === null ? false : array_search($lastPrefix, $prefixes, true);
275
-		if($i === false) {
276
-			$i = -1;
277
-		} else {
278
-			$i++;
279
-		}
280
-
281
-		if(!isset($prefixes[$i])) {
282
-			$i = 0;
283
-		}
284
-		return $prefixes[$i];
285
-	}
286
-
287
-	/**
288
-	 * "fixes" DI
289
-	 *
290
-	 * @param array $argument
291
-	 */
292
-	public function setArgument($argument) {
293
-		if(isset($argument['c'])) {
294
-			$this->c = $argument['c'];
295
-		} else {
296
-			$this->c = \OC::$server;
297
-		}
298
-
299
-		if(isset($argument['helper'])) {
300
-			$this->ldapHelper = $argument['helper'];
301
-		} else {
302
-			$this->ldapHelper = new Helper($this->c->getConfig());
303
-		}
304
-
305
-		if(isset($argument['ldapWrapper'])) {
306
-			$this->ldap = $argument['ldapWrapper'];
307
-		} else {
308
-			$this->ldap = new LDAP();
309
-		}
310
-
311
-		if(isset($argument['userManager'])) {
312
-			$this->userManager = $argument['userManager'];
313
-		} else {
314
-			$this->userManager = new Manager(
315
-				$this->c->getConfig(),
316
-				new FilesystemHelper(),
317
-				new LogWrapper(),
318
-				$this->c->getAvatarManager(),
319
-				new Image(),
320
-				$this->c->getDatabaseConnection(),
321
-				$this->c->getUserManager(),
322
-				$this->c->getNotificationManager()
323
-			);
324
-		}
325
-
326
-		if(isset($argument['mapper'])) {
327
-			$this->mapper = $argument['mapper'];
328
-		} else {
329
-			$this->mapper = new UserMapping($this->c->getDatabaseConnection());
330
-		}
331
-	}
42
+    /** @var IServerContainer */
43
+    protected $c;
44
+    /** @var  Helper */
45
+    protected $ldapHelper;
46
+    /** @var  LDAP */
47
+    protected $ldap;
48
+    /** @var  Manager */
49
+    protected $userManager;
50
+    /** @var UserMapping */
51
+    protected $mapper;
52
+    /** @var int */
53
+    protected $maxInterval = 12 * 60 * 60; // 12h
54
+    /** @var int */
55
+    protected $minInterval = 30 * 60; // 30min
56
+
57
+    public function __construct() {
58
+        $this->setInterval(
59
+            \OC::$server->getConfig()->getAppValue(
60
+                'user_ldap',
61
+                'background_sync_interval',
62
+                $this->minInterval
63
+            )
64
+        );
65
+    }
66
+
67
+    /**
68
+     * updates the interval
69
+     *
70
+     * the idea is to adjust the interval depending on the amount of known users
71
+     * and the attempt to update each user one day. At most it would run every
72
+     * 30 minutes, and at least every 12 hours.
73
+     */
74
+    public function updateInterval() {
75
+        $minPagingSize = $this->getMinPagingSize();
76
+        $mappedUsers = $this->mapper->count();
77
+
78
+        $runsPerDay = ($minPagingSize === 0) ? $this->maxInterval : $mappedUsers / $minPagingSize;
79
+        $interval = floor(24 * 60 * 60 / $runsPerDay);
80
+        $interval = min(max($interval, $this->minInterval), $this->maxInterval);
81
+
82
+        $this->c->getConfig()->setAppValue('user_ldap', 'background_sync_interval', $interval);
83
+    }
84
+
85
+    /**
86
+     * returns the smallest configured paging size
87
+     * @return int
88
+     */
89
+    protected function getMinPagingSize() {
90
+        $config = $this->c->getConfig();
91
+        $configKeys = $config->getAppKeys('user_ldap');
92
+        $configKeys = array_filter($configKeys, function($key) {
93
+            return strpos($key, 'ldap_paging_size') !== false;
94
+        });
95
+        $minPagingSize = null;
96
+        foreach ($configKeys as $configKey) {
97
+            $pagingSize = $config->getAppValue('user_ldap', $configKey, $minPagingSize);
98
+            $minPagingSize = $minPagingSize === null ? $pagingSize : min($minPagingSize, $pagingSize);
99
+        }
100
+        return (int)$minPagingSize;
101
+    }
102
+
103
+    /**
104
+     * @param array $argument
105
+     */
106
+    protected function run($argument) {
107
+        $this->setArgument($argument);
108
+
109
+        $isBackgroundJobModeAjax = $this->c->getConfig()
110
+                ->getAppValue('core', 'backgroundjobs_mode', 'ajax') === 'ajax';
111
+        if($isBackgroundJobModeAjax) {
112
+            return;
113
+        }
114
+
115
+        $cycleData = $this->getCycle();
116
+        if($cycleData === null) {
117
+            $cycleData = $this->determineNextCycle();
118
+            if($cycleData === null) {
119
+                $this->updateInterval();
120
+                return;
121
+            }
122
+        }
123
+
124
+        if(!$this->qualifiesToRun($cycleData)) {
125
+            $this->updateInterval();
126
+            return;
127
+        }
128
+
129
+        try {
130
+            $expectMoreResults = $this->runCycle($cycleData);
131
+            if ($expectMoreResults) {
132
+                $this->increaseOffset($cycleData);
133
+            } else {
134
+                $this->determineNextCycle();
135
+            }
136
+            $this->updateInterval();
137
+        } catch (ServerNotAvailableException $e) {
138
+            $this->determineNextCycle();
139
+        }
140
+    }
141
+
142
+    /**
143
+     * @param array $cycleData
144
+     * @return bool whether more results are expected from the same configuration
145
+     */
146
+    public function runCycle($cycleData) {
147
+        $connection = new Connection($this->ldap, $cycleData['prefix']);
148
+        $access = new Access($connection, $this->ldap, $this->userManager, $this->ldapHelper, $this->c);
149
+        $access->setUserMapper($this->mapper);
150
+
151
+        $filter = $access->combineFilterWithAnd(array(
152
+            $access->connection->ldapUserFilter,
153
+            $access->connection->ldapUserDisplayName . '=*',
154
+            $access->getFilterPartForUserSearch('')
155
+        ));
156
+        $results = $access->fetchListOfUsers(
157
+            $filter,
158
+            $access->userManager->getAttributes(),
159
+            $connection->ldapPagingSize,
160
+            $cycleData['offset'],
161
+            true
162
+        );
163
+
164
+        if($connection->ldapPagingSize === 0) {
165
+            return true;
166
+        }
167
+        return count($results) !== $connection->ldapPagingSize;
168
+    }
169
+
170
+    /**
171
+     * returns the info about the current cycle that should be run, if any,
172
+     * otherwise null
173
+     *
174
+     * @return array|null
175
+     */
176
+    public function getCycle() {
177
+        $prefixes = $this->ldapHelper->getServerConfigurationPrefixes(true);
178
+        if(count($prefixes) === 0) {
179
+            return null;
180
+        }
181
+
182
+        $config = $this->c->getConfig();
183
+        $cycleData = [
184
+            'prefix' => $config->getAppValue('user_ldap', 'background_sync_prefix', null),
185
+            'offset' => (int)$config->getAppValue('user_ldap', 'background_sync_offset', 0),
186
+        ];
187
+
188
+        if(
189
+            $cycleData['prefix'] !== null
190
+            && in_array($cycleData['prefix'], $prefixes)
191
+        ) {
192
+            return $cycleData;
193
+        }
194
+
195
+        return null;
196
+    }
197
+
198
+    /**
199
+     * Save the provided cycle information in the DB
200
+     *
201
+     * @param array $cycleData
202
+     */
203
+    public function setCycle(array $cycleData) {
204
+        $config = $this->c->getConfig();
205
+        $config->setAppValue('user_ldap', 'background_sync_prefix', $cycleData['prefix']);
206
+        $config->setAppValue('user_ldap', 'background_sync_offset', $cycleData['offset']);
207
+    }
208
+
209
+    /**
210
+     * returns data about the next cycle that should run, if any, otherwise
211
+     * null. It also always goes for the next LDAP configuration!
212
+     *
213
+     * @param array|null $cycleData the old cycle
214
+     * @return array|null
215
+     */
216
+    public function determineNextCycle(array $cycleData = null) {
217
+        $prefixes = $this->ldapHelper->getServerConfigurationPrefixes(true);
218
+        if(count($prefixes) === 0) {
219
+            return null;
220
+        }
221
+
222
+        // get the next prefix in line and remember it
223
+        $oldPrefix = $cycleData === null ? null : $cycleData['prefix'];
224
+        $prefix = $this->getNextPrefix($oldPrefix);
225
+        if($prefix === null) {
226
+            return null;
227
+        }
228
+        $cycleData['prefix'] = $prefix;
229
+        $cycleData['offset'] = 0;
230
+        $this->setCycle(['prefix' => $prefix, 'offset' => 0]);
231
+
232
+        return $cycleData;
233
+    }
234
+
235
+    /**
236
+     * Checks whether the provided cycle should be run. Currently only the
237
+     * last configuration change goes into account (at least one hour).
238
+     *
239
+     * @param $cycleData
240
+     * @return bool
241
+     */
242
+    protected function qualifiesToRun($cycleData) {
243
+        $config = $this->c->getConfig();
244
+        $lastChange = $config->getAppValue('user_ldap', $cycleData['prefix'] . '_lastChange', 0);
245
+        if((time() - $lastChange) > 60 * 30) {
246
+            return true;
247
+        }
248
+        return false;
249
+    }
250
+
251
+    /**
252
+     * increases the offset of the current cycle for the next run
253
+     *
254
+     * @param $cycleData
255
+     */
256
+    protected function increaseOffset($cycleData) {
257
+        $ldapConfig = new Configuration($cycleData['prefix']);
258
+        $cycleData['offset'] += (int)$ldapConfig->ldapPagingSize;
259
+        $this->setCycle($cycleData);
260
+    }
261
+
262
+    /**
263
+     * determines the next configuration prefix based on the last one (if any)
264
+     *
265
+     * @param string|null $lastPrefix
266
+     * @return string|null
267
+     */
268
+    protected function getNextPrefix($lastPrefix) {
269
+        $prefixes = $this->ldapHelper->getServerConfigurationPrefixes(true);
270
+        $noOfPrefixes = count($prefixes);
271
+        if($noOfPrefixes === 0) {
272
+            return null;
273
+        }
274
+        $i = $lastPrefix === null ? false : array_search($lastPrefix, $prefixes, true);
275
+        if($i === false) {
276
+            $i = -1;
277
+        } else {
278
+            $i++;
279
+        }
280
+
281
+        if(!isset($prefixes[$i])) {
282
+            $i = 0;
283
+        }
284
+        return $prefixes[$i];
285
+    }
286
+
287
+    /**
288
+     * "fixes" DI
289
+     *
290
+     * @param array $argument
291
+     */
292
+    public function setArgument($argument) {
293
+        if(isset($argument['c'])) {
294
+            $this->c = $argument['c'];
295
+        } else {
296
+            $this->c = \OC::$server;
297
+        }
298
+
299
+        if(isset($argument['helper'])) {
300
+            $this->ldapHelper = $argument['helper'];
301
+        } else {
302
+            $this->ldapHelper = new Helper($this->c->getConfig());
303
+        }
304
+
305
+        if(isset($argument['ldapWrapper'])) {
306
+            $this->ldap = $argument['ldapWrapper'];
307
+        } else {
308
+            $this->ldap = new LDAP();
309
+        }
310
+
311
+        if(isset($argument['userManager'])) {
312
+            $this->userManager = $argument['userManager'];
313
+        } else {
314
+            $this->userManager = new Manager(
315
+                $this->c->getConfig(),
316
+                new FilesystemHelper(),
317
+                new LogWrapper(),
318
+                $this->c->getAvatarManager(),
319
+                new Image(),
320
+                $this->c->getDatabaseConnection(),
321
+                $this->c->getUserManager(),
322
+                $this->c->getNotificationManager()
323
+            );
324
+        }
325
+
326
+        if(isset($argument['mapper'])) {
327
+            $this->mapper = $argument['mapper'];
328
+        } else {
329
+            $this->mapper = new UserMapping($this->c->getDatabaseConnection());
330
+        }
331
+    }
332 332
 }
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 			$pagingSize = $config->getAppValue('user_ldap', $configKey, $minPagingSize);
98 98
 			$minPagingSize = $minPagingSize === null ? $pagingSize : min($minPagingSize, $pagingSize);
99 99
 		}
100
-		return (int)$minPagingSize;
100
+		return (int) $minPagingSize;
101 101
 	}
102 102
 
103 103
 	/**
@@ -108,20 +108,20 @@  discard block
 block discarded – undo
108 108
 
109 109
 		$isBackgroundJobModeAjax = $this->c->getConfig()
110 110
 				->getAppValue('core', 'backgroundjobs_mode', 'ajax') === 'ajax';
111
-		if($isBackgroundJobModeAjax) {
111
+		if ($isBackgroundJobModeAjax) {
112 112
 			return;
113 113
 		}
114 114
 
115 115
 		$cycleData = $this->getCycle();
116
-		if($cycleData === null) {
116
+		if ($cycleData === null) {
117 117
 			$cycleData = $this->determineNextCycle();
118
-			if($cycleData === null) {
118
+			if ($cycleData === null) {
119 119
 				$this->updateInterval();
120 120
 				return;
121 121
 			}
122 122
 		}
123 123
 
124
-		if(!$this->qualifiesToRun($cycleData)) {
124
+		if (!$this->qualifiesToRun($cycleData)) {
125 125
 			$this->updateInterval();
126 126
 			return;
127 127
 		}
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 
151 151
 		$filter = $access->combineFilterWithAnd(array(
152 152
 			$access->connection->ldapUserFilter,
153
-			$access->connection->ldapUserDisplayName . '=*',
153
+			$access->connection->ldapUserDisplayName.'=*',
154 154
 			$access->getFilterPartForUserSearch('')
155 155
 		));
156 156
 		$results = $access->fetchListOfUsers(
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
 			true
162 162
 		);
163 163
 
164
-		if($connection->ldapPagingSize === 0) {
164
+		if ($connection->ldapPagingSize === 0) {
165 165
 			return true;
166 166
 		}
167 167
 		return count($results) !== $connection->ldapPagingSize;
@@ -175,17 +175,17 @@  discard block
 block discarded – undo
175 175
 	 */
176 176
 	public function getCycle() {
177 177
 		$prefixes = $this->ldapHelper->getServerConfigurationPrefixes(true);
178
-		if(count($prefixes) === 0) {
178
+		if (count($prefixes) === 0) {
179 179
 			return null;
180 180
 		}
181 181
 
182 182
 		$config = $this->c->getConfig();
183 183
 		$cycleData = [
184 184
 			'prefix' => $config->getAppValue('user_ldap', 'background_sync_prefix', null),
185
-			'offset' => (int)$config->getAppValue('user_ldap', 'background_sync_offset', 0),
185
+			'offset' => (int) $config->getAppValue('user_ldap', 'background_sync_offset', 0),
186 186
 		];
187 187
 
188
-		if(
188
+		if (
189 189
 			$cycleData['prefix'] !== null
190 190
 			&& in_array($cycleData['prefix'], $prefixes)
191 191
 		) {
@@ -215,14 +215,14 @@  discard block
 block discarded – undo
215 215
 	 */
216 216
 	public function determineNextCycle(array $cycleData = null) {
217 217
 		$prefixes = $this->ldapHelper->getServerConfigurationPrefixes(true);
218
-		if(count($prefixes) === 0) {
218
+		if (count($prefixes) === 0) {
219 219
 			return null;
220 220
 		}
221 221
 
222 222
 		// get the next prefix in line and remember it
223 223
 		$oldPrefix = $cycleData === null ? null : $cycleData['prefix'];
224 224
 		$prefix = $this->getNextPrefix($oldPrefix);
225
-		if($prefix === null) {
225
+		if ($prefix === null) {
226 226
 			return null;
227 227
 		}
228 228
 		$cycleData['prefix'] = $prefix;
@@ -241,8 +241,8 @@  discard block
 block discarded – undo
241 241
 	 */
242 242
 	protected function qualifiesToRun($cycleData) {
243 243
 		$config = $this->c->getConfig();
244
-		$lastChange = $config->getAppValue('user_ldap', $cycleData['prefix'] . '_lastChange', 0);
245
-		if((time() - $lastChange) > 60 * 30) {
244
+		$lastChange = $config->getAppValue('user_ldap', $cycleData['prefix'].'_lastChange', 0);
245
+		if ((time() - $lastChange) > 60 * 30) {
246 246
 			return true;
247 247
 		}
248 248
 		return false;
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
 	 */
256 256
 	protected function increaseOffset($cycleData) {
257 257
 		$ldapConfig = new Configuration($cycleData['prefix']);
258
-		$cycleData['offset'] += (int)$ldapConfig->ldapPagingSize;
258
+		$cycleData['offset'] += (int) $ldapConfig->ldapPagingSize;
259 259
 		$this->setCycle($cycleData);
260 260
 	}
261 261
 
@@ -268,17 +268,17 @@  discard block
 block discarded – undo
268 268
 	protected function getNextPrefix($lastPrefix) {
269 269
 		$prefixes = $this->ldapHelper->getServerConfigurationPrefixes(true);
270 270
 		$noOfPrefixes = count($prefixes);
271
-		if($noOfPrefixes === 0) {
271
+		if ($noOfPrefixes === 0) {
272 272
 			return null;
273 273
 		}
274 274
 		$i = $lastPrefix === null ? false : array_search($lastPrefix, $prefixes, true);
275
-		if($i === false) {
275
+		if ($i === false) {
276 276
 			$i = -1;
277 277
 		} else {
278 278
 			$i++;
279 279
 		}
280 280
 
281
-		if(!isset($prefixes[$i])) {
281
+		if (!isset($prefixes[$i])) {
282 282
 			$i = 0;
283 283
 		}
284 284
 		return $prefixes[$i];
@@ -290,25 +290,25 @@  discard block
 block discarded – undo
290 290
 	 * @param array $argument
291 291
 	 */
292 292
 	public function setArgument($argument) {
293
-		if(isset($argument['c'])) {
293
+		if (isset($argument['c'])) {
294 294
 			$this->c = $argument['c'];
295 295
 		} else {
296 296
 			$this->c = \OC::$server;
297 297
 		}
298 298
 
299
-		if(isset($argument['helper'])) {
299
+		if (isset($argument['helper'])) {
300 300
 			$this->ldapHelper = $argument['helper'];
301 301
 		} else {
302 302
 			$this->ldapHelper = new Helper($this->c->getConfig());
303 303
 		}
304 304
 
305
-		if(isset($argument['ldapWrapper'])) {
305
+		if (isset($argument['ldapWrapper'])) {
306 306
 			$this->ldap = $argument['ldapWrapper'];
307 307
 		} else {
308 308
 			$this->ldap = new LDAP();
309 309
 		}
310 310
 
311
-		if(isset($argument['userManager'])) {
311
+		if (isset($argument['userManager'])) {
312 312
 			$this->userManager = $argument['userManager'];
313 313
 		} else {
314 314
 			$this->userManager = new Manager(
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
 			);
324 324
 		}
325 325
 
326
-		if(isset($argument['mapper'])) {
326
+		if (isset($argument['mapper'])) {
327 327
 			$this->mapper = $argument['mapper'];
328 328
 		} else {
329 329
 			$this->mapper = new UserMapping($this->c->getDatabaseConnection());
Please login to merge, or discard this patch.
apps/user_ldap/lib/Jobs/UpdateGroups.php 1 patch
Indentation   +164 added lines, -164 removed lines patch added patch discarded remove patch
@@ -41,183 +41,183 @@
 block discarded – undo
41 41
 use OCA\User_LDAP\User\Manager;
42 42
 
43 43
 class UpdateGroups extends \OC\BackgroundJob\TimedJob {
44
-	static private $groupsFromDB;
45
-
46
-	static private $groupBE;
47
-
48
-	public function __construct(){
49
-		$this->interval = self::getRefreshInterval();
50
-	}
51
-
52
-	/**
53
-	 * @param mixed $argument
54
-	 */
55
-	public function run($argument){
56
-		self::updateGroups();
57
-	}
58
-
59
-	static public function updateGroups() {
60
-		\OCP\Util::writeLog('user_ldap', 'Run background job "updateGroups"', \OCP\Util::DEBUG);
61
-
62
-		$knownGroups = array_keys(self::getKnownGroups());
63
-		$actualGroups = self::getGroupBE()->getGroups();
64
-
65
-		if(empty($actualGroups) && empty($knownGroups)) {
66
-			\OCP\Util::writeLog('user_ldap',
67
-				'bgJ "updateGroups" – groups do not seem to be configured properly, aborting.',
68
-				\OCP\Util::INFO);
69
-			return;
70
-		}
71
-
72
-		self::handleKnownGroups(array_intersect($actualGroups, $knownGroups));
73
-		self::handleCreatedGroups(array_diff($actualGroups, $knownGroups));
74
-		self::handleRemovedGroups(array_diff($knownGroups, $actualGroups));
75
-
76
-		\OCP\Util::writeLog('user_ldap', 'bgJ "updateGroups" – Finished.', \OCP\Util::DEBUG);
77
-	}
78
-
79
-	/**
80
-	 * @return int
81
-	 */
82
-	static private function getRefreshInterval() {
83
-		//defaults to every hour
84
-		return \OCP\Config::getAppValue('user_ldap', 'bgjRefreshInterval', 3600);
85
-	}
86
-
87
-	/**
88
-	 * @param string[] $groups
89
-	 */
90
-	static private function handleKnownGroups($groups) {
91
-		\OCP\Util::writeLog('user_ldap', 'bgJ "updateGroups" – Dealing with known Groups.', \OCP\Util::DEBUG);
92
-		$query = \OCP\DB::prepare('
44
+    static private $groupsFromDB;
45
+
46
+    static private $groupBE;
47
+
48
+    public function __construct(){
49
+        $this->interval = self::getRefreshInterval();
50
+    }
51
+
52
+    /**
53
+     * @param mixed $argument
54
+     */
55
+    public function run($argument){
56
+        self::updateGroups();
57
+    }
58
+
59
+    static public function updateGroups() {
60
+        \OCP\Util::writeLog('user_ldap', 'Run background job "updateGroups"', \OCP\Util::DEBUG);
61
+
62
+        $knownGroups = array_keys(self::getKnownGroups());
63
+        $actualGroups = self::getGroupBE()->getGroups();
64
+
65
+        if(empty($actualGroups) && empty($knownGroups)) {
66
+            \OCP\Util::writeLog('user_ldap',
67
+                'bgJ "updateGroups" – groups do not seem to be configured properly, aborting.',
68
+                \OCP\Util::INFO);
69
+            return;
70
+        }
71
+
72
+        self::handleKnownGroups(array_intersect($actualGroups, $knownGroups));
73
+        self::handleCreatedGroups(array_diff($actualGroups, $knownGroups));
74
+        self::handleRemovedGroups(array_diff($knownGroups, $actualGroups));
75
+
76
+        \OCP\Util::writeLog('user_ldap', 'bgJ "updateGroups" – Finished.', \OCP\Util::DEBUG);
77
+    }
78
+
79
+    /**
80
+     * @return int
81
+     */
82
+    static private function getRefreshInterval() {
83
+        //defaults to every hour
84
+        return \OCP\Config::getAppValue('user_ldap', 'bgjRefreshInterval', 3600);
85
+    }
86
+
87
+    /**
88
+     * @param string[] $groups
89
+     */
90
+    static private function handleKnownGroups($groups) {
91
+        \OCP\Util::writeLog('user_ldap', 'bgJ "updateGroups" – Dealing with known Groups.', \OCP\Util::DEBUG);
92
+        $query = \OCP\DB::prepare('
93 93
 			UPDATE `*PREFIX*ldap_group_members`
94 94
 			SET `owncloudusers` = ?
95 95
 			WHERE `owncloudname` = ?
96 96
 		');
97
-		foreach($groups as $group) {
98
-			//we assume, that self::$groupsFromDB has been retrieved already
99
-			$knownUsers = unserialize(self::$groupsFromDB[$group]['owncloudusers']);
100
-			$actualUsers = self::getGroupBE()->usersInGroup($group);
101
-			$hasChanged = false;
102
-			foreach(array_diff($knownUsers, $actualUsers) as $removedUser) {
103
-				\OCP\Util::emitHook('OC_User', 'post_removeFromGroup', array('uid' => $removedUser, 'gid' => $group));
104
-				\OCP\Util::writeLog('user_ldap',
105
-				'bgJ "updateGroups" – "'.$removedUser.'" removed from "'.$group.'".',
106
-				\OCP\Util::INFO);
107
-				$hasChanged = true;
108
-			}
109
-			foreach(array_diff($actualUsers, $knownUsers) as $addedUser) {
110
-				\OCP\Util::emitHook('OC_User', 'post_addToGroup', array('uid' => $addedUser, 'gid' => $group));
111
-				\OCP\Util::writeLog('user_ldap',
112
-				'bgJ "updateGroups" – "'.$addedUser.'" added to "'.$group.'".',
113
-				\OCP\Util::INFO);
114
-				$hasChanged = true;
115
-			}
116
-			if($hasChanged) {
117
-				$query->execute(array(serialize($actualUsers), $group));
118
-			}
119
-		}
120
-		\OCP\Util::writeLog('user_ldap',
121
-			'bgJ "updateGroups" – FINISHED dealing with known Groups.',
122
-			\OCP\Util::DEBUG);
123
-	}
124
-
125
-	/**
126
-	 * @param string[] $createdGroups
127
-	 */
128
-	static private function handleCreatedGroups($createdGroups) {
129
-		\OCP\Util::writeLog('user_ldap', 'bgJ "updateGroups" – dealing with created Groups.', \OCP\Util::DEBUG);
130
-		$query = \OCP\DB::prepare('
97
+        foreach($groups as $group) {
98
+            //we assume, that self::$groupsFromDB has been retrieved already
99
+            $knownUsers = unserialize(self::$groupsFromDB[$group]['owncloudusers']);
100
+            $actualUsers = self::getGroupBE()->usersInGroup($group);
101
+            $hasChanged = false;
102
+            foreach(array_diff($knownUsers, $actualUsers) as $removedUser) {
103
+                \OCP\Util::emitHook('OC_User', 'post_removeFromGroup', array('uid' => $removedUser, 'gid' => $group));
104
+                \OCP\Util::writeLog('user_ldap',
105
+                'bgJ "updateGroups" – "'.$removedUser.'" removed from "'.$group.'".',
106
+                \OCP\Util::INFO);
107
+                $hasChanged = true;
108
+            }
109
+            foreach(array_diff($actualUsers, $knownUsers) as $addedUser) {
110
+                \OCP\Util::emitHook('OC_User', 'post_addToGroup', array('uid' => $addedUser, 'gid' => $group));
111
+                \OCP\Util::writeLog('user_ldap',
112
+                'bgJ "updateGroups" – "'.$addedUser.'" added to "'.$group.'".',
113
+                \OCP\Util::INFO);
114
+                $hasChanged = true;
115
+            }
116
+            if($hasChanged) {
117
+                $query->execute(array(serialize($actualUsers), $group));
118
+            }
119
+        }
120
+        \OCP\Util::writeLog('user_ldap',
121
+            'bgJ "updateGroups" – FINISHED dealing with known Groups.',
122
+            \OCP\Util::DEBUG);
123
+    }
124
+
125
+    /**
126
+     * @param string[] $createdGroups
127
+     */
128
+    static private function handleCreatedGroups($createdGroups) {
129
+        \OCP\Util::writeLog('user_ldap', 'bgJ "updateGroups" – dealing with created Groups.', \OCP\Util::DEBUG);
130
+        $query = \OCP\DB::prepare('
131 131
 			INSERT
132 132
 			INTO `*PREFIX*ldap_group_members` (`owncloudname`, `owncloudusers`)
133 133
 			VALUES (?, ?)
134 134
 		');
135
-		foreach($createdGroups as $createdGroup) {
136
-			\OCP\Util::writeLog('user_ldap',
137
-				'bgJ "updateGroups" – new group "'.$createdGroup.'" found.',
138
-				\OCP\Util::INFO);
139
-			$users = serialize(self::getGroupBE()->usersInGroup($createdGroup));
140
-			$query->execute(array($createdGroup, $users));
141
-		}
142
-		\OCP\Util::writeLog('user_ldap',
143
-			'bgJ "updateGroups" – FINISHED dealing with created Groups.',
144
-			\OCP\Util::DEBUG);
145
-	}
146
-
147
-	/**
148
-	 * @param string[] $removedGroups
149
-	 */
150
-	static private function handleRemovedGroups($removedGroups) {
151
-		\OCP\Util::writeLog('user_ldap', 'bgJ "updateGroups" – dealing with removed groups.', \OCP\Util::DEBUG);
152
-		$query = \OCP\DB::prepare('
135
+        foreach($createdGroups as $createdGroup) {
136
+            \OCP\Util::writeLog('user_ldap',
137
+                'bgJ "updateGroups" – new group "'.$createdGroup.'" found.',
138
+                \OCP\Util::INFO);
139
+            $users = serialize(self::getGroupBE()->usersInGroup($createdGroup));
140
+            $query->execute(array($createdGroup, $users));
141
+        }
142
+        \OCP\Util::writeLog('user_ldap',
143
+            'bgJ "updateGroups" – FINISHED dealing with created Groups.',
144
+            \OCP\Util::DEBUG);
145
+    }
146
+
147
+    /**
148
+     * @param string[] $removedGroups
149
+     */
150
+    static private function handleRemovedGroups($removedGroups) {
151
+        \OCP\Util::writeLog('user_ldap', 'bgJ "updateGroups" – dealing with removed groups.', \OCP\Util::DEBUG);
152
+        $query = \OCP\DB::prepare('
153 153
 			DELETE
154 154
 			FROM `*PREFIX*ldap_group_members`
155 155
 			WHERE `owncloudname` = ?
156 156
 		');
157
-		foreach($removedGroups as $removedGroup) {
158
-			\OCP\Util::writeLog('user_ldap',
159
-				'bgJ "updateGroups" – group "'.$removedGroup.'" was removed.',
160
-				\OCP\Util::INFO);
161
-			$query->execute(array($removedGroup));
162
-		}
163
-		\OCP\Util::writeLog('user_ldap',
164
-			'bgJ "updateGroups" – FINISHED dealing with removed groups.',
165
-			\OCP\Util::DEBUG);
166
-	}
167
-
168
-	/**
169
-	 * @return \OCA\User_LDAP\Group_LDAP|\OCA\User_LDAP\Group_Proxy
170
-	 */
171
-	static private function getGroupBE() {
172
-		if(!is_null(self::$groupBE)) {
173
-			return self::$groupBE;
174
-		}
175
-		$helper = new Helper(\OC::$server->getConfig());
176
-		$configPrefixes = $helper->getServerConfigurationPrefixes(true);
177
-		$ldapWrapper = new LDAP();
178
-		if(count($configPrefixes) === 1) {
179
-			//avoid the proxy when there is only one LDAP server configured
180
-			$dbc = \OC::$server->getDatabaseConnection();
181
-			$userManager = new Manager(
182
-				\OC::$server->getConfig(),
183
-				new FilesystemHelper(),
184
-				new LogWrapper(),
185
-				\OC::$server->getAvatarManager(),
186
-				new \OCP\Image(),
187
-				$dbc,
188
-				\OC::$server->getUserManager(),
189
-				\OC::$server->getNotificationManager());
190
-			$connector = new Connection($ldapWrapper, $configPrefixes[0]);
191
-			$ldapAccess = new Access($connector, $ldapWrapper, $userManager, $helper, \OC::$server);
192
-			$groupMapper = new GroupMapping($dbc);
193
-			$userMapper  = new UserMapping($dbc);
194
-			$ldapAccess->setGroupMapper($groupMapper);
195
-			$ldapAccess->setUserMapper($userMapper);
196
-			self::$groupBE = new \OCA\User_LDAP\Group_LDAP($ldapAccess);
197
-		} else {
198
-			self::$groupBE = new \OCA\User_LDAP\Group_Proxy($configPrefixes, $ldapWrapper);
199
-		}
200
-
201
-		return self::$groupBE;
202
-	}
203
-
204
-	/**
205
-	 * @return array
206
-	 */
207
-	static private function getKnownGroups() {
208
-		if(is_array(self::$groupsFromDB)) {
209
-			return self::$groupsFromDB;
210
-		}
211
-		$query = \OCP\DB::prepare('
157
+        foreach($removedGroups as $removedGroup) {
158
+            \OCP\Util::writeLog('user_ldap',
159
+                'bgJ "updateGroups" – group "'.$removedGroup.'" was removed.',
160
+                \OCP\Util::INFO);
161
+            $query->execute(array($removedGroup));
162
+        }
163
+        \OCP\Util::writeLog('user_ldap',
164
+            'bgJ "updateGroups" – FINISHED dealing with removed groups.',
165
+            \OCP\Util::DEBUG);
166
+    }
167
+
168
+    /**
169
+     * @return \OCA\User_LDAP\Group_LDAP|\OCA\User_LDAP\Group_Proxy
170
+     */
171
+    static private function getGroupBE() {
172
+        if(!is_null(self::$groupBE)) {
173
+            return self::$groupBE;
174
+        }
175
+        $helper = new Helper(\OC::$server->getConfig());
176
+        $configPrefixes = $helper->getServerConfigurationPrefixes(true);
177
+        $ldapWrapper = new LDAP();
178
+        if(count($configPrefixes) === 1) {
179
+            //avoid the proxy when there is only one LDAP server configured
180
+            $dbc = \OC::$server->getDatabaseConnection();
181
+            $userManager = new Manager(
182
+                \OC::$server->getConfig(),
183
+                new FilesystemHelper(),
184
+                new LogWrapper(),
185
+                \OC::$server->getAvatarManager(),
186
+                new \OCP\Image(),
187
+                $dbc,
188
+                \OC::$server->getUserManager(),
189
+                \OC::$server->getNotificationManager());
190
+            $connector = new Connection($ldapWrapper, $configPrefixes[0]);
191
+            $ldapAccess = new Access($connector, $ldapWrapper, $userManager, $helper, \OC::$server);
192
+            $groupMapper = new GroupMapping($dbc);
193
+            $userMapper  = new UserMapping($dbc);
194
+            $ldapAccess->setGroupMapper($groupMapper);
195
+            $ldapAccess->setUserMapper($userMapper);
196
+            self::$groupBE = new \OCA\User_LDAP\Group_LDAP($ldapAccess);
197
+        } else {
198
+            self::$groupBE = new \OCA\User_LDAP\Group_Proxy($configPrefixes, $ldapWrapper);
199
+        }
200
+
201
+        return self::$groupBE;
202
+    }
203
+
204
+    /**
205
+     * @return array
206
+     */
207
+    static private function getKnownGroups() {
208
+        if(is_array(self::$groupsFromDB)) {
209
+            return self::$groupsFromDB;
210
+        }
211
+        $query = \OCP\DB::prepare('
212 212
 			SELECT `owncloudname`, `owncloudusers`
213 213
 			FROM `*PREFIX*ldap_group_members`
214 214
 		');
215
-		$result = $query->execute()->fetchAll();
216
-		self::$groupsFromDB = array();
217
-		foreach($result as $dataset) {
218
-			self::$groupsFromDB[$dataset['owncloudname']] = $dataset;
219
-		}
220
-
221
-		return self::$groupsFromDB;
222
-	}
215
+        $result = $query->execute()->fetchAll();
216
+        self::$groupsFromDB = array();
217
+        foreach($result as $dataset) {
218
+            self::$groupsFromDB[$dataset['owncloudname']] = $dataset;
219
+        }
220
+
221
+        return self::$groupsFromDB;
222
+    }
223 223
 }
Please login to merge, or discard this patch.
apps/user_ldap/lib/Configuration.php 1 patch
Indentation   +464 added lines, -464 removed lines patch added patch discarded remove patch
@@ -36,493 +36,493 @@
 block discarded – undo
36 36
  */
37 37
 class Configuration {
38 38
 
39
-	protected $configPrefix = null;
40
-	protected $configRead = false;
39
+    protected $configPrefix = null;
40
+    protected $configRead = false;
41 41
 
42
-	//settings
43
-	protected $config = array(
44
-		'ldapHost' => null,
45
-		'ldapPort' => null,
46
-		'ldapBackupHost' => null,
47
-		'ldapBackupPort' => null,
48
-		'ldapBase' => null,
49
-		'ldapBaseUsers' => null,
50
-		'ldapBaseGroups' => null,
51
-		'ldapAgentName' => null,
52
-		'ldapAgentPassword' => null,
53
-		'ldapTLS' => null,
54
-		'turnOffCertCheck' => null,
55
-		'ldapIgnoreNamingRules' => null,
56
-		'ldapUserDisplayName' => null,
57
-		'ldapUserDisplayName2' => null,
58
-		'ldapGidNumber' => null,
59
-		'ldapUserFilterObjectclass' => null,
60
-		'ldapUserFilterGroups' => null,
61
-		'ldapUserFilter' => null,
62
-		'ldapUserFilterMode' => null,
63
-		'ldapGroupFilter' => null,
64
-		'ldapGroupFilterMode' => null,
65
-		'ldapGroupFilterObjectclass' => null,
66
-		'ldapGroupFilterGroups' => null,
67
-		'ldapGroupDisplayName' => null,
68
-		'ldapGroupMemberAssocAttr' => null,
69
-		'ldapLoginFilter' => null,
70
-		'ldapLoginFilterMode' => null,
71
-		'ldapLoginFilterEmail' => null,
72
-		'ldapLoginFilterUsername' => null,
73
-		'ldapLoginFilterAttributes' => null,
74
-		'ldapQuotaAttribute' => null,
75
-		'ldapQuotaDefault' => null,
76
-		'ldapEmailAttribute' => null,
77
-		'ldapCacheTTL' => null,
78
-		'ldapUuidUserAttribute' => 'auto',
79
-		'ldapUuidGroupAttribute' => 'auto',
80
-		'ldapOverrideMainServer' => false,
81
-		'ldapConfigurationActive' => false,
82
-		'ldapAttributesForUserSearch' => null,
83
-		'ldapAttributesForGroupSearch' => null,
84
-		'ldapExperiencedAdmin' => false,
85
-		'homeFolderNamingRule' => null,
86
-		'hasPagedResultSupport' => false,
87
-		'hasMemberOfFilterSupport' => false,
88
-		'useMemberOfToDetectMembership' => true,
89
-		'ldapExpertUsernameAttr' => null,
90
-		'ldapExpertUUIDUserAttr' => null,
91
-		'ldapExpertUUIDGroupAttr' => null,
92
-		'lastJpegPhotoLookup' => null,
93
-		'ldapNestedGroups' => false,
94
-		'ldapPagingSize' => null,
95
-		'turnOnPasswordChange' => false,
96
-		'ldapDynamicGroupMemberURL' => null,
97
-		'ldapDefaultPPolicyDN' => null,
98
-	);
42
+    //settings
43
+    protected $config = array(
44
+        'ldapHost' => null,
45
+        'ldapPort' => null,
46
+        'ldapBackupHost' => null,
47
+        'ldapBackupPort' => null,
48
+        'ldapBase' => null,
49
+        'ldapBaseUsers' => null,
50
+        'ldapBaseGroups' => null,
51
+        'ldapAgentName' => null,
52
+        'ldapAgentPassword' => null,
53
+        'ldapTLS' => null,
54
+        'turnOffCertCheck' => null,
55
+        'ldapIgnoreNamingRules' => null,
56
+        'ldapUserDisplayName' => null,
57
+        'ldapUserDisplayName2' => null,
58
+        'ldapGidNumber' => null,
59
+        'ldapUserFilterObjectclass' => null,
60
+        'ldapUserFilterGroups' => null,
61
+        'ldapUserFilter' => null,
62
+        'ldapUserFilterMode' => null,
63
+        'ldapGroupFilter' => null,
64
+        'ldapGroupFilterMode' => null,
65
+        'ldapGroupFilterObjectclass' => null,
66
+        'ldapGroupFilterGroups' => null,
67
+        'ldapGroupDisplayName' => null,
68
+        'ldapGroupMemberAssocAttr' => null,
69
+        'ldapLoginFilter' => null,
70
+        'ldapLoginFilterMode' => null,
71
+        'ldapLoginFilterEmail' => null,
72
+        'ldapLoginFilterUsername' => null,
73
+        'ldapLoginFilterAttributes' => null,
74
+        'ldapQuotaAttribute' => null,
75
+        'ldapQuotaDefault' => null,
76
+        'ldapEmailAttribute' => null,
77
+        'ldapCacheTTL' => null,
78
+        'ldapUuidUserAttribute' => 'auto',
79
+        'ldapUuidGroupAttribute' => 'auto',
80
+        'ldapOverrideMainServer' => false,
81
+        'ldapConfigurationActive' => false,
82
+        'ldapAttributesForUserSearch' => null,
83
+        'ldapAttributesForGroupSearch' => null,
84
+        'ldapExperiencedAdmin' => false,
85
+        'homeFolderNamingRule' => null,
86
+        'hasPagedResultSupport' => false,
87
+        'hasMemberOfFilterSupport' => false,
88
+        'useMemberOfToDetectMembership' => true,
89
+        'ldapExpertUsernameAttr' => null,
90
+        'ldapExpertUUIDUserAttr' => null,
91
+        'ldapExpertUUIDGroupAttr' => null,
92
+        'lastJpegPhotoLookup' => null,
93
+        'ldapNestedGroups' => false,
94
+        'ldapPagingSize' => null,
95
+        'turnOnPasswordChange' => false,
96
+        'ldapDynamicGroupMemberURL' => null,
97
+        'ldapDefaultPPolicyDN' => null,
98
+    );
99 99
 
100
-	/**
101
-	 * @param string $configPrefix
102
-	 * @param bool $autoRead
103
-	 */
104
-	public function __construct($configPrefix, $autoRead = true) {
105
-		$this->configPrefix = $configPrefix;
106
-		if($autoRead) {
107
-			$this->readConfiguration();
108
-		}
109
-	}
100
+    /**
101
+     * @param string $configPrefix
102
+     * @param bool $autoRead
103
+     */
104
+    public function __construct($configPrefix, $autoRead = true) {
105
+        $this->configPrefix = $configPrefix;
106
+        if($autoRead) {
107
+            $this->readConfiguration();
108
+        }
109
+    }
110 110
 
111
-	/**
112
-	 * @param string $name
113
-	 * @return mixed|null
114
-	 */
115
-	public function __get($name) {
116
-		if(isset($this->config[$name])) {
117
-			return $this->config[$name];
118
-		}
119
-		return null;
120
-	}
111
+    /**
112
+     * @param string $name
113
+     * @return mixed|null
114
+     */
115
+    public function __get($name) {
116
+        if(isset($this->config[$name])) {
117
+            return $this->config[$name];
118
+        }
119
+        return null;
120
+    }
121 121
 
122
-	/**
123
-	 * @param string $name
124
-	 * @param mixed $value
125
-	 */
126
-	public function __set($name, $value) {
127
-		$this->setConfiguration(array($name => $value));
128
-	}
122
+    /**
123
+     * @param string $name
124
+     * @param mixed $value
125
+     */
126
+    public function __set($name, $value) {
127
+        $this->setConfiguration(array($name => $value));
128
+    }
129 129
 
130
-	/**
131
-	 * @return array
132
-	 */
133
-	public function getConfiguration() {
134
-		return $this->config;
135
-	}
130
+    /**
131
+     * @return array
132
+     */
133
+    public function getConfiguration() {
134
+        return $this->config;
135
+    }
136 136
 
137
-	/**
138
-	 * set LDAP configuration with values delivered by an array, not read
139
-	 * from configuration. It does not save the configuration! To do so, you
140
-	 * must call saveConfiguration afterwards.
141
-	 * @param array $config array that holds the config parameters in an associated
142
-	 * array
143
-	 * @param array &$applied optional; array where the set fields will be given to
144
-	 * @return false|null
145
-	 */
146
-	public function setConfiguration($config, &$applied = null) {
147
-		if(!is_array($config)) {
148
-			return false;
149
-		}
137
+    /**
138
+     * set LDAP configuration with values delivered by an array, not read
139
+     * from configuration. It does not save the configuration! To do so, you
140
+     * must call saveConfiguration afterwards.
141
+     * @param array $config array that holds the config parameters in an associated
142
+     * array
143
+     * @param array &$applied optional; array where the set fields will be given to
144
+     * @return false|null
145
+     */
146
+    public function setConfiguration($config, &$applied = null) {
147
+        if(!is_array($config)) {
148
+            return false;
149
+        }
150 150
 
151
-		$cta = $this->getConfigTranslationArray();
152
-		foreach($config as $inputKey => $val) {
153
-			if(strpos($inputKey, '_') !== false && array_key_exists($inputKey, $cta)) {
154
-				$key = $cta[$inputKey];
155
-			} elseif(array_key_exists($inputKey, $this->config)) {
156
-				$key = $inputKey;
157
-			} else {
158
-				continue;
159
-			}
151
+        $cta = $this->getConfigTranslationArray();
152
+        foreach($config as $inputKey => $val) {
153
+            if(strpos($inputKey, '_') !== false && array_key_exists($inputKey, $cta)) {
154
+                $key = $cta[$inputKey];
155
+            } elseif(array_key_exists($inputKey, $this->config)) {
156
+                $key = $inputKey;
157
+            } else {
158
+                continue;
159
+            }
160 160
 
161
-			$setMethod = 'setValue';
162
-			switch($key) {
163
-				case 'ldapAgentPassword':
164
-					$setMethod = 'setRawValue';
165
-					break;
166
-				case 'homeFolderNamingRule':
167
-					$trimmedVal = trim($val);
168
-					if ($trimmedVal !== '' && strpos($val, 'attr:') === false) {
169
-						$val = 'attr:'.$trimmedVal;
170
-					}
171
-					break;
172
-				case 'ldapBase':
173
-				case 'ldapBaseUsers':
174
-				case 'ldapBaseGroups':
175
-				case 'ldapAttributesForUserSearch':
176
-				case 'ldapAttributesForGroupSearch':
177
-				case 'ldapUserFilterObjectclass':
178
-				case 'ldapUserFilterGroups':
179
-				case 'ldapGroupFilterObjectclass':
180
-				case 'ldapGroupFilterGroups':
181
-				case 'ldapLoginFilterAttributes':
182
-					$setMethod = 'setMultiLine';
183
-					break;
184
-			}
185
-			$this->$setMethod($key, $val);
186
-			if(is_array($applied)) {
187
-				$applied[] = $inputKey;
188
-			}
189
-		}
190
-		return null;
191
-	}
161
+            $setMethod = 'setValue';
162
+            switch($key) {
163
+                case 'ldapAgentPassword':
164
+                    $setMethod = 'setRawValue';
165
+                    break;
166
+                case 'homeFolderNamingRule':
167
+                    $trimmedVal = trim($val);
168
+                    if ($trimmedVal !== '' && strpos($val, 'attr:') === false) {
169
+                        $val = 'attr:'.$trimmedVal;
170
+                    }
171
+                    break;
172
+                case 'ldapBase':
173
+                case 'ldapBaseUsers':
174
+                case 'ldapBaseGroups':
175
+                case 'ldapAttributesForUserSearch':
176
+                case 'ldapAttributesForGroupSearch':
177
+                case 'ldapUserFilterObjectclass':
178
+                case 'ldapUserFilterGroups':
179
+                case 'ldapGroupFilterObjectclass':
180
+                case 'ldapGroupFilterGroups':
181
+                case 'ldapLoginFilterAttributes':
182
+                    $setMethod = 'setMultiLine';
183
+                    break;
184
+            }
185
+            $this->$setMethod($key, $val);
186
+            if(is_array($applied)) {
187
+                $applied[] = $inputKey;
188
+            }
189
+        }
190
+        return null;
191
+    }
192 192
 
193
-	public function readConfiguration() {
194
-		if(!$this->configRead && !is_null($this->configPrefix)) {
195
-			$cta = array_flip($this->getConfigTranslationArray());
196
-			foreach($this->config as $key => $val) {
197
-				if(!isset($cta[$key])) {
198
-					//some are determined
199
-					continue;
200
-				}
201
-				$dbKey = $cta[$key];
202
-				switch($key) {
203
-					case 'ldapBase':
204
-					case 'ldapBaseUsers':
205
-					case 'ldapBaseGroups':
206
-					case 'ldapAttributesForUserSearch':
207
-					case 'ldapAttributesForGroupSearch':
208
-					case 'ldapUserFilterObjectclass':
209
-					case 'ldapUserFilterGroups':
210
-					case 'ldapGroupFilterObjectclass':
211
-					case 'ldapGroupFilterGroups':
212
-					case 'ldapLoginFilterAttributes':
213
-						$readMethod = 'getMultiLine';
214
-						break;
215
-					case 'ldapIgnoreNamingRules':
216
-						$readMethod = 'getSystemValue';
217
-						$dbKey = $key;
218
-						break;
219
-					case 'ldapAgentPassword':
220
-						$readMethod = 'getPwd';
221
-						break;
222
-					case 'ldapUserDisplayName2':
223
-					case 'ldapGroupDisplayName':
224
-						$readMethod = 'getLcValue';
225
-						break;
226
-					case 'ldapUserDisplayName':
227
-					default:
228
-						// user display name does not lower case because
229
-						// we rely on an upper case N as indicator whether to
230
-						// auto-detect it or not. FIXME
231
-						$readMethod = 'getValue';
232
-						break;
233
-				}
234
-				$this->config[$key] = $this->$readMethod($dbKey);
235
-			}
236
-			$this->configRead = true;
237
-		}
238
-	}
193
+    public function readConfiguration() {
194
+        if(!$this->configRead && !is_null($this->configPrefix)) {
195
+            $cta = array_flip($this->getConfigTranslationArray());
196
+            foreach($this->config as $key => $val) {
197
+                if(!isset($cta[$key])) {
198
+                    //some are determined
199
+                    continue;
200
+                }
201
+                $dbKey = $cta[$key];
202
+                switch($key) {
203
+                    case 'ldapBase':
204
+                    case 'ldapBaseUsers':
205
+                    case 'ldapBaseGroups':
206
+                    case 'ldapAttributesForUserSearch':
207
+                    case 'ldapAttributesForGroupSearch':
208
+                    case 'ldapUserFilterObjectclass':
209
+                    case 'ldapUserFilterGroups':
210
+                    case 'ldapGroupFilterObjectclass':
211
+                    case 'ldapGroupFilterGroups':
212
+                    case 'ldapLoginFilterAttributes':
213
+                        $readMethod = 'getMultiLine';
214
+                        break;
215
+                    case 'ldapIgnoreNamingRules':
216
+                        $readMethod = 'getSystemValue';
217
+                        $dbKey = $key;
218
+                        break;
219
+                    case 'ldapAgentPassword':
220
+                        $readMethod = 'getPwd';
221
+                        break;
222
+                    case 'ldapUserDisplayName2':
223
+                    case 'ldapGroupDisplayName':
224
+                        $readMethod = 'getLcValue';
225
+                        break;
226
+                    case 'ldapUserDisplayName':
227
+                    default:
228
+                        // user display name does not lower case because
229
+                        // we rely on an upper case N as indicator whether to
230
+                        // auto-detect it or not. FIXME
231
+                        $readMethod = 'getValue';
232
+                        break;
233
+                }
234
+                $this->config[$key] = $this->$readMethod($dbKey);
235
+            }
236
+            $this->configRead = true;
237
+        }
238
+    }
239 239
 
240
-	/**
241
-	 * saves the current Configuration in the database
242
-	 */
243
-	public function saveConfiguration() {
244
-		$cta = array_flip($this->getConfigTranslationArray());
245
-		foreach($this->config as $key => $value) {
246
-			switch ($key) {
247
-				case 'ldapAgentPassword':
248
-					$value = base64_encode($value);
249
-					break;
250
-				case 'ldapBase':
251
-				case 'ldapBaseUsers':
252
-				case 'ldapBaseGroups':
253
-				case 'ldapAttributesForUserSearch':
254
-				case 'ldapAttributesForGroupSearch':
255
-				case 'ldapUserFilterObjectclass':
256
-				case 'ldapUserFilterGroups':
257
-				case 'ldapGroupFilterObjectclass':
258
-				case 'ldapGroupFilterGroups':
259
-				case 'ldapLoginFilterAttributes':
260
-					if(is_array($value)) {
261
-						$value = implode("\n", $value);
262
-					}
263
-					break;
264
-				//following options are not stored but detected, skip them
265
-				case 'ldapIgnoreNamingRules':
266
-				case 'hasPagedResultSupport':
267
-				case 'ldapUuidUserAttribute':
268
-				case 'ldapUuidGroupAttribute':
269
-					continue 2;
270
-			}
271
-			if(is_null($value)) {
272
-				$value = '';
273
-			}
274
-			$this->saveValue($cta[$key], $value);
275
-		}
276
-		$this->saveValue('_lastChange', time());
277
-	}
240
+    /**
241
+     * saves the current Configuration in the database
242
+     */
243
+    public function saveConfiguration() {
244
+        $cta = array_flip($this->getConfigTranslationArray());
245
+        foreach($this->config as $key => $value) {
246
+            switch ($key) {
247
+                case 'ldapAgentPassword':
248
+                    $value = base64_encode($value);
249
+                    break;
250
+                case 'ldapBase':
251
+                case 'ldapBaseUsers':
252
+                case 'ldapBaseGroups':
253
+                case 'ldapAttributesForUserSearch':
254
+                case 'ldapAttributesForGroupSearch':
255
+                case 'ldapUserFilterObjectclass':
256
+                case 'ldapUserFilterGroups':
257
+                case 'ldapGroupFilterObjectclass':
258
+                case 'ldapGroupFilterGroups':
259
+                case 'ldapLoginFilterAttributes':
260
+                    if(is_array($value)) {
261
+                        $value = implode("\n", $value);
262
+                    }
263
+                    break;
264
+                //following options are not stored but detected, skip them
265
+                case 'ldapIgnoreNamingRules':
266
+                case 'hasPagedResultSupport':
267
+                case 'ldapUuidUserAttribute':
268
+                case 'ldapUuidGroupAttribute':
269
+                    continue 2;
270
+            }
271
+            if(is_null($value)) {
272
+                $value = '';
273
+            }
274
+            $this->saveValue($cta[$key], $value);
275
+        }
276
+        $this->saveValue('_lastChange', time());
277
+    }
278 278
 
279
-	/**
280
-	 * @param string $varName
281
-	 * @return array|string
282
-	 */
283
-	protected function getMultiLine($varName) {
284
-		$value = $this->getValue($varName);
285
-		if(empty($value)) {
286
-			$value = '';
287
-		} else {
288
-			$value = preg_split('/\r\n|\r|\n/', $value);
289
-		}
279
+    /**
280
+     * @param string $varName
281
+     * @return array|string
282
+     */
283
+    protected function getMultiLine($varName) {
284
+        $value = $this->getValue($varName);
285
+        if(empty($value)) {
286
+            $value = '';
287
+        } else {
288
+            $value = preg_split('/\r\n|\r|\n/', $value);
289
+        }
290 290
 
291
-		return $value;
292
-	}
291
+        return $value;
292
+    }
293 293
 
294
-	/**
295
-	 * Sets multi-line values as arrays
296
-	 * 
297
-	 * @param string $varName name of config-key
298
-	 * @param array|string $value to set
299
-	 */
300
-	protected function setMultiLine($varName, $value) {
301
-		if(empty($value)) {
302
-			$value = '';
303
-		} else if (!is_array($value)) {
304
-			$value = preg_split('/\r\n|\r|\n|;/', $value);
305
-			if($value === false) {
306
-				$value = '';
307
-			}
308
-		}
294
+    /**
295
+     * Sets multi-line values as arrays
296
+     * 
297
+     * @param string $varName name of config-key
298
+     * @param array|string $value to set
299
+     */
300
+    protected function setMultiLine($varName, $value) {
301
+        if(empty($value)) {
302
+            $value = '';
303
+        } else if (!is_array($value)) {
304
+            $value = preg_split('/\r\n|\r|\n|;/', $value);
305
+            if($value === false) {
306
+                $value = '';
307
+            }
308
+        }
309 309
 
310
-		if(!is_array($value)) {
311
-			$finalValue = trim($value);
312
-		} else {
313
-			$finalValue = [];
314
-			foreach($value as $key => $val) {
315
-				if(is_string($val)) {
316
-					$val = trim($val);
317
-					if ($val !== '') {
318
-						//accidental line breaks are not wanted and can cause
319
-						// odd behaviour. Thus, away with them.
320
-						$finalValue[] = $val;
321
-					}
322
-				} else {
323
-					$finalValue[] = $val;
324
-				}
325
-			}
326
-		}
310
+        if(!is_array($value)) {
311
+            $finalValue = trim($value);
312
+        } else {
313
+            $finalValue = [];
314
+            foreach($value as $key => $val) {
315
+                if(is_string($val)) {
316
+                    $val = trim($val);
317
+                    if ($val !== '') {
318
+                        //accidental line breaks are not wanted and can cause
319
+                        // odd behaviour. Thus, away with them.
320
+                        $finalValue[] = $val;
321
+                    }
322
+                } else {
323
+                    $finalValue[] = $val;
324
+                }
325
+            }
326
+        }
327 327
 
328
-		$this->setRawValue($varName, $finalValue);
329
-	}
328
+        $this->setRawValue($varName, $finalValue);
329
+    }
330 330
 
331
-	/**
332
-	 * @param string $varName
333
-	 * @return string
334
-	 */
335
-	protected function getPwd($varName) {
336
-		return base64_decode($this->getValue($varName));
337
-	}
331
+    /**
332
+     * @param string $varName
333
+     * @return string
334
+     */
335
+    protected function getPwd($varName) {
336
+        return base64_decode($this->getValue($varName));
337
+    }
338 338
 
339
-	/**
340
-	 * @param string $varName
341
-	 * @return string
342
-	 */
343
-	protected function getLcValue($varName) {
344
-		return mb_strtolower($this->getValue($varName), 'UTF-8');
345
-	}
339
+    /**
340
+     * @param string $varName
341
+     * @return string
342
+     */
343
+    protected function getLcValue($varName) {
344
+        return mb_strtolower($this->getValue($varName), 'UTF-8');
345
+    }
346 346
 
347
-	/**
348
-	 * @param string $varName
349
-	 * @return string
350
-	 */
351
-	protected function getSystemValue($varName) {
352
-		//FIXME: if another system value is added, softcode the default value
353
-		return \OC::$server->getConfig()->getSystemValue($varName, false);
354
-	}
347
+    /**
348
+     * @param string $varName
349
+     * @return string
350
+     */
351
+    protected function getSystemValue($varName) {
352
+        //FIXME: if another system value is added, softcode the default value
353
+        return \OC::$server->getConfig()->getSystemValue($varName, false);
354
+    }
355 355
 
356
-	/**
357
-	 * @param string $varName
358
-	 * @return string
359
-	 */
360
-	protected function getValue($varName) {
361
-		static $defaults;
362
-		if(is_null($defaults)) {
363
-			$defaults = $this->getDefaults();
364
-		}
365
-		return \OCP\Config::getAppValue('user_ldap',
366
-										$this->configPrefix.$varName,
367
-										$defaults[$varName]);
368
-	}
356
+    /**
357
+     * @param string $varName
358
+     * @return string
359
+     */
360
+    protected function getValue($varName) {
361
+        static $defaults;
362
+        if(is_null($defaults)) {
363
+            $defaults = $this->getDefaults();
364
+        }
365
+        return \OCP\Config::getAppValue('user_ldap',
366
+                                        $this->configPrefix.$varName,
367
+                                        $defaults[$varName]);
368
+    }
369 369
 
370
-	/**
371
-	 * Sets a scalar value.
372
-	 * 
373
-	 * @param string $varName name of config key
374
-	 * @param mixed $value to set
375
-	 */
376
-	protected function setValue($varName, $value) {
377
-		if(is_string($value)) {
378
-			$value = trim($value);
379
-		}
380
-		$this->config[$varName] = $value;
381
-	}
370
+    /**
371
+     * Sets a scalar value.
372
+     * 
373
+     * @param string $varName name of config key
374
+     * @param mixed $value to set
375
+     */
376
+    protected function setValue($varName, $value) {
377
+        if(is_string($value)) {
378
+            $value = trim($value);
379
+        }
380
+        $this->config[$varName] = $value;
381
+    }
382 382
 
383
-	/**
384
-	 * Sets a scalar value without trimming.
385
-	 *
386
-	 * @param string $varName name of config key
387
-	 * @param mixed $value to set
388
-	 */
389
-	protected function setRawValue($varName, $value) {
390
-		$this->config[$varName] = $value;
391
-	}
383
+    /**
384
+     * Sets a scalar value without trimming.
385
+     *
386
+     * @param string $varName name of config key
387
+     * @param mixed $value to set
388
+     */
389
+    protected function setRawValue($varName, $value) {
390
+        $this->config[$varName] = $value;
391
+    }
392 392
 
393
-	/**
394
-	 * @param string $varName
395
-	 * @param string $value
396
-	 * @return bool
397
-	 */
398
-	protected function saveValue($varName, $value) {
399
-		\OC::$server->getConfig()->setAppValue(
400
-			'user_ldap',
401
-			$this->configPrefix.$varName,
402
-			$value
403
-		);
404
-		return true;
405
-	}
393
+    /**
394
+     * @param string $varName
395
+     * @param string $value
396
+     * @return bool
397
+     */
398
+    protected function saveValue($varName, $value) {
399
+        \OC::$server->getConfig()->setAppValue(
400
+            'user_ldap',
401
+            $this->configPrefix.$varName,
402
+            $value
403
+        );
404
+        return true;
405
+    }
406 406
 
407
-	/**
408
-	 * @return array an associative array with the default values. Keys are correspond
409
-	 * to config-value entries in the database table
410
-	 */
411
-	public function getDefaults() {
412
-		return array(
413
-			'ldap_host'                         => '',
414
-			'ldap_port'                         => '',
415
-			'ldap_backup_host'                  => '',
416
-			'ldap_backup_port'                  => '',
417
-			'ldap_override_main_server'         => '',
418
-			'ldap_dn'                           => '',
419
-			'ldap_agent_password'               => '',
420
-			'ldap_base'                         => '',
421
-			'ldap_base_users'                   => '',
422
-			'ldap_base_groups'                  => '',
423
-			'ldap_userlist_filter'              => '',
424
-			'ldap_user_filter_mode'             => 0,
425
-			'ldap_userfilter_objectclass'       => '',
426
-			'ldap_userfilter_groups'            => '',
427
-			'ldap_login_filter'                 => '',
428
-			'ldap_login_filter_mode'            => 0,
429
-			'ldap_loginfilter_email'            => 0,
430
-			'ldap_loginfilter_username'         => 1,
431
-			'ldap_loginfilter_attributes'       => '',
432
-			'ldap_group_filter'                 => '',
433
-			'ldap_group_filter_mode'            => 0,
434
-			'ldap_groupfilter_objectclass'      => '',
435
-			'ldap_groupfilter_groups'           => '',
436
-			'ldap_gid_number'                   => 'gidNumber',
437
-			'ldap_display_name'                 => 'displayName',
438
-			'ldap_user_display_name_2'			=> '',
439
-			'ldap_group_display_name'           => 'cn',
440
-			'ldap_tls'                          => 0,
441
-			'ldap_quota_def'                    => '',
442
-			'ldap_quota_attr'                   => '',
443
-			'ldap_email_attr'                   => '',
444
-			'ldap_group_member_assoc_attribute' => 'uniqueMember',
445
-			'ldap_cache_ttl'                    => 600,
446
-			'ldap_uuid_user_attribute'          => 'auto',
447
-			'ldap_uuid_group_attribute'         => 'auto',
448
-			'home_folder_naming_rule'           => '',
449
-			'ldap_turn_off_cert_check'          => 0,
450
-			'ldap_configuration_active'         => 0,
451
-			'ldap_attributes_for_user_search'   => '',
452
-			'ldap_attributes_for_group_search'  => '',
453
-			'ldap_expert_username_attr'         => '',
454
-			'ldap_expert_uuid_user_attr'        => '',
455
-			'ldap_expert_uuid_group_attr'       => '',
456
-			'has_memberof_filter_support'       => 0,
457
-			'use_memberof_to_detect_membership' => 1,
458
-			'last_jpegPhoto_lookup'             => 0,
459
-			'ldap_nested_groups'                => 0,
460
-			'ldap_paging_size'                  => 500,
461
-			'ldap_turn_on_pwd_change'           => 0,
462
-			'ldap_experienced_admin'            => 0,
463
-			'ldap_dynamic_group_member_url'     => '',
464
-			'ldap_default_ppolicy_dn'           => '',
465
-		);
466
-	}
407
+    /**
408
+     * @return array an associative array with the default values. Keys are correspond
409
+     * to config-value entries in the database table
410
+     */
411
+    public function getDefaults() {
412
+        return array(
413
+            'ldap_host'                         => '',
414
+            'ldap_port'                         => '',
415
+            'ldap_backup_host'                  => '',
416
+            'ldap_backup_port'                  => '',
417
+            'ldap_override_main_server'         => '',
418
+            'ldap_dn'                           => '',
419
+            'ldap_agent_password'               => '',
420
+            'ldap_base'                         => '',
421
+            'ldap_base_users'                   => '',
422
+            'ldap_base_groups'                  => '',
423
+            'ldap_userlist_filter'              => '',
424
+            'ldap_user_filter_mode'             => 0,
425
+            'ldap_userfilter_objectclass'       => '',
426
+            'ldap_userfilter_groups'            => '',
427
+            'ldap_login_filter'                 => '',
428
+            'ldap_login_filter_mode'            => 0,
429
+            'ldap_loginfilter_email'            => 0,
430
+            'ldap_loginfilter_username'         => 1,
431
+            'ldap_loginfilter_attributes'       => '',
432
+            'ldap_group_filter'                 => '',
433
+            'ldap_group_filter_mode'            => 0,
434
+            'ldap_groupfilter_objectclass'      => '',
435
+            'ldap_groupfilter_groups'           => '',
436
+            'ldap_gid_number'                   => 'gidNumber',
437
+            'ldap_display_name'                 => 'displayName',
438
+            'ldap_user_display_name_2'			=> '',
439
+            'ldap_group_display_name'           => 'cn',
440
+            'ldap_tls'                          => 0,
441
+            'ldap_quota_def'                    => '',
442
+            'ldap_quota_attr'                   => '',
443
+            'ldap_email_attr'                   => '',
444
+            'ldap_group_member_assoc_attribute' => 'uniqueMember',
445
+            'ldap_cache_ttl'                    => 600,
446
+            'ldap_uuid_user_attribute'          => 'auto',
447
+            'ldap_uuid_group_attribute'         => 'auto',
448
+            'home_folder_naming_rule'           => '',
449
+            'ldap_turn_off_cert_check'          => 0,
450
+            'ldap_configuration_active'         => 0,
451
+            'ldap_attributes_for_user_search'   => '',
452
+            'ldap_attributes_for_group_search'  => '',
453
+            'ldap_expert_username_attr'         => '',
454
+            'ldap_expert_uuid_user_attr'        => '',
455
+            'ldap_expert_uuid_group_attr'       => '',
456
+            'has_memberof_filter_support'       => 0,
457
+            'use_memberof_to_detect_membership' => 1,
458
+            'last_jpegPhoto_lookup'             => 0,
459
+            'ldap_nested_groups'                => 0,
460
+            'ldap_paging_size'                  => 500,
461
+            'ldap_turn_on_pwd_change'           => 0,
462
+            'ldap_experienced_admin'            => 0,
463
+            'ldap_dynamic_group_member_url'     => '',
464
+            'ldap_default_ppolicy_dn'           => '',
465
+        );
466
+    }
467 467
 
468
-	/**
469
-	 * @return array that maps internal variable names to database fields
470
-	 */
471
-	public function getConfigTranslationArray() {
472
-		//TODO: merge them into one representation
473
-		static $array = array(
474
-			'ldap_host'                         => 'ldapHost',
475
-			'ldap_port'                         => 'ldapPort',
476
-			'ldap_backup_host'                  => 'ldapBackupHost',
477
-			'ldap_backup_port'                  => 'ldapBackupPort',
478
-			'ldap_override_main_server'         => 'ldapOverrideMainServer',
479
-			'ldap_dn'                           => 'ldapAgentName',
480
-			'ldap_agent_password'               => 'ldapAgentPassword',
481
-			'ldap_base'                         => 'ldapBase',
482
-			'ldap_base_users'                   => 'ldapBaseUsers',
483
-			'ldap_base_groups'                  => 'ldapBaseGroups',
484
-			'ldap_userfilter_objectclass'       => 'ldapUserFilterObjectclass',
485
-			'ldap_userfilter_groups'            => 'ldapUserFilterGroups',
486
-			'ldap_userlist_filter'              => 'ldapUserFilter',
487
-			'ldap_user_filter_mode'             => 'ldapUserFilterMode',
488
-			'ldap_login_filter'                 => 'ldapLoginFilter',
489
-			'ldap_login_filter_mode'            => 'ldapLoginFilterMode',
490
-			'ldap_loginfilter_email'            => 'ldapLoginFilterEmail',
491
-			'ldap_loginfilter_username'         => 'ldapLoginFilterUsername',
492
-			'ldap_loginfilter_attributes'       => 'ldapLoginFilterAttributes',
493
-			'ldap_group_filter'                 => 'ldapGroupFilter',
494
-			'ldap_group_filter_mode'            => 'ldapGroupFilterMode',
495
-			'ldap_groupfilter_objectclass'      => 'ldapGroupFilterObjectclass',
496
-			'ldap_groupfilter_groups'           => 'ldapGroupFilterGroups',
497
-			'ldap_gid_number'                   => 'ldapGidNumber',
498
-			'ldap_display_name'                 => 'ldapUserDisplayName',
499
-			'ldap_user_display_name_2'			=> 'ldapUserDisplayName2',
500
-			'ldap_group_display_name'           => 'ldapGroupDisplayName',
501
-			'ldap_tls'                          => 'ldapTLS',
502
-			'ldap_quota_def'                    => 'ldapQuotaDefault',
503
-			'ldap_quota_attr'                   => 'ldapQuotaAttribute',
504
-			'ldap_email_attr'                   => 'ldapEmailAttribute',
505
-			'ldap_group_member_assoc_attribute' => 'ldapGroupMemberAssocAttr',
506
-			'ldap_cache_ttl'                    => 'ldapCacheTTL',
507
-			'home_folder_naming_rule'           => 'homeFolderNamingRule',
508
-			'ldap_turn_off_cert_check'          => 'turnOffCertCheck',
509
-			'ldap_configuration_active'         => 'ldapConfigurationActive',
510
-			'ldap_attributes_for_user_search'   => 'ldapAttributesForUserSearch',
511
-			'ldap_attributes_for_group_search'  => 'ldapAttributesForGroupSearch',
512
-			'ldap_expert_username_attr'         => 'ldapExpertUsernameAttr',
513
-			'ldap_expert_uuid_user_attr'        => 'ldapExpertUUIDUserAttr',
514
-			'ldap_expert_uuid_group_attr'       => 'ldapExpertUUIDGroupAttr',
515
-			'has_memberof_filter_support'       => 'hasMemberOfFilterSupport',
516
-			'use_memberof_to_detect_membership' => 'useMemberOfToDetectMembership',
517
-			'last_jpegPhoto_lookup'             => 'lastJpegPhotoLookup',
518
-			'ldap_nested_groups'                => 'ldapNestedGroups',
519
-			'ldap_paging_size'                  => 'ldapPagingSize',
520
-			'ldap_turn_on_pwd_change'           => 'turnOnPasswordChange',
521
-			'ldap_experienced_admin'            => 'ldapExperiencedAdmin',
522
-			'ldap_dynamic_group_member_url'     => 'ldapDynamicGroupMemberURL',
523
-			'ldap_default_ppolicy_dn'           => 'ldapDefaultPPolicyDN',
524
-		);
525
-		return $array;
526
-	}
468
+    /**
469
+     * @return array that maps internal variable names to database fields
470
+     */
471
+    public function getConfigTranslationArray() {
472
+        //TODO: merge them into one representation
473
+        static $array = array(
474
+            'ldap_host'                         => 'ldapHost',
475
+            'ldap_port'                         => 'ldapPort',
476
+            'ldap_backup_host'                  => 'ldapBackupHost',
477
+            'ldap_backup_port'                  => 'ldapBackupPort',
478
+            'ldap_override_main_server'         => 'ldapOverrideMainServer',
479
+            'ldap_dn'                           => 'ldapAgentName',
480
+            'ldap_agent_password'               => 'ldapAgentPassword',
481
+            'ldap_base'                         => 'ldapBase',
482
+            'ldap_base_users'                   => 'ldapBaseUsers',
483
+            'ldap_base_groups'                  => 'ldapBaseGroups',
484
+            'ldap_userfilter_objectclass'       => 'ldapUserFilterObjectclass',
485
+            'ldap_userfilter_groups'            => 'ldapUserFilterGroups',
486
+            'ldap_userlist_filter'              => 'ldapUserFilter',
487
+            'ldap_user_filter_mode'             => 'ldapUserFilterMode',
488
+            'ldap_login_filter'                 => 'ldapLoginFilter',
489
+            'ldap_login_filter_mode'            => 'ldapLoginFilterMode',
490
+            'ldap_loginfilter_email'            => 'ldapLoginFilterEmail',
491
+            'ldap_loginfilter_username'         => 'ldapLoginFilterUsername',
492
+            'ldap_loginfilter_attributes'       => 'ldapLoginFilterAttributes',
493
+            'ldap_group_filter'                 => 'ldapGroupFilter',
494
+            'ldap_group_filter_mode'            => 'ldapGroupFilterMode',
495
+            'ldap_groupfilter_objectclass'      => 'ldapGroupFilterObjectclass',
496
+            'ldap_groupfilter_groups'           => 'ldapGroupFilterGroups',
497
+            'ldap_gid_number'                   => 'ldapGidNumber',
498
+            'ldap_display_name'                 => 'ldapUserDisplayName',
499
+            'ldap_user_display_name_2'			=> 'ldapUserDisplayName2',
500
+            'ldap_group_display_name'           => 'ldapGroupDisplayName',
501
+            'ldap_tls'                          => 'ldapTLS',
502
+            'ldap_quota_def'                    => 'ldapQuotaDefault',
503
+            'ldap_quota_attr'                   => 'ldapQuotaAttribute',
504
+            'ldap_email_attr'                   => 'ldapEmailAttribute',
505
+            'ldap_group_member_assoc_attribute' => 'ldapGroupMemberAssocAttr',
506
+            'ldap_cache_ttl'                    => 'ldapCacheTTL',
507
+            'home_folder_naming_rule'           => 'homeFolderNamingRule',
508
+            'ldap_turn_off_cert_check'          => 'turnOffCertCheck',
509
+            'ldap_configuration_active'         => 'ldapConfigurationActive',
510
+            'ldap_attributes_for_user_search'   => 'ldapAttributesForUserSearch',
511
+            'ldap_attributes_for_group_search'  => 'ldapAttributesForGroupSearch',
512
+            'ldap_expert_username_attr'         => 'ldapExpertUsernameAttr',
513
+            'ldap_expert_uuid_user_attr'        => 'ldapExpertUUIDUserAttr',
514
+            'ldap_expert_uuid_group_attr'       => 'ldapExpertUUIDGroupAttr',
515
+            'has_memberof_filter_support'       => 'hasMemberOfFilterSupport',
516
+            'use_memberof_to_detect_membership' => 'useMemberOfToDetectMembership',
517
+            'last_jpegPhoto_lookup'             => 'lastJpegPhotoLookup',
518
+            'ldap_nested_groups'                => 'ldapNestedGroups',
519
+            'ldap_paging_size'                  => 'ldapPagingSize',
520
+            'ldap_turn_on_pwd_change'           => 'turnOnPasswordChange',
521
+            'ldap_experienced_admin'            => 'ldapExperiencedAdmin',
522
+            'ldap_dynamic_group_member_url'     => 'ldapDynamicGroupMemberURL',
523
+            'ldap_default_ppolicy_dn'           => 'ldapDefaultPPolicyDN',
524
+        );
525
+        return $array;
526
+    }
527 527
 
528 528
 }
Please login to merge, or discard this patch.