@@ -31,72 +31,72 @@ |
||
31 | 31 | |
32 | 32 | class Notifier implements INotifier { |
33 | 33 | |
34 | - /** @var IFactory */ |
|
35 | - protected $l10nFactory; |
|
34 | + /** @var IFactory */ |
|
35 | + protected $l10nFactory; |
|
36 | 36 | |
37 | - /** |
|
38 | - * @param IFactory $l10nFactory |
|
39 | - */ |
|
40 | - public function __construct(\OCP\L10N\IFactory $l10nFactory) { |
|
41 | - $this->l10nFactory = $l10nFactory; |
|
42 | - } |
|
37 | + /** |
|
38 | + * @param IFactory $l10nFactory |
|
39 | + */ |
|
40 | + public function __construct(\OCP\L10N\IFactory $l10nFactory) { |
|
41 | + $this->l10nFactory = $l10nFactory; |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * Identifier of the notifier, only use [a-z0-9_] |
|
46 | - * |
|
47 | - * @return string |
|
48 | - * @since 17.0.0 |
|
49 | - */ |
|
50 | - public function getID(): string { |
|
51 | - return 'user_ldap'; |
|
52 | - } |
|
44 | + /** |
|
45 | + * Identifier of the notifier, only use [a-z0-9_] |
|
46 | + * |
|
47 | + * @return string |
|
48 | + * @since 17.0.0 |
|
49 | + */ |
|
50 | + public function getID(): string { |
|
51 | + return 'user_ldap'; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Human readable name describing the notifier |
|
56 | - * |
|
57 | - * @return string |
|
58 | - * @since 17.0.0 |
|
59 | - */ |
|
60 | - public function getName(): string { |
|
61 | - return $this->l10nFactory->get('user_ldap')->t('LDAP User backend'); |
|
62 | - } |
|
54 | + /** |
|
55 | + * Human readable name describing the notifier |
|
56 | + * |
|
57 | + * @return string |
|
58 | + * @since 17.0.0 |
|
59 | + */ |
|
60 | + public function getName(): string { |
|
61 | + return $this->l10nFactory->get('user_ldap')->t('LDAP User backend'); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * @param INotification $notification |
|
66 | - * @param string $languageCode The code of the language that should be used to prepare the notification |
|
67 | - * @return INotification |
|
68 | - * @throws \InvalidArgumentException When the notification was not prepared by a notifier |
|
69 | - */ |
|
70 | - public function prepare(INotification $notification, string $languageCode): INotification { |
|
71 | - if ($notification->getApp() !== 'user_ldap') { |
|
72 | - // Not my app => throw |
|
73 | - throw new \InvalidArgumentException(); |
|
74 | - } |
|
64 | + /** |
|
65 | + * @param INotification $notification |
|
66 | + * @param string $languageCode The code of the language that should be used to prepare the notification |
|
67 | + * @return INotification |
|
68 | + * @throws \InvalidArgumentException When the notification was not prepared by a notifier |
|
69 | + */ |
|
70 | + public function prepare(INotification $notification, string $languageCode): INotification { |
|
71 | + if ($notification->getApp() !== 'user_ldap') { |
|
72 | + // Not my app => throw |
|
73 | + throw new \InvalidArgumentException(); |
|
74 | + } |
|
75 | 75 | |
76 | - // Read the language from the notification |
|
77 | - $l = $this->l10nFactory->get('user_ldap', $languageCode); |
|
76 | + // Read the language from the notification |
|
77 | + $l = $this->l10nFactory->get('user_ldap', $languageCode); |
|
78 | 78 | |
79 | - switch ($notification->getSubject()) { |
|
80 | - // Deal with known subjects |
|
81 | - case 'pwd_exp_warn_days': |
|
82 | - $params = $notification->getSubjectParameters(); |
|
83 | - $days = (int) $params[0]; |
|
84 | - if ($days === 2) { |
|
85 | - $notification->setParsedSubject($l->t('Your password will expire tomorrow.')); |
|
86 | - } elseif ($days === 1) { |
|
87 | - $notification->setParsedSubject($l->t('Your password will expire today.')); |
|
88 | - } else { |
|
89 | - $notification->setParsedSubject($l->n( |
|
90 | - 'Your password will expire within %n day.', |
|
91 | - 'Your password will expire within %n days.', |
|
92 | - $days |
|
93 | - )); |
|
94 | - } |
|
95 | - return $notification; |
|
79 | + switch ($notification->getSubject()) { |
|
80 | + // Deal with known subjects |
|
81 | + case 'pwd_exp_warn_days': |
|
82 | + $params = $notification->getSubjectParameters(); |
|
83 | + $days = (int) $params[0]; |
|
84 | + if ($days === 2) { |
|
85 | + $notification->setParsedSubject($l->t('Your password will expire tomorrow.')); |
|
86 | + } elseif ($days === 1) { |
|
87 | + $notification->setParsedSubject($l->t('Your password will expire today.')); |
|
88 | + } else { |
|
89 | + $notification->setParsedSubject($l->n( |
|
90 | + 'Your password will expire within %n day.', |
|
91 | + 'Your password will expire within %n days.', |
|
92 | + $days |
|
93 | + )); |
|
94 | + } |
|
95 | + return $notification; |
|
96 | 96 | |
97 | - default: |
|
98 | - // Unknown subject => Unknown notification => throw |
|
99 | - throw new \InvalidArgumentException(); |
|
100 | - } |
|
101 | - } |
|
97 | + default: |
|
98 | + // Unknown subject => Unknown notification => throw |
|
99 | + throw new \InvalidArgumentException(); |
|
100 | + } |
|
101 | + } |
|
102 | 102 | } |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | $this->respondToActions |= $respondToActions; |
55 | 55 | |
56 | 56 | foreach ($this->which as $action => $v) { |
57 | - if ((bool)($respondToActions & $action)) { |
|
57 | + if ((bool) ($respondToActions & $action)) { |
|
58 | 58 | $this->which[$action] = $plugin; |
59 | 59 | \OC::$server->getLogger()->debug("Registered action ".$action." to plugin ".get_class($plugin), ['app' => 'user_ldap']); |
60 | 60 | } |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | $plugin = $this->which[GroupInterface::COUNT_USERS]; |
148 | 148 | |
149 | 149 | if ($plugin) { |
150 | - return $plugin->countUsersInGroup($gid,$search); |
|
150 | + return $plugin->countUsersInGroup($gid, $search); |
|
151 | 151 | } |
152 | 152 | throw new \Exception('No plugin implements countUsersInGroup in this LDAP Backend.'); |
153 | 153 | } |
@@ -26,161 +26,161 @@ |
||
26 | 26 | use OCP\GroupInterface; |
27 | 27 | |
28 | 28 | class GroupPluginManager { |
29 | - private int $respondToActions = 0; |
|
30 | - |
|
31 | - /** @var array<int, ?ILDAPGroupPlugin> */ |
|
32 | - private array $which = [ |
|
33 | - GroupInterface::CREATE_GROUP => null, |
|
34 | - GroupInterface::DELETE_GROUP => null, |
|
35 | - GroupInterface::ADD_TO_GROUP => null, |
|
36 | - GroupInterface::REMOVE_FROM_GROUP => null, |
|
37 | - GroupInterface::COUNT_USERS => null, |
|
38 | - GroupInterface::GROUP_DETAILS => null |
|
39 | - ]; |
|
40 | - |
|
41 | - private bool $suppressDeletion = false; |
|
42 | - |
|
43 | - /** |
|
44 | - * @return int All implemented actions |
|
45 | - */ |
|
46 | - public function getImplementedActions() { |
|
47 | - return $this->respondToActions; |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * Registers a group plugin that may implement some actions, overriding User_LDAP's group actions. |
|
52 | - * @param ILDAPGroupPlugin $plugin |
|
53 | - */ |
|
54 | - public function register(ILDAPGroupPlugin $plugin) { |
|
55 | - $respondToActions = $plugin->respondToActions(); |
|
56 | - $this->respondToActions |= $respondToActions; |
|
57 | - |
|
58 | - foreach ($this->which as $action => $v) { |
|
59 | - if ((bool)($respondToActions & $action)) { |
|
60 | - $this->which[$action] = $plugin; |
|
61 | - \OC::$server->getLogger()->debug("Registered action ".$action." to plugin ".get_class($plugin), ['app' => 'user_ldap']); |
|
62 | - } |
|
63 | - } |
|
64 | - } |
|
65 | - |
|
66 | - /** |
|
67 | - * Signal if there is a registered plugin that implements some given actions |
|
68 | - * @param int $actions Actions defined in \OCP\GroupInterface, like GroupInterface::REMOVE_FROM_GROUP |
|
69 | - * @return bool |
|
70 | - */ |
|
71 | - public function implementsActions($actions) { |
|
72 | - return ($actions & $this->respondToActions) == $actions; |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * Create a group |
|
77 | - * @param string $gid Group Id |
|
78 | - * @return string | null The group DN if group creation was successful. |
|
79 | - * @throws \Exception |
|
80 | - */ |
|
81 | - public function createGroup($gid) { |
|
82 | - $plugin = $this->which[GroupInterface::CREATE_GROUP]; |
|
83 | - |
|
84 | - if ($plugin) { |
|
85 | - return $plugin->createGroup($gid); |
|
86 | - } |
|
87 | - throw new \Exception('No plugin implements createGroup in this LDAP Backend.'); |
|
88 | - } |
|
89 | - |
|
90 | - public function canDeleteGroup(): bool { |
|
91 | - return !$this->suppressDeletion && $this->implementsActions(GroupInterface::DELETE_GROUP); |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * @return bool – the value before the change |
|
96 | - */ |
|
97 | - public function setSuppressDeletion(bool $value): bool { |
|
98 | - $old = $this->suppressDeletion; |
|
99 | - $this->suppressDeletion = $value; |
|
100 | - return $old; |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Delete a group |
|
105 | - * |
|
106 | - * @throws \Exception |
|
107 | - */ |
|
108 | - public function deleteGroup(string $gid): bool { |
|
109 | - $plugin = $this->which[GroupInterface::DELETE_GROUP]; |
|
110 | - |
|
111 | - if ($plugin) { |
|
112 | - if ($this->suppressDeletion) { |
|
113 | - return false; |
|
114 | - } |
|
115 | - return $plugin->deleteGroup($gid); |
|
116 | - } |
|
117 | - throw new \Exception('No plugin implements deleteGroup in this LDAP Backend.'); |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * Add a user to a group |
|
122 | - * @param string $uid ID of the user to add to group |
|
123 | - * @param string $gid ID of the group in which add the user |
|
124 | - * @return bool |
|
125 | - * @throws \Exception |
|
126 | - * |
|
127 | - * Adds a user to a group. |
|
128 | - */ |
|
129 | - public function addToGroup($uid, $gid) { |
|
130 | - $plugin = $this->which[GroupInterface::ADD_TO_GROUP]; |
|
131 | - |
|
132 | - if ($plugin) { |
|
133 | - return $plugin->addToGroup($uid, $gid); |
|
134 | - } |
|
135 | - throw new \Exception('No plugin implements addToGroup in this LDAP Backend.'); |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * Removes a user from a group |
|
140 | - * @param string $uid ID of the user to remove from group |
|
141 | - * @param string $gid ID of the group from which remove the user |
|
142 | - * @return bool |
|
143 | - * @throws \Exception |
|
144 | - * |
|
145 | - * removes the user from a group. |
|
146 | - */ |
|
147 | - public function removeFromGroup($uid, $gid) { |
|
148 | - $plugin = $this->which[GroupInterface::REMOVE_FROM_GROUP]; |
|
149 | - |
|
150 | - if ($plugin) { |
|
151 | - return $plugin->removeFromGroup($uid, $gid); |
|
152 | - } |
|
153 | - throw new \Exception('No plugin implements removeFromGroup in this LDAP Backend.'); |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * get the number of all users matching the search string in a group |
|
158 | - * @param string $gid ID of the group |
|
159 | - * @param string $search query string |
|
160 | - * @return int|false |
|
161 | - * @throws \Exception |
|
162 | - */ |
|
163 | - public function countUsersInGroup($gid, $search = '') { |
|
164 | - $plugin = $this->which[GroupInterface::COUNT_USERS]; |
|
165 | - |
|
166 | - if ($plugin) { |
|
167 | - return $plugin->countUsersInGroup($gid,$search); |
|
168 | - } |
|
169 | - throw new \Exception('No plugin implements countUsersInGroup in this LDAP Backend.'); |
|
170 | - } |
|
171 | - |
|
172 | - /** |
|
173 | - * get an array with group details |
|
174 | - * @param string $gid |
|
175 | - * @return array|false |
|
176 | - * @throws \Exception |
|
177 | - */ |
|
178 | - public function getGroupDetails($gid) { |
|
179 | - $plugin = $this->which[GroupInterface::GROUP_DETAILS]; |
|
180 | - |
|
181 | - if ($plugin) { |
|
182 | - return $plugin->getGroupDetails($gid); |
|
183 | - } |
|
184 | - throw new \Exception('No plugin implements getGroupDetails in this LDAP Backend.'); |
|
185 | - } |
|
29 | + private int $respondToActions = 0; |
|
30 | + |
|
31 | + /** @var array<int, ?ILDAPGroupPlugin> */ |
|
32 | + private array $which = [ |
|
33 | + GroupInterface::CREATE_GROUP => null, |
|
34 | + GroupInterface::DELETE_GROUP => null, |
|
35 | + GroupInterface::ADD_TO_GROUP => null, |
|
36 | + GroupInterface::REMOVE_FROM_GROUP => null, |
|
37 | + GroupInterface::COUNT_USERS => null, |
|
38 | + GroupInterface::GROUP_DETAILS => null |
|
39 | + ]; |
|
40 | + |
|
41 | + private bool $suppressDeletion = false; |
|
42 | + |
|
43 | + /** |
|
44 | + * @return int All implemented actions |
|
45 | + */ |
|
46 | + public function getImplementedActions() { |
|
47 | + return $this->respondToActions; |
|
48 | + } |
|
49 | + |
|
50 | + /** |
|
51 | + * Registers a group plugin that may implement some actions, overriding User_LDAP's group actions. |
|
52 | + * @param ILDAPGroupPlugin $plugin |
|
53 | + */ |
|
54 | + public function register(ILDAPGroupPlugin $plugin) { |
|
55 | + $respondToActions = $plugin->respondToActions(); |
|
56 | + $this->respondToActions |= $respondToActions; |
|
57 | + |
|
58 | + foreach ($this->which as $action => $v) { |
|
59 | + if ((bool)($respondToActions & $action)) { |
|
60 | + $this->which[$action] = $plugin; |
|
61 | + \OC::$server->getLogger()->debug("Registered action ".$action." to plugin ".get_class($plugin), ['app' => 'user_ldap']); |
|
62 | + } |
|
63 | + } |
|
64 | + } |
|
65 | + |
|
66 | + /** |
|
67 | + * Signal if there is a registered plugin that implements some given actions |
|
68 | + * @param int $actions Actions defined in \OCP\GroupInterface, like GroupInterface::REMOVE_FROM_GROUP |
|
69 | + * @return bool |
|
70 | + */ |
|
71 | + public function implementsActions($actions) { |
|
72 | + return ($actions & $this->respondToActions) == $actions; |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * Create a group |
|
77 | + * @param string $gid Group Id |
|
78 | + * @return string | null The group DN if group creation was successful. |
|
79 | + * @throws \Exception |
|
80 | + */ |
|
81 | + public function createGroup($gid) { |
|
82 | + $plugin = $this->which[GroupInterface::CREATE_GROUP]; |
|
83 | + |
|
84 | + if ($plugin) { |
|
85 | + return $plugin->createGroup($gid); |
|
86 | + } |
|
87 | + throw new \Exception('No plugin implements createGroup in this LDAP Backend.'); |
|
88 | + } |
|
89 | + |
|
90 | + public function canDeleteGroup(): bool { |
|
91 | + return !$this->suppressDeletion && $this->implementsActions(GroupInterface::DELETE_GROUP); |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * @return bool – the value before the change |
|
96 | + */ |
|
97 | + public function setSuppressDeletion(bool $value): bool { |
|
98 | + $old = $this->suppressDeletion; |
|
99 | + $this->suppressDeletion = $value; |
|
100 | + return $old; |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Delete a group |
|
105 | + * |
|
106 | + * @throws \Exception |
|
107 | + */ |
|
108 | + public function deleteGroup(string $gid): bool { |
|
109 | + $plugin = $this->which[GroupInterface::DELETE_GROUP]; |
|
110 | + |
|
111 | + if ($plugin) { |
|
112 | + if ($this->suppressDeletion) { |
|
113 | + return false; |
|
114 | + } |
|
115 | + return $plugin->deleteGroup($gid); |
|
116 | + } |
|
117 | + throw new \Exception('No plugin implements deleteGroup in this LDAP Backend.'); |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * Add a user to a group |
|
122 | + * @param string $uid ID of the user to add to group |
|
123 | + * @param string $gid ID of the group in which add the user |
|
124 | + * @return bool |
|
125 | + * @throws \Exception |
|
126 | + * |
|
127 | + * Adds a user to a group. |
|
128 | + */ |
|
129 | + public function addToGroup($uid, $gid) { |
|
130 | + $plugin = $this->which[GroupInterface::ADD_TO_GROUP]; |
|
131 | + |
|
132 | + if ($plugin) { |
|
133 | + return $plugin->addToGroup($uid, $gid); |
|
134 | + } |
|
135 | + throw new \Exception('No plugin implements addToGroup in this LDAP Backend.'); |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * Removes a user from a group |
|
140 | + * @param string $uid ID of the user to remove from group |
|
141 | + * @param string $gid ID of the group from which remove the user |
|
142 | + * @return bool |
|
143 | + * @throws \Exception |
|
144 | + * |
|
145 | + * removes the user from a group. |
|
146 | + */ |
|
147 | + public function removeFromGroup($uid, $gid) { |
|
148 | + $plugin = $this->which[GroupInterface::REMOVE_FROM_GROUP]; |
|
149 | + |
|
150 | + if ($plugin) { |
|
151 | + return $plugin->removeFromGroup($uid, $gid); |
|
152 | + } |
|
153 | + throw new \Exception('No plugin implements removeFromGroup in this LDAP Backend.'); |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * get the number of all users matching the search string in a group |
|
158 | + * @param string $gid ID of the group |
|
159 | + * @param string $search query string |
|
160 | + * @return int|false |
|
161 | + * @throws \Exception |
|
162 | + */ |
|
163 | + public function countUsersInGroup($gid, $search = '') { |
|
164 | + $plugin = $this->which[GroupInterface::COUNT_USERS]; |
|
165 | + |
|
166 | + if ($plugin) { |
|
167 | + return $plugin->countUsersInGroup($gid,$search); |
|
168 | + } |
|
169 | + throw new \Exception('No plugin implements countUsersInGroup in this LDAP Backend.'); |
|
170 | + } |
|
171 | + |
|
172 | + /** |
|
173 | + * get an array with group details |
|
174 | + * @param string $gid |
|
175 | + * @return array|false |
|
176 | + * @throws \Exception |
|
177 | + */ |
|
178 | + public function getGroupDetails($gid) { |
|
179 | + $plugin = $this->which[GroupInterface::GROUP_DETAILS]; |
|
180 | + |
|
181 | + if ($plugin) { |
|
182 | + return $plugin->getGroupDetails($gid); |
|
183 | + } |
|
184 | + throw new \Exception('No plugin implements getGroupDetails in this LDAP Backend.'); |
|
185 | + } |
|
186 | 186 | } |
@@ -30,40 +30,40 @@ |
||
30 | 30 | use OCA\User_LDAP\User_Proxy; |
31 | 31 | |
32 | 32 | class ExtStorageConfigHandler extends UserContext implements IConfigHandler { |
33 | - use SimpleSubstitutionTrait; |
|
33 | + use SimpleSubstitutionTrait; |
|
34 | 34 | |
35 | - /** |
|
36 | - * @param mixed $optionValue |
|
37 | - * @return mixed the same type as $optionValue |
|
38 | - * @since 16.0.0 |
|
39 | - * @throws \Exception |
|
40 | - */ |
|
41 | - public function handle($optionValue) { |
|
42 | - $this->placeholder = 'home'; |
|
43 | - $user = $this->getUser(); |
|
35 | + /** |
|
36 | + * @param mixed $optionValue |
|
37 | + * @return mixed the same type as $optionValue |
|
38 | + * @since 16.0.0 |
|
39 | + * @throws \Exception |
|
40 | + */ |
|
41 | + public function handle($optionValue) { |
|
42 | + $this->placeholder = 'home'; |
|
43 | + $user = $this->getUser(); |
|
44 | 44 | |
45 | - if ($user === null) { |
|
46 | - return $optionValue; |
|
47 | - } |
|
45 | + if ($user === null) { |
|
46 | + return $optionValue; |
|
47 | + } |
|
48 | 48 | |
49 | - $backend = $user->getBackend(); |
|
50 | - if (!$backend instanceof User_Proxy) { |
|
51 | - return $optionValue; |
|
52 | - } |
|
49 | + $backend = $user->getBackend(); |
|
50 | + if (!$backend instanceof User_Proxy) { |
|
51 | + return $optionValue; |
|
52 | + } |
|
53 | 53 | |
54 | - $access = $backend->getLDAPAccess($user->getUID()); |
|
55 | - if (!$access) { |
|
56 | - return $optionValue; |
|
57 | - } |
|
54 | + $access = $backend->getLDAPAccess($user->getUID()); |
|
55 | + if (!$access) { |
|
56 | + return $optionValue; |
|
57 | + } |
|
58 | 58 | |
59 | - $attribute = $access->connection->ldapExtStorageHomeAttribute; |
|
60 | - if (empty($attribute)) { |
|
61 | - return $optionValue; |
|
62 | - } |
|
59 | + $attribute = $access->connection->ldapExtStorageHomeAttribute; |
|
60 | + if (empty($attribute)) { |
|
61 | + return $optionValue; |
|
62 | + } |
|
63 | 63 | |
64 | - $ldapUser = $access->userManager->get($user->getUID()); |
|
65 | - $extHome = $ldapUser->getExtStorageHome(); |
|
64 | + $ldapUser = $access->userManager->get($user->getUID()); |
|
65 | + $extHome = $ldapUser->getExtStorageHome(); |
|
66 | 66 | |
67 | - return $this->processInput($optionValue, $extHome); |
|
68 | - } |
|
67 | + return $this->processInput($optionValue, $extHome); |
|
68 | + } |
|
69 | 69 | } |
@@ -114,7 +114,7 @@ |
||
114 | 114 | return; |
115 | 115 | } |
116 | 116 | $this->config->setUserValue($ocName, 'user_ldap', 'isDeleted', '1'); |
117 | - $this->config->setUserValue($ocName, 'user_ldap', 'foundDeleted', (string)time()); |
|
117 | + $this->config->setUserValue($ocName, 'user_ldap', 'foundDeleted', (string) time()); |
|
118 | 118 | $this->deletedUsers = null; |
119 | 119 | } |
120 | 120 | } |
@@ -33,82 +33,82 @@ |
||
33 | 33 | * @package OCA\User_LDAP |
34 | 34 | */ |
35 | 35 | class DeletedUsersIndex { |
36 | - /** |
|
37 | - * @var \OCP\IConfig $config |
|
38 | - */ |
|
39 | - protected $config; |
|
36 | + /** |
|
37 | + * @var \OCP\IConfig $config |
|
38 | + */ |
|
39 | + protected $config; |
|
40 | 40 | |
41 | - /** |
|
42 | - * @var \OCA\User_LDAP\Mapping\UserMapping $mapping |
|
43 | - */ |
|
44 | - protected $mapping; |
|
41 | + /** |
|
42 | + * @var \OCA\User_LDAP\Mapping\UserMapping $mapping |
|
43 | + */ |
|
44 | + protected $mapping; |
|
45 | 45 | |
46 | - /** |
|
47 | - * @var array $deletedUsers |
|
48 | - */ |
|
49 | - protected $deletedUsers; |
|
50 | - /** @var IManager */ |
|
51 | - private $shareManager; |
|
46 | + /** |
|
47 | + * @var array $deletedUsers |
|
48 | + */ |
|
49 | + protected $deletedUsers; |
|
50 | + /** @var IManager */ |
|
51 | + private $shareManager; |
|
52 | 52 | |
53 | - public function __construct(\OCP\IConfig $config, UserMapping $mapping, IManager $shareManager) { |
|
54 | - $this->config = $config; |
|
55 | - $this->mapping = $mapping; |
|
56 | - $this->shareManager = $shareManager; |
|
57 | - } |
|
53 | + public function __construct(\OCP\IConfig $config, UserMapping $mapping, IManager $shareManager) { |
|
54 | + $this->config = $config; |
|
55 | + $this->mapping = $mapping; |
|
56 | + $this->shareManager = $shareManager; |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * reads LDAP users marked as deleted from the database |
|
61 | - * @return \OCA\User_LDAP\User\OfflineUser[] |
|
62 | - */ |
|
63 | - private function fetchDeletedUsers() { |
|
64 | - $deletedUsers = $this->config->getUsersForUserValue( |
|
65 | - 'user_ldap', 'isDeleted', '1'); |
|
59 | + /** |
|
60 | + * reads LDAP users marked as deleted from the database |
|
61 | + * @return \OCA\User_LDAP\User\OfflineUser[] |
|
62 | + */ |
|
63 | + private function fetchDeletedUsers() { |
|
64 | + $deletedUsers = $this->config->getUsersForUserValue( |
|
65 | + 'user_ldap', 'isDeleted', '1'); |
|
66 | 66 | |
67 | - $userObjects = []; |
|
68 | - foreach ($deletedUsers as $user) { |
|
69 | - $userObjects[] = new OfflineUser($user, $this->config, $this->mapping, $this->shareManager); |
|
70 | - } |
|
71 | - $this->deletedUsers = $userObjects; |
|
67 | + $userObjects = []; |
|
68 | + foreach ($deletedUsers as $user) { |
|
69 | + $userObjects[] = new OfflineUser($user, $this->config, $this->mapping, $this->shareManager); |
|
70 | + } |
|
71 | + $this->deletedUsers = $userObjects; |
|
72 | 72 | |
73 | - return $this->deletedUsers; |
|
74 | - } |
|
73 | + return $this->deletedUsers; |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * returns all LDAP users that are marked as deleted |
|
78 | - * @return \OCA\User_LDAP\User\OfflineUser[] |
|
79 | - */ |
|
80 | - public function getUsers() { |
|
81 | - if (is_array($this->deletedUsers)) { |
|
82 | - return $this->deletedUsers; |
|
83 | - } |
|
84 | - return $this->fetchDeletedUsers(); |
|
85 | - } |
|
76 | + /** |
|
77 | + * returns all LDAP users that are marked as deleted |
|
78 | + * @return \OCA\User_LDAP\User\OfflineUser[] |
|
79 | + */ |
|
80 | + public function getUsers() { |
|
81 | + if (is_array($this->deletedUsers)) { |
|
82 | + return $this->deletedUsers; |
|
83 | + } |
|
84 | + return $this->fetchDeletedUsers(); |
|
85 | + } |
|
86 | 86 | |
87 | - /** |
|
88 | - * whether at least one user was detected as deleted |
|
89 | - * @return bool |
|
90 | - */ |
|
91 | - public function hasUsers() { |
|
92 | - if (!is_array($this->deletedUsers)) { |
|
93 | - $this->fetchDeletedUsers(); |
|
94 | - } |
|
95 | - return is_array($this->deletedUsers) && (count($this->deletedUsers) > 0); |
|
96 | - } |
|
87 | + /** |
|
88 | + * whether at least one user was detected as deleted |
|
89 | + * @return bool |
|
90 | + */ |
|
91 | + public function hasUsers() { |
|
92 | + if (!is_array($this->deletedUsers)) { |
|
93 | + $this->fetchDeletedUsers(); |
|
94 | + } |
|
95 | + return is_array($this->deletedUsers) && (count($this->deletedUsers) > 0); |
|
96 | + } |
|
97 | 97 | |
98 | - /** |
|
99 | - * marks a user as deleted |
|
100 | - * |
|
101 | - * @param string $ocName |
|
102 | - * @throws \OCP\PreConditionNotMetException |
|
103 | - */ |
|
104 | - public function markUser($ocName) { |
|
105 | - $curValue = $this->config->getUserValue($ocName, 'user_ldap', 'isDeleted', '0'); |
|
106 | - if ($curValue === '1') { |
|
107 | - // the user is already marked, do not write to DB again |
|
108 | - return; |
|
109 | - } |
|
110 | - $this->config->setUserValue($ocName, 'user_ldap', 'isDeleted', '1'); |
|
111 | - $this->config->setUserValue($ocName, 'user_ldap', 'foundDeleted', (string)time()); |
|
112 | - $this->deletedUsers = null; |
|
113 | - } |
|
98 | + /** |
|
99 | + * marks a user as deleted |
|
100 | + * |
|
101 | + * @param string $ocName |
|
102 | + * @throws \OCP\PreConditionNotMetException |
|
103 | + */ |
|
104 | + public function markUser($ocName) { |
|
105 | + $curValue = $this->config->getUserValue($ocName, 'user_ldap', 'isDeleted', '0'); |
|
106 | + if ($curValue === '1') { |
|
107 | + // the user is already marked, do not write to DB again |
|
108 | + return; |
|
109 | + } |
|
110 | + $this->config->setUserValue($ocName, 'user_ldap', 'isDeleted', '1'); |
|
111 | + $this->config->setUserValue($ocName, 'user_ldap', 'foundDeleted', (string)time()); |
|
112 | + $this->deletedUsers = null; |
|
113 | + } |
|
114 | 114 | } |
@@ -292,7 +292,7 @@ |
||
292 | 292 | |
293 | 293 | $config = new Configuration($configID); |
294 | 294 | $data = $config->getConfiguration(); |
295 | - if (!(int)$showPassword) { |
|
295 | + if (!(int) $showPassword) { |
|
296 | 296 | $data['ldapAgentPassword'] = '***'; |
297 | 297 | } |
298 | 298 | foreach ($data as $key => $value) { |
@@ -40,292 +40,292 @@ |
||
40 | 40 | |
41 | 41 | class ConfigAPIController extends OCSController { |
42 | 42 | |
43 | - /** @var Helper */ |
|
44 | - private $ldapHelper; |
|
43 | + /** @var Helper */ |
|
44 | + private $ldapHelper; |
|
45 | 45 | |
46 | - /** @var ILogger */ |
|
47 | - private $logger; |
|
46 | + /** @var ILogger */ |
|
47 | + private $logger; |
|
48 | 48 | |
49 | - /** @var ConnectionFactory */ |
|
50 | - private $connectionFactory; |
|
49 | + /** @var ConnectionFactory */ |
|
50 | + private $connectionFactory; |
|
51 | 51 | |
52 | - public function __construct( |
|
53 | - $appName, |
|
54 | - IRequest $request, |
|
55 | - CapabilitiesManager $capabilitiesManager, |
|
56 | - IUserSession $userSession, |
|
57 | - IUserManager $userManager, |
|
58 | - Manager $keyManager, |
|
59 | - Helper $ldapHelper, |
|
60 | - ILogger $logger, |
|
61 | - ConnectionFactory $connectionFactory |
|
62 | - ) { |
|
63 | - parent::__construct( |
|
64 | - $appName, |
|
65 | - $request, |
|
66 | - $capabilitiesManager, |
|
67 | - $userSession, |
|
68 | - $userManager, |
|
69 | - $keyManager |
|
70 | - ); |
|
52 | + public function __construct( |
|
53 | + $appName, |
|
54 | + IRequest $request, |
|
55 | + CapabilitiesManager $capabilitiesManager, |
|
56 | + IUserSession $userSession, |
|
57 | + IUserManager $userManager, |
|
58 | + Manager $keyManager, |
|
59 | + Helper $ldapHelper, |
|
60 | + ILogger $logger, |
|
61 | + ConnectionFactory $connectionFactory |
|
62 | + ) { |
|
63 | + parent::__construct( |
|
64 | + $appName, |
|
65 | + $request, |
|
66 | + $capabilitiesManager, |
|
67 | + $userSession, |
|
68 | + $userManager, |
|
69 | + $keyManager |
|
70 | + ); |
|
71 | 71 | |
72 | 72 | |
73 | - $this->ldapHelper = $ldapHelper; |
|
74 | - $this->logger = $logger; |
|
75 | - $this->connectionFactory = $connectionFactory; |
|
76 | - } |
|
73 | + $this->ldapHelper = $ldapHelper; |
|
74 | + $this->logger = $logger; |
|
75 | + $this->connectionFactory = $connectionFactory; |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * Creates a new (empty) configuration and returns the resulting prefix |
|
80 | - * |
|
81 | - * Example: curl -X POST -H "OCS-APIREQUEST: true" -u $admin:$password \ |
|
82 | - * https://nextcloud.server/ocs/v2.php/apps/user_ldap/api/v1/config |
|
83 | - * |
|
84 | - * results in: |
|
85 | - * |
|
86 | - * <?xml version="1.0"?> |
|
87 | - * <ocs> |
|
88 | - * <meta> |
|
89 | - * <status>ok</status> |
|
90 | - * <statuscode>200</statuscode> |
|
91 | - * <message>OK</message> |
|
92 | - * </meta> |
|
93 | - * <data> |
|
94 | - * <configID>s40</configID> |
|
95 | - * </data> |
|
96 | - * </ocs> |
|
97 | - * |
|
98 | - * Failing example: if an exception is thrown (e.g. Database connection lost) |
|
99 | - * the detailed error will be logged. The output will then look like: |
|
100 | - * |
|
101 | - * <?xml version="1.0"?> |
|
102 | - * <ocs> |
|
103 | - * <meta> |
|
104 | - * <status>failure</status> |
|
105 | - * <statuscode>999</statuscode> |
|
106 | - * <message>An issue occurred when creating the new config.</message> |
|
107 | - * </meta> |
|
108 | - * <data/> |
|
109 | - * </ocs> |
|
110 | - * |
|
111 | - * For JSON output provide the format=json parameter |
|
112 | - * |
|
113 | - * @AuthorizedAdminSetting(settings=OCA\User_LDAP\Settings\Admin) |
|
114 | - * @return DataResponse |
|
115 | - * @throws OCSException |
|
116 | - */ |
|
117 | - public function create() { |
|
118 | - try { |
|
119 | - $configPrefix = $this->ldapHelper->getNextServerConfigurationPrefix(); |
|
120 | - $configHolder = new Configuration($configPrefix); |
|
121 | - $configHolder->ldapConfigurationActive = false; |
|
122 | - $configHolder->saveConfiguration(); |
|
123 | - } catch (\Exception $e) { |
|
124 | - $this->logger->logException($e); |
|
125 | - throw new OCSException('An issue occurred when creating the new config.'); |
|
126 | - } |
|
127 | - return new DataResponse(['configID' => $configPrefix]); |
|
128 | - } |
|
78 | + /** |
|
79 | + * Creates a new (empty) configuration and returns the resulting prefix |
|
80 | + * |
|
81 | + * Example: curl -X POST -H "OCS-APIREQUEST: true" -u $admin:$password \ |
|
82 | + * https://nextcloud.server/ocs/v2.php/apps/user_ldap/api/v1/config |
|
83 | + * |
|
84 | + * results in: |
|
85 | + * |
|
86 | + * <?xml version="1.0"?> |
|
87 | + * <ocs> |
|
88 | + * <meta> |
|
89 | + * <status>ok</status> |
|
90 | + * <statuscode>200</statuscode> |
|
91 | + * <message>OK</message> |
|
92 | + * </meta> |
|
93 | + * <data> |
|
94 | + * <configID>s40</configID> |
|
95 | + * </data> |
|
96 | + * </ocs> |
|
97 | + * |
|
98 | + * Failing example: if an exception is thrown (e.g. Database connection lost) |
|
99 | + * the detailed error will be logged. The output will then look like: |
|
100 | + * |
|
101 | + * <?xml version="1.0"?> |
|
102 | + * <ocs> |
|
103 | + * <meta> |
|
104 | + * <status>failure</status> |
|
105 | + * <statuscode>999</statuscode> |
|
106 | + * <message>An issue occurred when creating the new config.</message> |
|
107 | + * </meta> |
|
108 | + * <data/> |
|
109 | + * </ocs> |
|
110 | + * |
|
111 | + * For JSON output provide the format=json parameter |
|
112 | + * |
|
113 | + * @AuthorizedAdminSetting(settings=OCA\User_LDAP\Settings\Admin) |
|
114 | + * @return DataResponse |
|
115 | + * @throws OCSException |
|
116 | + */ |
|
117 | + public function create() { |
|
118 | + try { |
|
119 | + $configPrefix = $this->ldapHelper->getNextServerConfigurationPrefix(); |
|
120 | + $configHolder = new Configuration($configPrefix); |
|
121 | + $configHolder->ldapConfigurationActive = false; |
|
122 | + $configHolder->saveConfiguration(); |
|
123 | + } catch (\Exception $e) { |
|
124 | + $this->logger->logException($e); |
|
125 | + throw new OCSException('An issue occurred when creating the new config.'); |
|
126 | + } |
|
127 | + return new DataResponse(['configID' => $configPrefix]); |
|
128 | + } |
|
129 | 129 | |
130 | - /** |
|
131 | - * Deletes a LDAP configuration, if present. |
|
132 | - * |
|
133 | - * Example: |
|
134 | - * curl -X DELETE -H "OCS-APIREQUEST: true" -u $admin:$password \ |
|
135 | - * https://nextcloud.server/ocs/v2.php/apps/user_ldap/api/v1/config/s60 |
|
136 | - * |
|
137 | - * <?xml version="1.0"?> |
|
138 | - * <ocs> |
|
139 | - * <meta> |
|
140 | - * <status>ok</status> |
|
141 | - * <statuscode>200</statuscode> |
|
142 | - * <message>OK</message> |
|
143 | - * </meta> |
|
144 | - * <data/> |
|
145 | - * </ocs> |
|
146 | - * |
|
147 | - * @AuthorizedAdminSetting(settings=OCA\User_LDAP\Settings\Admin) |
|
148 | - * @param string $configID |
|
149 | - * @return DataResponse |
|
150 | - * @throws OCSBadRequestException |
|
151 | - * @throws OCSException |
|
152 | - */ |
|
153 | - public function delete($configID) { |
|
154 | - try { |
|
155 | - $this->ensureConfigIDExists($configID); |
|
156 | - if (!$this->ldapHelper->deleteServerConfiguration($configID)) { |
|
157 | - throw new OCSException('Could not delete configuration'); |
|
158 | - } |
|
159 | - } catch (OCSException $e) { |
|
160 | - throw $e; |
|
161 | - } catch (\Exception $e) { |
|
162 | - $this->logger->logException($e); |
|
163 | - throw new OCSException('An issue occurred when deleting the config.'); |
|
164 | - } |
|
130 | + /** |
|
131 | + * Deletes a LDAP configuration, if present. |
|
132 | + * |
|
133 | + * Example: |
|
134 | + * curl -X DELETE -H "OCS-APIREQUEST: true" -u $admin:$password \ |
|
135 | + * https://nextcloud.server/ocs/v2.php/apps/user_ldap/api/v1/config/s60 |
|
136 | + * |
|
137 | + * <?xml version="1.0"?> |
|
138 | + * <ocs> |
|
139 | + * <meta> |
|
140 | + * <status>ok</status> |
|
141 | + * <statuscode>200</statuscode> |
|
142 | + * <message>OK</message> |
|
143 | + * </meta> |
|
144 | + * <data/> |
|
145 | + * </ocs> |
|
146 | + * |
|
147 | + * @AuthorizedAdminSetting(settings=OCA\User_LDAP\Settings\Admin) |
|
148 | + * @param string $configID |
|
149 | + * @return DataResponse |
|
150 | + * @throws OCSBadRequestException |
|
151 | + * @throws OCSException |
|
152 | + */ |
|
153 | + public function delete($configID) { |
|
154 | + try { |
|
155 | + $this->ensureConfigIDExists($configID); |
|
156 | + if (!$this->ldapHelper->deleteServerConfiguration($configID)) { |
|
157 | + throw new OCSException('Could not delete configuration'); |
|
158 | + } |
|
159 | + } catch (OCSException $e) { |
|
160 | + throw $e; |
|
161 | + } catch (\Exception $e) { |
|
162 | + $this->logger->logException($e); |
|
163 | + throw new OCSException('An issue occurred when deleting the config.'); |
|
164 | + } |
|
165 | 165 | |
166 | - return new DataResponse(); |
|
167 | - } |
|
166 | + return new DataResponse(); |
|
167 | + } |
|
168 | 168 | |
169 | - /** |
|
170 | - * Modifies a configuration |
|
171 | - * |
|
172 | - * Example: |
|
173 | - * curl -X PUT -d "configData[ldapHost]=ldaps://my.ldap.server&configData[ldapPort]=636" \ |
|
174 | - * -H "OCS-APIREQUEST: true" -u $admin:$password \ |
|
175 | - * https://nextcloud.server/ocs/v2.php/apps/user_ldap/api/v1/config/s60 |
|
176 | - * |
|
177 | - * <?xml version="1.0"?> |
|
178 | - * <ocs> |
|
179 | - * <meta> |
|
180 | - * <status>ok</status> |
|
181 | - * <statuscode>200</statuscode> |
|
182 | - * <message>OK</message> |
|
183 | - * </meta> |
|
184 | - * <data/> |
|
185 | - * </ocs> |
|
186 | - * |
|
187 | - * @AuthorizedAdminSetting(settings=OCA\User_LDAP\Settings\Admin) |
|
188 | - * @param string $configID |
|
189 | - * @param array $configData |
|
190 | - * @return DataResponse |
|
191 | - * @throws OCSException |
|
192 | - */ |
|
193 | - public function modify($configID, $configData) { |
|
194 | - try { |
|
195 | - $this->ensureConfigIDExists($configID); |
|
169 | + /** |
|
170 | + * Modifies a configuration |
|
171 | + * |
|
172 | + * Example: |
|
173 | + * curl -X PUT -d "configData[ldapHost]=ldaps://my.ldap.server&configData[ldapPort]=636" \ |
|
174 | + * -H "OCS-APIREQUEST: true" -u $admin:$password \ |
|
175 | + * https://nextcloud.server/ocs/v2.php/apps/user_ldap/api/v1/config/s60 |
|
176 | + * |
|
177 | + * <?xml version="1.0"?> |
|
178 | + * <ocs> |
|
179 | + * <meta> |
|
180 | + * <status>ok</status> |
|
181 | + * <statuscode>200</statuscode> |
|
182 | + * <message>OK</message> |
|
183 | + * </meta> |
|
184 | + * <data/> |
|
185 | + * </ocs> |
|
186 | + * |
|
187 | + * @AuthorizedAdminSetting(settings=OCA\User_LDAP\Settings\Admin) |
|
188 | + * @param string $configID |
|
189 | + * @param array $configData |
|
190 | + * @return DataResponse |
|
191 | + * @throws OCSException |
|
192 | + */ |
|
193 | + public function modify($configID, $configData) { |
|
194 | + try { |
|
195 | + $this->ensureConfigIDExists($configID); |
|
196 | 196 | |
197 | - if (!is_array($configData)) { |
|
198 | - throw new OCSBadRequestException('configData is not properly set'); |
|
199 | - } |
|
197 | + if (!is_array($configData)) { |
|
198 | + throw new OCSBadRequestException('configData is not properly set'); |
|
199 | + } |
|
200 | 200 | |
201 | - $configuration = new Configuration($configID); |
|
202 | - $configKeys = $configuration->getConfigTranslationArray(); |
|
201 | + $configuration = new Configuration($configID); |
|
202 | + $configKeys = $configuration->getConfigTranslationArray(); |
|
203 | 203 | |
204 | - foreach ($configKeys as $i => $key) { |
|
205 | - if (isset($configData[$key])) { |
|
206 | - $configuration->$key = $configData[$key]; |
|
207 | - } |
|
208 | - } |
|
204 | + foreach ($configKeys as $i => $key) { |
|
205 | + if (isset($configData[$key])) { |
|
206 | + $configuration->$key = $configData[$key]; |
|
207 | + } |
|
208 | + } |
|
209 | 209 | |
210 | - $configuration->saveConfiguration(); |
|
211 | - $this->connectionFactory->get($configID)->clearCache(); |
|
212 | - } catch (OCSException $e) { |
|
213 | - throw $e; |
|
214 | - } catch (\Exception $e) { |
|
215 | - $this->logger->logException($e); |
|
216 | - throw new OCSException('An issue occurred when modifying the config.'); |
|
217 | - } |
|
210 | + $configuration->saveConfiguration(); |
|
211 | + $this->connectionFactory->get($configID)->clearCache(); |
|
212 | + } catch (OCSException $e) { |
|
213 | + throw $e; |
|
214 | + } catch (\Exception $e) { |
|
215 | + $this->logger->logException($e); |
|
216 | + throw new OCSException('An issue occurred when modifying the config.'); |
|
217 | + } |
|
218 | 218 | |
219 | - return new DataResponse(); |
|
220 | - } |
|
219 | + return new DataResponse(); |
|
220 | + } |
|
221 | 221 | |
222 | - /** |
|
223 | - * Retrieves a configuration |
|
224 | - * |
|
225 | - * <?xml version="1.0"?> |
|
226 | - * <ocs> |
|
227 | - * <meta> |
|
228 | - * <status>ok</status> |
|
229 | - * <statuscode>200</statuscode> |
|
230 | - * <message>OK</message> |
|
231 | - * </meta> |
|
232 | - * <data> |
|
233 | - * <ldapHost>ldaps://my.ldap.server</ldapHost> |
|
234 | - * <ldapPort>7770</ldapPort> |
|
235 | - * <ldapBackupHost></ldapBackupHost> |
|
236 | - * <ldapBackupPort></ldapBackupPort> |
|
237 | - * <ldapBase>ou=small,dc=my,dc=ldap,dc=server</ldapBase> |
|
238 | - * <ldapBaseUsers>ou=users,ou=small,dc=my,dc=ldap,dc=server</ldapBaseUsers> |
|
239 | - * <ldapBaseGroups>ou=small,dc=my,dc=ldap,dc=server</ldapBaseGroups> |
|
240 | - * <ldapAgentName>cn=root,dc=my,dc=ldap,dc=server</ldapAgentName> |
|
241 | - * <ldapAgentPassword>clearTextWithShowPassword=1</ldapAgentPassword> |
|
242 | - * <ldapTLS>1</ldapTLS> |
|
243 | - * <turnOffCertCheck>0</turnOffCertCheck> |
|
244 | - * <ldapIgnoreNamingRules/> |
|
245 | - * <ldapUserDisplayName>displayname</ldapUserDisplayName> |
|
246 | - * <ldapUserDisplayName2>uid</ldapUserDisplayName2> |
|
247 | - * <ldapUserFilterObjectclass>inetOrgPerson</ldapUserFilterObjectclass> |
|
248 | - * <ldapUserFilterGroups></ldapUserFilterGroups> |
|
249 | - * <ldapUserFilter>(&(objectclass=nextcloudUser)(nextcloudEnabled=TRUE))</ldapUserFilter> |
|
250 | - * <ldapUserFilterMode>1</ldapUserFilterMode> |
|
251 | - * <ldapGroupFilter>(&(|(objectclass=nextcloudGroup)))</ldapGroupFilter> |
|
252 | - * <ldapGroupFilterMode>0</ldapGroupFilterMode> |
|
253 | - * <ldapGroupFilterObjectclass>nextcloudGroup</ldapGroupFilterObjectclass> |
|
254 | - * <ldapGroupFilterGroups></ldapGroupFilterGroups> |
|
255 | - * <ldapGroupDisplayName>cn</ldapGroupDisplayName> |
|
256 | - * <ldapGroupMemberAssocAttr>memberUid</ldapGroupMemberAssocAttr> |
|
257 | - * <ldapLoginFilter>(&(|(objectclass=inetOrgPerson))(uid=%uid))</ldapLoginFilter> |
|
258 | - * <ldapLoginFilterMode>0</ldapLoginFilterMode> |
|
259 | - * <ldapLoginFilterEmail>0</ldapLoginFilterEmail> |
|
260 | - * <ldapLoginFilterUsername>1</ldapLoginFilterUsername> |
|
261 | - * <ldapLoginFilterAttributes></ldapLoginFilterAttributes> |
|
262 | - * <ldapQuotaAttribute></ldapQuotaAttribute> |
|
263 | - * <ldapQuotaDefault></ldapQuotaDefault> |
|
264 | - * <ldapEmailAttribute>mail</ldapEmailAttribute> |
|
265 | - * <ldapCacheTTL>20</ldapCacheTTL> |
|
266 | - * <ldapUuidUserAttribute>auto</ldapUuidUserAttribute> |
|
267 | - * <ldapUuidGroupAttribute>auto</ldapUuidGroupAttribute> |
|
268 | - * <ldapOverrideMainServer></ldapOverrideMainServer> |
|
269 | - * <ldapConfigurationActive>1</ldapConfigurationActive> |
|
270 | - * <ldapAttributesForUserSearch>uid;sn;givenname</ldapAttributesForUserSearch> |
|
271 | - * <ldapAttributesForGroupSearch></ldapAttributesForGroupSearch> |
|
272 | - * <ldapExperiencedAdmin>0</ldapExperiencedAdmin> |
|
273 | - * <homeFolderNamingRule></homeFolderNamingRule> |
|
274 | - * <hasMemberOfFilterSupport></hasMemberOfFilterSupport> |
|
275 | - * <useMemberOfToDetectMembership>1</useMemberOfToDetectMembership> |
|
276 | - * <ldapExpertUsernameAttr>uid</ldapExpertUsernameAttr> |
|
277 | - * <ldapExpertUUIDUserAttr>uid</ldapExpertUUIDUserAttr> |
|
278 | - * <ldapExpertUUIDGroupAttr></ldapExpertUUIDGroupAttr> |
|
279 | - * <lastJpegPhotoLookup>0</lastJpegPhotoLookup> |
|
280 | - * <ldapNestedGroups>0</ldapNestedGroups> |
|
281 | - * <ldapPagingSize>500</ldapPagingSize> |
|
282 | - * <turnOnPasswordChange>1</turnOnPasswordChange> |
|
283 | - * <ldapDynamicGroupMemberURL></ldapDynamicGroupMemberURL> |
|
284 | - * </data> |
|
285 | - * </ocs> |
|
286 | - * |
|
287 | - * @AuthorizedAdminSetting(settings=OCA\User_LDAP\Settings\Admin) |
|
288 | - * @param string $configID |
|
289 | - * @param bool|string $showPassword |
|
290 | - * @return DataResponse |
|
291 | - * @throws OCSException |
|
292 | - */ |
|
293 | - public function show($configID, $showPassword = false) { |
|
294 | - try { |
|
295 | - $this->ensureConfigIDExists($configID); |
|
222 | + /** |
|
223 | + * Retrieves a configuration |
|
224 | + * |
|
225 | + * <?xml version="1.0"?> |
|
226 | + * <ocs> |
|
227 | + * <meta> |
|
228 | + * <status>ok</status> |
|
229 | + * <statuscode>200</statuscode> |
|
230 | + * <message>OK</message> |
|
231 | + * </meta> |
|
232 | + * <data> |
|
233 | + * <ldapHost>ldaps://my.ldap.server</ldapHost> |
|
234 | + * <ldapPort>7770</ldapPort> |
|
235 | + * <ldapBackupHost></ldapBackupHost> |
|
236 | + * <ldapBackupPort></ldapBackupPort> |
|
237 | + * <ldapBase>ou=small,dc=my,dc=ldap,dc=server</ldapBase> |
|
238 | + * <ldapBaseUsers>ou=users,ou=small,dc=my,dc=ldap,dc=server</ldapBaseUsers> |
|
239 | + * <ldapBaseGroups>ou=small,dc=my,dc=ldap,dc=server</ldapBaseGroups> |
|
240 | + * <ldapAgentName>cn=root,dc=my,dc=ldap,dc=server</ldapAgentName> |
|
241 | + * <ldapAgentPassword>clearTextWithShowPassword=1</ldapAgentPassword> |
|
242 | + * <ldapTLS>1</ldapTLS> |
|
243 | + * <turnOffCertCheck>0</turnOffCertCheck> |
|
244 | + * <ldapIgnoreNamingRules/> |
|
245 | + * <ldapUserDisplayName>displayname</ldapUserDisplayName> |
|
246 | + * <ldapUserDisplayName2>uid</ldapUserDisplayName2> |
|
247 | + * <ldapUserFilterObjectclass>inetOrgPerson</ldapUserFilterObjectclass> |
|
248 | + * <ldapUserFilterGroups></ldapUserFilterGroups> |
|
249 | + * <ldapUserFilter>(&(objectclass=nextcloudUser)(nextcloudEnabled=TRUE))</ldapUserFilter> |
|
250 | + * <ldapUserFilterMode>1</ldapUserFilterMode> |
|
251 | + * <ldapGroupFilter>(&(|(objectclass=nextcloudGroup)))</ldapGroupFilter> |
|
252 | + * <ldapGroupFilterMode>0</ldapGroupFilterMode> |
|
253 | + * <ldapGroupFilterObjectclass>nextcloudGroup</ldapGroupFilterObjectclass> |
|
254 | + * <ldapGroupFilterGroups></ldapGroupFilterGroups> |
|
255 | + * <ldapGroupDisplayName>cn</ldapGroupDisplayName> |
|
256 | + * <ldapGroupMemberAssocAttr>memberUid</ldapGroupMemberAssocAttr> |
|
257 | + * <ldapLoginFilter>(&(|(objectclass=inetOrgPerson))(uid=%uid))</ldapLoginFilter> |
|
258 | + * <ldapLoginFilterMode>0</ldapLoginFilterMode> |
|
259 | + * <ldapLoginFilterEmail>0</ldapLoginFilterEmail> |
|
260 | + * <ldapLoginFilterUsername>1</ldapLoginFilterUsername> |
|
261 | + * <ldapLoginFilterAttributes></ldapLoginFilterAttributes> |
|
262 | + * <ldapQuotaAttribute></ldapQuotaAttribute> |
|
263 | + * <ldapQuotaDefault></ldapQuotaDefault> |
|
264 | + * <ldapEmailAttribute>mail</ldapEmailAttribute> |
|
265 | + * <ldapCacheTTL>20</ldapCacheTTL> |
|
266 | + * <ldapUuidUserAttribute>auto</ldapUuidUserAttribute> |
|
267 | + * <ldapUuidGroupAttribute>auto</ldapUuidGroupAttribute> |
|
268 | + * <ldapOverrideMainServer></ldapOverrideMainServer> |
|
269 | + * <ldapConfigurationActive>1</ldapConfigurationActive> |
|
270 | + * <ldapAttributesForUserSearch>uid;sn;givenname</ldapAttributesForUserSearch> |
|
271 | + * <ldapAttributesForGroupSearch></ldapAttributesForGroupSearch> |
|
272 | + * <ldapExperiencedAdmin>0</ldapExperiencedAdmin> |
|
273 | + * <homeFolderNamingRule></homeFolderNamingRule> |
|
274 | + * <hasMemberOfFilterSupport></hasMemberOfFilterSupport> |
|
275 | + * <useMemberOfToDetectMembership>1</useMemberOfToDetectMembership> |
|
276 | + * <ldapExpertUsernameAttr>uid</ldapExpertUsernameAttr> |
|
277 | + * <ldapExpertUUIDUserAttr>uid</ldapExpertUUIDUserAttr> |
|
278 | + * <ldapExpertUUIDGroupAttr></ldapExpertUUIDGroupAttr> |
|
279 | + * <lastJpegPhotoLookup>0</lastJpegPhotoLookup> |
|
280 | + * <ldapNestedGroups>0</ldapNestedGroups> |
|
281 | + * <ldapPagingSize>500</ldapPagingSize> |
|
282 | + * <turnOnPasswordChange>1</turnOnPasswordChange> |
|
283 | + * <ldapDynamicGroupMemberURL></ldapDynamicGroupMemberURL> |
|
284 | + * </data> |
|
285 | + * </ocs> |
|
286 | + * |
|
287 | + * @AuthorizedAdminSetting(settings=OCA\User_LDAP\Settings\Admin) |
|
288 | + * @param string $configID |
|
289 | + * @param bool|string $showPassword |
|
290 | + * @return DataResponse |
|
291 | + * @throws OCSException |
|
292 | + */ |
|
293 | + public function show($configID, $showPassword = false) { |
|
294 | + try { |
|
295 | + $this->ensureConfigIDExists($configID); |
|
296 | 296 | |
297 | - $config = new Configuration($configID); |
|
298 | - $data = $config->getConfiguration(); |
|
299 | - if (!(int)$showPassword) { |
|
300 | - $data['ldapAgentPassword'] = '***'; |
|
301 | - } |
|
302 | - foreach ($data as $key => $value) { |
|
303 | - if (is_array($value)) { |
|
304 | - $value = implode(';', $value); |
|
305 | - $data[$key] = $value; |
|
306 | - } |
|
307 | - } |
|
308 | - } catch (OCSException $e) { |
|
309 | - throw $e; |
|
310 | - } catch (\Exception $e) { |
|
311 | - $this->logger->logException($e); |
|
312 | - throw new OCSException('An issue occurred when modifying the config.'); |
|
313 | - } |
|
297 | + $config = new Configuration($configID); |
|
298 | + $data = $config->getConfiguration(); |
|
299 | + if (!(int)$showPassword) { |
|
300 | + $data['ldapAgentPassword'] = '***'; |
|
301 | + } |
|
302 | + foreach ($data as $key => $value) { |
|
303 | + if (is_array($value)) { |
|
304 | + $value = implode(';', $value); |
|
305 | + $data[$key] = $value; |
|
306 | + } |
|
307 | + } |
|
308 | + } catch (OCSException $e) { |
|
309 | + throw $e; |
|
310 | + } catch (\Exception $e) { |
|
311 | + $this->logger->logException($e); |
|
312 | + throw new OCSException('An issue occurred when modifying the config.'); |
|
313 | + } |
|
314 | 314 | |
315 | - return new DataResponse($data); |
|
316 | - } |
|
315 | + return new DataResponse($data); |
|
316 | + } |
|
317 | 317 | |
318 | - /** |
|
319 | - * If the given config ID is not available, an exception is thrown |
|
320 | - * |
|
321 | - * @AuthorizedAdminSetting(settings=OCA\User_LDAP\Settings\Admin) |
|
322 | - * @param string $configID |
|
323 | - * @throws OCSNotFoundException |
|
324 | - */ |
|
325 | - private function ensureConfigIDExists($configID) { |
|
326 | - $prefixes = $this->ldapHelper->getServerConfigurationPrefixes(); |
|
327 | - if (!in_array($configID, $prefixes, true)) { |
|
328 | - throw new OCSNotFoundException('Config ID not found'); |
|
329 | - } |
|
330 | - } |
|
318 | + /** |
|
319 | + * If the given config ID is not available, an exception is thrown |
|
320 | + * |
|
321 | + * @AuthorizedAdminSetting(settings=OCA\User_LDAP\Settings\Admin) |
|
322 | + * @param string $configID |
|
323 | + * @throws OCSNotFoundException |
|
324 | + */ |
|
325 | + private function ensureConfigIDExists($configID) { |
|
326 | + $prefixes = $this->ldapHelper->getServerConfigurationPrefixes(); |
|
327 | + if (!in_array($configID, $prefixes, true)) { |
|
328 | + throw new OCSNotFoundException('Config ID not found'); |
|
329 | + } |
|
330 | + } |
|
331 | 331 | } |
@@ -30,50 +30,50 @@ |
||
30 | 30 | namespace OCA\User_LDAP; |
31 | 31 | |
32 | 32 | class WizardResult { |
33 | - protected $changes = []; |
|
34 | - protected $options = []; |
|
35 | - protected $markedChange = false; |
|
33 | + protected $changes = []; |
|
34 | + protected $options = []; |
|
35 | + protected $markedChange = false; |
|
36 | 36 | |
37 | - /** |
|
38 | - * @param string $key |
|
39 | - * @param mixed $value |
|
40 | - */ |
|
41 | - public function addChange($key, $value) { |
|
42 | - $this->changes[$key] = $value; |
|
43 | - } |
|
37 | + /** |
|
38 | + * @param string $key |
|
39 | + * @param mixed $value |
|
40 | + */ |
|
41 | + public function addChange($key, $value) { |
|
42 | + $this->changes[$key] = $value; |
|
43 | + } |
|
44 | 44 | |
45 | 45 | |
46 | - public function markChange() { |
|
47 | - $this->markedChange = true; |
|
48 | - } |
|
46 | + public function markChange() { |
|
47 | + $this->markedChange = true; |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * @param string $key |
|
52 | - * @param array|string $values |
|
53 | - */ |
|
54 | - public function addOptions($key, $values) { |
|
55 | - if (!is_array($values)) { |
|
56 | - $values = [$values]; |
|
57 | - } |
|
58 | - $this->options[$key] = $values; |
|
59 | - } |
|
50 | + /** |
|
51 | + * @param string $key |
|
52 | + * @param array|string $values |
|
53 | + */ |
|
54 | + public function addOptions($key, $values) { |
|
55 | + if (!is_array($values)) { |
|
56 | + $values = [$values]; |
|
57 | + } |
|
58 | + $this->options[$key] = $values; |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * @return bool |
|
63 | - */ |
|
64 | - public function hasChanges() { |
|
65 | - return (count($this->changes) > 0 || $this->markedChange); |
|
66 | - } |
|
61 | + /** |
|
62 | + * @return bool |
|
63 | + */ |
|
64 | + public function hasChanges() { |
|
65 | + return (count($this->changes) > 0 || $this->markedChange); |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * @return array |
|
70 | - */ |
|
71 | - public function getResultArray() { |
|
72 | - $result = []; |
|
73 | - $result['changes'] = $this->changes; |
|
74 | - if (count($this->options) > 0) { |
|
75 | - $result['options'] = $this->options; |
|
76 | - } |
|
77 | - return $result; |
|
78 | - } |
|
68 | + /** |
|
69 | + * @return array |
|
70 | + */ |
|
71 | + public function getResultArray() { |
|
72 | + $result = []; |
|
73 | + $result['changes'] = $this->changes; |
|
74 | + if (count($this->options) > 0) { |
|
75 | + $result['options'] = $this->options; |
|
76 | + } |
|
77 | + return $result; |
|
78 | + } |
|
79 | 79 | } |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | */ |
104 | 104 | protected function getMinPagingSize() { |
105 | 105 | $configKeys = $this->config->getAppKeys('user_ldap'); |
106 | - $configKeys = array_filter($configKeys, function ($key) { |
|
106 | + $configKeys = array_filter($configKeys, function($key) { |
|
107 | 107 | return strpos($key, 'ldap_paging_size') !== false; |
108 | 108 | }); |
109 | 109 | $minPagingSize = null; |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | $pagingSize = $this->config->getAppValue('user_ldap', $configKey, $minPagingSize); |
112 | 112 | $minPagingSize = $minPagingSize === null ? $pagingSize : min($minPagingSize, $pagingSize); |
113 | 113 | } |
114 | - return (int)$minPagingSize; |
|
114 | + return (int) $minPagingSize; |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | /** |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | |
165 | 165 | $filter = $access->combineFilterWithAnd([ |
166 | 166 | $access->connection->ldapUserFilter, |
167 | - $access->connection->ldapUserDisplayName . '=*', |
|
167 | + $access->connection->ldapUserDisplayName.'=*', |
|
168 | 168 | $access->getFilterPartForUserSearch('') |
169 | 169 | ]); |
170 | 170 | $results = $access->fetchListOfUsers( |
@@ -175,10 +175,10 @@ discard block |
||
175 | 175 | true |
176 | 176 | ); |
177 | 177 | |
178 | - if ((int)$connection->ldapPagingSize === 0) { |
|
178 | + if ((int) $connection->ldapPagingSize === 0) { |
|
179 | 179 | return false; |
180 | 180 | } |
181 | - return count($results) >= (int)$connection->ldapPagingSize; |
|
181 | + return count($results) >= (int) $connection->ldapPagingSize; |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | /** |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | |
196 | 196 | $cycleData = [ |
197 | 197 | 'prefix' => $this->config->getAppValue('user_ldap', 'background_sync_prefix', null), |
198 | - 'offset' => (int)$this->config->getAppValue('user_ldap', 'background_sync_offset', 0), |
|
198 | + 'offset' => (int) $this->config->getAppValue('user_ldap', 'background_sync_offset', 0), |
|
199 | 199 | ]; |
200 | 200 | |
201 | 201 | if ( |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | * @return bool |
253 | 253 | */ |
254 | 254 | public function qualifiesToRun($cycleData) { |
255 | - $lastChange = $this->config->getAppValue('user_ldap', $cycleData['prefix'] . '_lastChange', 0); |
|
255 | + $lastChange = $this->config->getAppValue('user_ldap', $cycleData['prefix'].'_lastChange', 0); |
|
256 | 256 | if ((time() - $lastChange) > 60 * 30) { |
257 | 257 | return true; |
258 | 258 | } |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | */ |
267 | 267 | protected function increaseOffset($cycleData) { |
268 | 268 | $ldapConfig = new Configuration($cycleData['prefix']); |
269 | - $cycleData['offset'] += (int)$ldapConfig->ldapPagingSize; |
|
269 | + $cycleData['offset'] += (int) $ldapConfig->ldapPagingSize; |
|
270 | 270 | $this->setCycle($cycleData); |
271 | 271 | } |
272 | 272 |
@@ -42,341 +42,341 @@ |
||
42 | 42 | use Psr\Log\LoggerInterface; |
43 | 43 | |
44 | 44 | class Sync extends TimedJob { |
45 | - public const MAX_INTERVAL = 12 * 60 * 60; // 12h |
|
46 | - public const MIN_INTERVAL = 30 * 60; // 30min |
|
47 | - /** @var Helper */ |
|
48 | - protected $ldapHelper; |
|
49 | - /** @var LDAP */ |
|
50 | - protected $ldap; |
|
51 | - /** @var Manager */ |
|
52 | - protected $userManager; |
|
53 | - /** @var UserMapping */ |
|
54 | - protected $mapper; |
|
55 | - /** @var IConfig */ |
|
56 | - protected $config; |
|
57 | - /** @var IAvatarManager */ |
|
58 | - protected $avatarManager; |
|
59 | - /** @var IDBConnection */ |
|
60 | - protected $dbc; |
|
61 | - /** @var IUserManager */ |
|
62 | - protected $ncUserManager; |
|
63 | - /** @var LoggerInterface */ |
|
64 | - protected $logger; |
|
65 | - /** @var IManager */ |
|
66 | - protected $notificationManager; |
|
67 | - /** @var ConnectionFactory */ |
|
68 | - protected $connectionFactory; |
|
69 | - /** @var AccessFactory */ |
|
70 | - protected $accessFactory; |
|
71 | - |
|
72 | - public function __construct(Manager $userManager, ITimeFactory $time) { |
|
73 | - parent::__construct($time); |
|
74 | - $this->userManager = $userManager; |
|
75 | - $this->setInterval( |
|
76 | - \OC::$server->getConfig()->getAppValue( |
|
77 | - 'user_ldap', |
|
78 | - 'background_sync_interval', |
|
79 | - self::MIN_INTERVAL |
|
80 | - ) |
|
81 | - ); |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * updates the interval |
|
86 | - * |
|
87 | - * the idea is to adjust the interval depending on the amount of known users |
|
88 | - * and the attempt to update each user one day. At most it would run every |
|
89 | - * 30 minutes, and at least every 12 hours. |
|
90 | - */ |
|
91 | - public function updateInterval() { |
|
92 | - $minPagingSize = $this->getMinPagingSize(); |
|
93 | - $mappedUsers = $this->mapper->count(); |
|
94 | - |
|
95 | - $runsPerDay = ($minPagingSize === 0 || $mappedUsers === 0) ? self::MAX_INTERVAL |
|
96 | - : $mappedUsers / $minPagingSize; |
|
97 | - $interval = floor(24 * 60 * 60 / $runsPerDay); |
|
98 | - $interval = min(max($interval, self::MIN_INTERVAL), self::MAX_INTERVAL); |
|
99 | - |
|
100 | - $this->config->setAppValue('user_ldap', 'background_sync_interval', $interval); |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * returns the smallest configured paging size |
|
105 | - * @return int |
|
106 | - */ |
|
107 | - protected function getMinPagingSize() { |
|
108 | - $configKeys = $this->config->getAppKeys('user_ldap'); |
|
109 | - $configKeys = array_filter($configKeys, function ($key) { |
|
110 | - return strpos($key, 'ldap_paging_size') !== false; |
|
111 | - }); |
|
112 | - $minPagingSize = null; |
|
113 | - foreach ($configKeys as $configKey) { |
|
114 | - $pagingSize = $this->config->getAppValue('user_ldap', $configKey, $minPagingSize); |
|
115 | - $minPagingSize = $minPagingSize === null ? $pagingSize : min($minPagingSize, $pagingSize); |
|
116 | - } |
|
117 | - return (int)$minPagingSize; |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * @param array $argument |
|
122 | - */ |
|
123 | - public function run($argument) { |
|
124 | - $this->setArgument($argument); |
|
125 | - |
|
126 | - $isBackgroundJobModeAjax = $this->config |
|
127 | - ->getAppValue('core', 'backgroundjobs_mode', 'ajax') === 'ajax'; |
|
128 | - if ($isBackgroundJobModeAjax) { |
|
129 | - return; |
|
130 | - } |
|
131 | - |
|
132 | - $cycleData = $this->getCycle(); |
|
133 | - if ($cycleData === null) { |
|
134 | - $cycleData = $this->determineNextCycle(); |
|
135 | - if ($cycleData === null) { |
|
136 | - $this->updateInterval(); |
|
137 | - return; |
|
138 | - } |
|
139 | - } |
|
140 | - |
|
141 | - if (!$this->qualifiesToRun($cycleData)) { |
|
142 | - $this->updateInterval(); |
|
143 | - return; |
|
144 | - } |
|
145 | - |
|
146 | - try { |
|
147 | - $expectMoreResults = $this->runCycle($cycleData); |
|
148 | - if ($expectMoreResults) { |
|
149 | - $this->increaseOffset($cycleData); |
|
150 | - } else { |
|
151 | - $this->determineNextCycle($cycleData); |
|
152 | - } |
|
153 | - $this->updateInterval(); |
|
154 | - } catch (ServerNotAvailableException $e) { |
|
155 | - $this->determineNextCycle($cycleData); |
|
156 | - } |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * @param array $cycleData |
|
161 | - * @return bool whether more results are expected from the same configuration |
|
162 | - */ |
|
163 | - public function runCycle($cycleData) { |
|
164 | - $connection = $this->connectionFactory->get($cycleData['prefix']); |
|
165 | - $access = $this->accessFactory->get($connection); |
|
166 | - $access->setUserMapper($this->mapper); |
|
167 | - |
|
168 | - $filter = $access->combineFilterWithAnd([ |
|
169 | - $access->connection->ldapUserFilter, |
|
170 | - $access->connection->ldapUserDisplayName . '=*', |
|
171 | - $access->getFilterPartForUserSearch('') |
|
172 | - ]); |
|
173 | - $results = $access->fetchListOfUsers( |
|
174 | - $filter, |
|
175 | - $access->userManager->getAttributes(), |
|
176 | - $connection->ldapPagingSize, |
|
177 | - $cycleData['offset'], |
|
178 | - true |
|
179 | - ); |
|
180 | - |
|
181 | - if ((int)$connection->ldapPagingSize === 0) { |
|
182 | - return false; |
|
183 | - } |
|
184 | - return count($results) >= (int)$connection->ldapPagingSize; |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * returns the info about the current cycle that should be run, if any, |
|
189 | - * otherwise null |
|
190 | - * |
|
191 | - * @return array|null |
|
192 | - */ |
|
193 | - public function getCycle() { |
|
194 | - $prefixes = $this->ldapHelper->getServerConfigurationPrefixes(true); |
|
195 | - if (count($prefixes) === 0) { |
|
196 | - return null; |
|
197 | - } |
|
198 | - |
|
199 | - $cycleData = [ |
|
200 | - 'prefix' => $this->config->getAppValue('user_ldap', 'background_sync_prefix', null), |
|
201 | - 'offset' => (int)$this->config->getAppValue('user_ldap', 'background_sync_offset', 0), |
|
202 | - ]; |
|
203 | - |
|
204 | - if ( |
|
205 | - $cycleData['prefix'] !== null |
|
206 | - && in_array($cycleData['prefix'], $prefixes) |
|
207 | - ) { |
|
208 | - return $cycleData; |
|
209 | - } |
|
210 | - |
|
211 | - return null; |
|
212 | - } |
|
213 | - |
|
214 | - /** |
|
215 | - * Save the provided cycle information in the DB |
|
216 | - * |
|
217 | - * @param array $cycleData |
|
218 | - */ |
|
219 | - public function setCycle(array $cycleData) { |
|
220 | - $this->config->setAppValue('user_ldap', 'background_sync_prefix', $cycleData['prefix']); |
|
221 | - $this->config->setAppValue('user_ldap', 'background_sync_offset', $cycleData['offset']); |
|
222 | - } |
|
223 | - |
|
224 | - /** |
|
225 | - * returns data about the next cycle that should run, if any, otherwise |
|
226 | - * null. It also always goes for the next LDAP configuration! |
|
227 | - * |
|
228 | - * @param array|null $cycleData the old cycle |
|
229 | - * @return array|null |
|
230 | - */ |
|
231 | - public function determineNextCycle(array $cycleData = null) { |
|
232 | - $prefixes = $this->ldapHelper->getServerConfigurationPrefixes(true); |
|
233 | - if (count($prefixes) === 0) { |
|
234 | - return null; |
|
235 | - } |
|
236 | - |
|
237 | - // get the next prefix in line and remember it |
|
238 | - $oldPrefix = $cycleData === null ? null : $cycleData['prefix']; |
|
239 | - $prefix = $this->getNextPrefix($oldPrefix); |
|
240 | - if ($prefix === null) { |
|
241 | - return null; |
|
242 | - } |
|
243 | - $cycleData['prefix'] = $prefix; |
|
244 | - $cycleData['offset'] = 0; |
|
245 | - $this->setCycle(['prefix' => $prefix, 'offset' => 0]); |
|
246 | - |
|
247 | - return $cycleData; |
|
248 | - } |
|
249 | - |
|
250 | - /** |
|
251 | - * Checks whether the provided cycle should be run. Currently only the |
|
252 | - * last configuration change goes into account (at least one hour). |
|
253 | - * |
|
254 | - * @param $cycleData |
|
255 | - * @return bool |
|
256 | - */ |
|
257 | - public function qualifiesToRun($cycleData) { |
|
258 | - $lastChange = $this->config->getAppValue('user_ldap', $cycleData['prefix'] . '_lastChange', 0); |
|
259 | - if ((time() - $lastChange) > 60 * 30) { |
|
260 | - return true; |
|
261 | - } |
|
262 | - return false; |
|
263 | - } |
|
264 | - |
|
265 | - /** |
|
266 | - * increases the offset of the current cycle for the next run |
|
267 | - * |
|
268 | - * @param $cycleData |
|
269 | - */ |
|
270 | - protected function increaseOffset($cycleData) { |
|
271 | - $ldapConfig = new Configuration($cycleData['prefix']); |
|
272 | - $cycleData['offset'] += (int)$ldapConfig->ldapPagingSize; |
|
273 | - $this->setCycle($cycleData); |
|
274 | - } |
|
275 | - |
|
276 | - /** |
|
277 | - * determines the next configuration prefix based on the last one (if any) |
|
278 | - * |
|
279 | - * @param string|null $lastPrefix |
|
280 | - * @return string|null |
|
281 | - */ |
|
282 | - protected function getNextPrefix($lastPrefix) { |
|
283 | - $prefixes = $this->ldapHelper->getServerConfigurationPrefixes(true); |
|
284 | - $noOfPrefixes = count($prefixes); |
|
285 | - if ($noOfPrefixes === 0) { |
|
286 | - return null; |
|
287 | - } |
|
288 | - $i = $lastPrefix === null ? false : array_search($lastPrefix, $prefixes, true); |
|
289 | - if ($i === false) { |
|
290 | - $i = -1; |
|
291 | - } else { |
|
292 | - $i++; |
|
293 | - } |
|
294 | - |
|
295 | - if (!isset($prefixes[$i])) { |
|
296 | - $i = 0; |
|
297 | - } |
|
298 | - return $prefixes[$i]; |
|
299 | - } |
|
300 | - |
|
301 | - /** |
|
302 | - * "fixes" DI |
|
303 | - */ |
|
304 | - public function setArgument($argument) { |
|
305 | - if (isset($argument['config'])) { |
|
306 | - $this->config = $argument['config']; |
|
307 | - } else { |
|
308 | - $this->config = \OC::$server->getConfig(); |
|
309 | - } |
|
310 | - |
|
311 | - if (isset($argument['helper'])) { |
|
312 | - $this->ldapHelper = $argument['helper']; |
|
313 | - } else { |
|
314 | - $this->ldapHelper = new Helper($this->config, \OC::$server->getDatabaseConnection()); |
|
315 | - } |
|
316 | - |
|
317 | - if (isset($argument['ldapWrapper'])) { |
|
318 | - $this->ldap = $argument['ldapWrapper']; |
|
319 | - } else { |
|
320 | - $this->ldap = new LDAP($this->config->getSystemValueString('ldap_log_file')); |
|
321 | - } |
|
322 | - |
|
323 | - if (isset($argument['avatarManager'])) { |
|
324 | - $this->avatarManager = $argument['avatarManager']; |
|
325 | - } else { |
|
326 | - $this->avatarManager = \OC::$server->getAvatarManager(); |
|
327 | - } |
|
328 | - |
|
329 | - if (isset($argument['dbc'])) { |
|
330 | - $this->dbc = $argument['dbc']; |
|
331 | - } else { |
|
332 | - $this->dbc = \OC::$server->getDatabaseConnection(); |
|
333 | - } |
|
334 | - |
|
335 | - if (isset($argument['ncUserManager'])) { |
|
336 | - $this->ncUserManager = $argument['ncUserManager']; |
|
337 | - } else { |
|
338 | - $this->ncUserManager = \OC::$server->getUserManager(); |
|
339 | - } |
|
340 | - |
|
341 | - if (isset($argument['logger'])) { |
|
342 | - $this->logger = $argument['logger']; |
|
343 | - } else { |
|
344 | - $this->logger = \OC::$server->get(LoggerInterface::class); |
|
345 | - } |
|
346 | - |
|
347 | - if (isset($argument['notificationManager'])) { |
|
348 | - $this->notificationManager = $argument['notificationManager']; |
|
349 | - } else { |
|
350 | - $this->notificationManager = \OC::$server->getNotificationManager(); |
|
351 | - } |
|
352 | - |
|
353 | - if (isset($argument['userManager'])) { |
|
354 | - $this->userManager = $argument['userManager']; |
|
355 | - } |
|
356 | - |
|
357 | - if (isset($argument['mapper'])) { |
|
358 | - $this->mapper = $argument['mapper']; |
|
359 | - } else { |
|
360 | - $this->mapper = \OCP\Server::get(UserMapping::class); |
|
361 | - } |
|
362 | - |
|
363 | - if (isset($argument['connectionFactory'])) { |
|
364 | - $this->connectionFactory = $argument['connectionFactory']; |
|
365 | - } else { |
|
366 | - $this->connectionFactory = new ConnectionFactory($this->ldap); |
|
367 | - } |
|
368 | - |
|
369 | - if (isset($argument['accessFactory'])) { |
|
370 | - $this->accessFactory = $argument['accessFactory']; |
|
371 | - } else { |
|
372 | - $this->accessFactory = new AccessFactory( |
|
373 | - $this->ldap, |
|
374 | - $this->userManager, |
|
375 | - $this->ldapHelper, |
|
376 | - $this->config, |
|
377 | - $this->ncUserManager, |
|
378 | - $this->logger |
|
379 | - ); |
|
380 | - } |
|
381 | - } |
|
45 | + public const MAX_INTERVAL = 12 * 60 * 60; // 12h |
|
46 | + public const MIN_INTERVAL = 30 * 60; // 30min |
|
47 | + /** @var Helper */ |
|
48 | + protected $ldapHelper; |
|
49 | + /** @var LDAP */ |
|
50 | + protected $ldap; |
|
51 | + /** @var Manager */ |
|
52 | + protected $userManager; |
|
53 | + /** @var UserMapping */ |
|
54 | + protected $mapper; |
|
55 | + /** @var IConfig */ |
|
56 | + protected $config; |
|
57 | + /** @var IAvatarManager */ |
|
58 | + protected $avatarManager; |
|
59 | + /** @var IDBConnection */ |
|
60 | + protected $dbc; |
|
61 | + /** @var IUserManager */ |
|
62 | + protected $ncUserManager; |
|
63 | + /** @var LoggerInterface */ |
|
64 | + protected $logger; |
|
65 | + /** @var IManager */ |
|
66 | + protected $notificationManager; |
|
67 | + /** @var ConnectionFactory */ |
|
68 | + protected $connectionFactory; |
|
69 | + /** @var AccessFactory */ |
|
70 | + protected $accessFactory; |
|
71 | + |
|
72 | + public function __construct(Manager $userManager, ITimeFactory $time) { |
|
73 | + parent::__construct($time); |
|
74 | + $this->userManager = $userManager; |
|
75 | + $this->setInterval( |
|
76 | + \OC::$server->getConfig()->getAppValue( |
|
77 | + 'user_ldap', |
|
78 | + 'background_sync_interval', |
|
79 | + self::MIN_INTERVAL |
|
80 | + ) |
|
81 | + ); |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * updates the interval |
|
86 | + * |
|
87 | + * the idea is to adjust the interval depending on the amount of known users |
|
88 | + * and the attempt to update each user one day. At most it would run every |
|
89 | + * 30 minutes, and at least every 12 hours. |
|
90 | + */ |
|
91 | + public function updateInterval() { |
|
92 | + $minPagingSize = $this->getMinPagingSize(); |
|
93 | + $mappedUsers = $this->mapper->count(); |
|
94 | + |
|
95 | + $runsPerDay = ($minPagingSize === 0 || $mappedUsers === 0) ? self::MAX_INTERVAL |
|
96 | + : $mappedUsers / $minPagingSize; |
|
97 | + $interval = floor(24 * 60 * 60 / $runsPerDay); |
|
98 | + $interval = min(max($interval, self::MIN_INTERVAL), self::MAX_INTERVAL); |
|
99 | + |
|
100 | + $this->config->setAppValue('user_ldap', 'background_sync_interval', $interval); |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * returns the smallest configured paging size |
|
105 | + * @return int |
|
106 | + */ |
|
107 | + protected function getMinPagingSize() { |
|
108 | + $configKeys = $this->config->getAppKeys('user_ldap'); |
|
109 | + $configKeys = array_filter($configKeys, function ($key) { |
|
110 | + return strpos($key, 'ldap_paging_size') !== false; |
|
111 | + }); |
|
112 | + $minPagingSize = null; |
|
113 | + foreach ($configKeys as $configKey) { |
|
114 | + $pagingSize = $this->config->getAppValue('user_ldap', $configKey, $minPagingSize); |
|
115 | + $minPagingSize = $minPagingSize === null ? $pagingSize : min($minPagingSize, $pagingSize); |
|
116 | + } |
|
117 | + return (int)$minPagingSize; |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * @param array $argument |
|
122 | + */ |
|
123 | + public function run($argument) { |
|
124 | + $this->setArgument($argument); |
|
125 | + |
|
126 | + $isBackgroundJobModeAjax = $this->config |
|
127 | + ->getAppValue('core', 'backgroundjobs_mode', 'ajax') === 'ajax'; |
|
128 | + if ($isBackgroundJobModeAjax) { |
|
129 | + return; |
|
130 | + } |
|
131 | + |
|
132 | + $cycleData = $this->getCycle(); |
|
133 | + if ($cycleData === null) { |
|
134 | + $cycleData = $this->determineNextCycle(); |
|
135 | + if ($cycleData === null) { |
|
136 | + $this->updateInterval(); |
|
137 | + return; |
|
138 | + } |
|
139 | + } |
|
140 | + |
|
141 | + if (!$this->qualifiesToRun($cycleData)) { |
|
142 | + $this->updateInterval(); |
|
143 | + return; |
|
144 | + } |
|
145 | + |
|
146 | + try { |
|
147 | + $expectMoreResults = $this->runCycle($cycleData); |
|
148 | + if ($expectMoreResults) { |
|
149 | + $this->increaseOffset($cycleData); |
|
150 | + } else { |
|
151 | + $this->determineNextCycle($cycleData); |
|
152 | + } |
|
153 | + $this->updateInterval(); |
|
154 | + } catch (ServerNotAvailableException $e) { |
|
155 | + $this->determineNextCycle($cycleData); |
|
156 | + } |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * @param array $cycleData |
|
161 | + * @return bool whether more results are expected from the same configuration |
|
162 | + */ |
|
163 | + public function runCycle($cycleData) { |
|
164 | + $connection = $this->connectionFactory->get($cycleData['prefix']); |
|
165 | + $access = $this->accessFactory->get($connection); |
|
166 | + $access->setUserMapper($this->mapper); |
|
167 | + |
|
168 | + $filter = $access->combineFilterWithAnd([ |
|
169 | + $access->connection->ldapUserFilter, |
|
170 | + $access->connection->ldapUserDisplayName . '=*', |
|
171 | + $access->getFilterPartForUserSearch('') |
|
172 | + ]); |
|
173 | + $results = $access->fetchListOfUsers( |
|
174 | + $filter, |
|
175 | + $access->userManager->getAttributes(), |
|
176 | + $connection->ldapPagingSize, |
|
177 | + $cycleData['offset'], |
|
178 | + true |
|
179 | + ); |
|
180 | + |
|
181 | + if ((int)$connection->ldapPagingSize === 0) { |
|
182 | + return false; |
|
183 | + } |
|
184 | + return count($results) >= (int)$connection->ldapPagingSize; |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * returns the info about the current cycle that should be run, if any, |
|
189 | + * otherwise null |
|
190 | + * |
|
191 | + * @return array|null |
|
192 | + */ |
|
193 | + public function getCycle() { |
|
194 | + $prefixes = $this->ldapHelper->getServerConfigurationPrefixes(true); |
|
195 | + if (count($prefixes) === 0) { |
|
196 | + return null; |
|
197 | + } |
|
198 | + |
|
199 | + $cycleData = [ |
|
200 | + 'prefix' => $this->config->getAppValue('user_ldap', 'background_sync_prefix', null), |
|
201 | + 'offset' => (int)$this->config->getAppValue('user_ldap', 'background_sync_offset', 0), |
|
202 | + ]; |
|
203 | + |
|
204 | + if ( |
|
205 | + $cycleData['prefix'] !== null |
|
206 | + && in_array($cycleData['prefix'], $prefixes) |
|
207 | + ) { |
|
208 | + return $cycleData; |
|
209 | + } |
|
210 | + |
|
211 | + return null; |
|
212 | + } |
|
213 | + |
|
214 | + /** |
|
215 | + * Save the provided cycle information in the DB |
|
216 | + * |
|
217 | + * @param array $cycleData |
|
218 | + */ |
|
219 | + public function setCycle(array $cycleData) { |
|
220 | + $this->config->setAppValue('user_ldap', 'background_sync_prefix', $cycleData['prefix']); |
|
221 | + $this->config->setAppValue('user_ldap', 'background_sync_offset', $cycleData['offset']); |
|
222 | + } |
|
223 | + |
|
224 | + /** |
|
225 | + * returns data about the next cycle that should run, if any, otherwise |
|
226 | + * null. It also always goes for the next LDAP configuration! |
|
227 | + * |
|
228 | + * @param array|null $cycleData the old cycle |
|
229 | + * @return array|null |
|
230 | + */ |
|
231 | + public function determineNextCycle(array $cycleData = null) { |
|
232 | + $prefixes = $this->ldapHelper->getServerConfigurationPrefixes(true); |
|
233 | + if (count($prefixes) === 0) { |
|
234 | + return null; |
|
235 | + } |
|
236 | + |
|
237 | + // get the next prefix in line and remember it |
|
238 | + $oldPrefix = $cycleData === null ? null : $cycleData['prefix']; |
|
239 | + $prefix = $this->getNextPrefix($oldPrefix); |
|
240 | + if ($prefix === null) { |
|
241 | + return null; |
|
242 | + } |
|
243 | + $cycleData['prefix'] = $prefix; |
|
244 | + $cycleData['offset'] = 0; |
|
245 | + $this->setCycle(['prefix' => $prefix, 'offset' => 0]); |
|
246 | + |
|
247 | + return $cycleData; |
|
248 | + } |
|
249 | + |
|
250 | + /** |
|
251 | + * Checks whether the provided cycle should be run. Currently only the |
|
252 | + * last configuration change goes into account (at least one hour). |
|
253 | + * |
|
254 | + * @param $cycleData |
|
255 | + * @return bool |
|
256 | + */ |
|
257 | + public function qualifiesToRun($cycleData) { |
|
258 | + $lastChange = $this->config->getAppValue('user_ldap', $cycleData['prefix'] . '_lastChange', 0); |
|
259 | + if ((time() - $lastChange) > 60 * 30) { |
|
260 | + return true; |
|
261 | + } |
|
262 | + return false; |
|
263 | + } |
|
264 | + |
|
265 | + /** |
|
266 | + * increases the offset of the current cycle for the next run |
|
267 | + * |
|
268 | + * @param $cycleData |
|
269 | + */ |
|
270 | + protected function increaseOffset($cycleData) { |
|
271 | + $ldapConfig = new Configuration($cycleData['prefix']); |
|
272 | + $cycleData['offset'] += (int)$ldapConfig->ldapPagingSize; |
|
273 | + $this->setCycle($cycleData); |
|
274 | + } |
|
275 | + |
|
276 | + /** |
|
277 | + * determines the next configuration prefix based on the last one (if any) |
|
278 | + * |
|
279 | + * @param string|null $lastPrefix |
|
280 | + * @return string|null |
|
281 | + */ |
|
282 | + protected function getNextPrefix($lastPrefix) { |
|
283 | + $prefixes = $this->ldapHelper->getServerConfigurationPrefixes(true); |
|
284 | + $noOfPrefixes = count($prefixes); |
|
285 | + if ($noOfPrefixes === 0) { |
|
286 | + return null; |
|
287 | + } |
|
288 | + $i = $lastPrefix === null ? false : array_search($lastPrefix, $prefixes, true); |
|
289 | + if ($i === false) { |
|
290 | + $i = -1; |
|
291 | + } else { |
|
292 | + $i++; |
|
293 | + } |
|
294 | + |
|
295 | + if (!isset($prefixes[$i])) { |
|
296 | + $i = 0; |
|
297 | + } |
|
298 | + return $prefixes[$i]; |
|
299 | + } |
|
300 | + |
|
301 | + /** |
|
302 | + * "fixes" DI |
|
303 | + */ |
|
304 | + public function setArgument($argument) { |
|
305 | + if (isset($argument['config'])) { |
|
306 | + $this->config = $argument['config']; |
|
307 | + } else { |
|
308 | + $this->config = \OC::$server->getConfig(); |
|
309 | + } |
|
310 | + |
|
311 | + if (isset($argument['helper'])) { |
|
312 | + $this->ldapHelper = $argument['helper']; |
|
313 | + } else { |
|
314 | + $this->ldapHelper = new Helper($this->config, \OC::$server->getDatabaseConnection()); |
|
315 | + } |
|
316 | + |
|
317 | + if (isset($argument['ldapWrapper'])) { |
|
318 | + $this->ldap = $argument['ldapWrapper']; |
|
319 | + } else { |
|
320 | + $this->ldap = new LDAP($this->config->getSystemValueString('ldap_log_file')); |
|
321 | + } |
|
322 | + |
|
323 | + if (isset($argument['avatarManager'])) { |
|
324 | + $this->avatarManager = $argument['avatarManager']; |
|
325 | + } else { |
|
326 | + $this->avatarManager = \OC::$server->getAvatarManager(); |
|
327 | + } |
|
328 | + |
|
329 | + if (isset($argument['dbc'])) { |
|
330 | + $this->dbc = $argument['dbc']; |
|
331 | + } else { |
|
332 | + $this->dbc = \OC::$server->getDatabaseConnection(); |
|
333 | + } |
|
334 | + |
|
335 | + if (isset($argument['ncUserManager'])) { |
|
336 | + $this->ncUserManager = $argument['ncUserManager']; |
|
337 | + } else { |
|
338 | + $this->ncUserManager = \OC::$server->getUserManager(); |
|
339 | + } |
|
340 | + |
|
341 | + if (isset($argument['logger'])) { |
|
342 | + $this->logger = $argument['logger']; |
|
343 | + } else { |
|
344 | + $this->logger = \OC::$server->get(LoggerInterface::class); |
|
345 | + } |
|
346 | + |
|
347 | + if (isset($argument['notificationManager'])) { |
|
348 | + $this->notificationManager = $argument['notificationManager']; |
|
349 | + } else { |
|
350 | + $this->notificationManager = \OC::$server->getNotificationManager(); |
|
351 | + } |
|
352 | + |
|
353 | + if (isset($argument['userManager'])) { |
|
354 | + $this->userManager = $argument['userManager']; |
|
355 | + } |
|
356 | + |
|
357 | + if (isset($argument['mapper'])) { |
|
358 | + $this->mapper = $argument['mapper']; |
|
359 | + } else { |
|
360 | + $this->mapper = \OCP\Server::get(UserMapping::class); |
|
361 | + } |
|
362 | + |
|
363 | + if (isset($argument['connectionFactory'])) { |
|
364 | + $this->connectionFactory = $argument['connectionFactory']; |
|
365 | + } else { |
|
366 | + $this->connectionFactory = new ConnectionFactory($this->ldap); |
|
367 | + } |
|
368 | + |
|
369 | + if (isset($argument['accessFactory'])) { |
|
370 | + $this->accessFactory = $argument['accessFactory']; |
|
371 | + } else { |
|
372 | + $this->accessFactory = new AccessFactory( |
|
373 | + $this->ldap, |
|
374 | + $this->userManager, |
|
375 | + $this->ldapHelper, |
|
376 | + $this->config, |
|
377 | + $this->ncUserManager, |
|
378 | + $this->logger |
|
379 | + ); |
|
380 | + } |
|
381 | + } |
|
382 | 382 | } |
@@ -33,69 +33,69 @@ |
||
33 | 33 | |
34 | 34 | class UUIDFixInsert implements IRepairStep { |
35 | 35 | |
36 | - /** @var IConfig */ |
|
37 | - protected $config; |
|
36 | + /** @var IConfig */ |
|
37 | + protected $config; |
|
38 | 38 | |
39 | - /** @var UserMapping */ |
|
40 | - protected $userMapper; |
|
39 | + /** @var UserMapping */ |
|
40 | + protected $userMapper; |
|
41 | 41 | |
42 | - /** @var GroupMapping */ |
|
43 | - protected $groupMapper; |
|
42 | + /** @var GroupMapping */ |
|
43 | + protected $groupMapper; |
|
44 | 44 | |
45 | - /** @var IJobList */ |
|
46 | - protected $jobList; |
|
45 | + /** @var IJobList */ |
|
46 | + protected $jobList; |
|
47 | 47 | |
48 | - public function __construct(IConfig $config, UserMapping $userMapper, GroupMapping $groupMapper, IJobList $jobList) { |
|
49 | - $this->config = $config; |
|
50 | - $this->userMapper = $userMapper; |
|
51 | - $this->groupMapper = $groupMapper; |
|
52 | - $this->jobList = $jobList; |
|
53 | - } |
|
48 | + public function __construct(IConfig $config, UserMapping $userMapper, GroupMapping $groupMapper, IJobList $jobList) { |
|
49 | + $this->config = $config; |
|
50 | + $this->userMapper = $userMapper; |
|
51 | + $this->groupMapper = $groupMapper; |
|
52 | + $this->jobList = $jobList; |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * Returns the step's name |
|
57 | - * |
|
58 | - * @return string |
|
59 | - * @since 9.1.0 |
|
60 | - */ |
|
61 | - public function getName() { |
|
62 | - return 'Insert UUIDFix background job for user and group in batches'; |
|
63 | - } |
|
55 | + /** |
|
56 | + * Returns the step's name |
|
57 | + * |
|
58 | + * @return string |
|
59 | + * @since 9.1.0 |
|
60 | + */ |
|
61 | + public function getName() { |
|
62 | + return 'Insert UUIDFix background job for user and group in batches'; |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * Run repair step. |
|
67 | - * Must throw exception on error. |
|
68 | - * |
|
69 | - * @param IOutput $output |
|
70 | - * @throws \Exception in case of failure |
|
71 | - * @since 9.1.0 |
|
72 | - */ |
|
73 | - public function run(IOutput $output) { |
|
74 | - $installedVersion = $this->config->getAppValue('user_ldap', 'installed_version', '1.2.1'); |
|
75 | - if (version_compare($installedVersion, '1.2.1') !== -1) { |
|
76 | - return; |
|
77 | - } |
|
65 | + /** |
|
66 | + * Run repair step. |
|
67 | + * Must throw exception on error. |
|
68 | + * |
|
69 | + * @param IOutput $output |
|
70 | + * @throws \Exception in case of failure |
|
71 | + * @since 9.1.0 |
|
72 | + */ |
|
73 | + public function run(IOutput $output) { |
|
74 | + $installedVersion = $this->config->getAppValue('user_ldap', 'installed_version', '1.2.1'); |
|
75 | + if (version_compare($installedVersion, '1.2.1') !== -1) { |
|
76 | + return; |
|
77 | + } |
|
78 | 78 | |
79 | - foreach ([$this->userMapper, $this->groupMapper] as $mapper) { |
|
80 | - $offset = 0; |
|
81 | - $batchSize = 50; |
|
82 | - $jobClass = $mapper instanceof UserMapping ? UUIDFixUser::class : UUIDFixGroup::class; |
|
83 | - do { |
|
84 | - $retry = false; |
|
85 | - $records = $mapper->getList($offset, $batchSize); |
|
86 | - if (count($records) === 0) { |
|
87 | - continue; |
|
88 | - } |
|
89 | - try { |
|
90 | - $this->jobList->add($jobClass, ['records' => $records]); |
|
91 | - $offset += $batchSize; |
|
92 | - } catch (\InvalidArgumentException $e) { |
|
93 | - if (strpos($e->getMessage(), 'Background job arguments can\'t exceed 4000') !== false) { |
|
94 | - $batchSize = (int)floor(count($records) * 0.8); |
|
95 | - $retry = true; |
|
96 | - } |
|
97 | - } |
|
98 | - } while (count($records) === $batchSize || $retry); |
|
99 | - } |
|
100 | - } |
|
79 | + foreach ([$this->userMapper, $this->groupMapper] as $mapper) { |
|
80 | + $offset = 0; |
|
81 | + $batchSize = 50; |
|
82 | + $jobClass = $mapper instanceof UserMapping ? UUIDFixUser::class : UUIDFixGroup::class; |
|
83 | + do { |
|
84 | + $retry = false; |
|
85 | + $records = $mapper->getList($offset, $batchSize); |
|
86 | + if (count($records) === 0) { |
|
87 | + continue; |
|
88 | + } |
|
89 | + try { |
|
90 | + $this->jobList->add($jobClass, ['records' => $records]); |
|
91 | + $offset += $batchSize; |
|
92 | + } catch (\InvalidArgumentException $e) { |
|
93 | + if (strpos($e->getMessage(), 'Background job arguments can\'t exceed 4000') !== false) { |
|
94 | + $batchSize = (int)floor(count($records) * 0.8); |
|
95 | + $retry = true; |
|
96 | + } |
|
97 | + } |
|
98 | + } while (count($records) === $batchSize || $retry); |
|
99 | + } |
|
100 | + } |
|
101 | 101 | } |
@@ -91,7 +91,7 @@ |
||
91 | 91 | $offset += $batchSize; |
92 | 92 | } catch (\InvalidArgumentException $e) { |
93 | 93 | if (strpos($e->getMessage(), 'Background job arguments can\'t exceed 4000') !== false) { |
94 | - $batchSize = (int)floor(count($records) * 0.8); |
|
94 | + $batchSize = (int) floor(count($records) * 0.8); |
|
95 | 95 | $retry = true; |
96 | 96 | } |
97 | 97 | } |
@@ -24,14 +24,14 @@ discard block |
||
24 | 24 | <?php endif; ?> |
25 | 25 | <div id="message" class="hidden"> |
26 | 26 | <img class="float-spinner" alt="" |
27 | - src="<?php p(image_path('core', 'loading-dark.gif'));?>"> |
|
27 | + src="<?php p(image_path('core', 'loading-dark.gif')); ?>"> |
|
28 | 28 | <span id="messageText"></span> |
29 | 29 | <!-- the following div ensures that the spinner is always inside the #message div --> |
30 | 30 | <div style="clear: both;"></div> |
31 | 31 | </div> |
32 | 32 | <p class="grouptop"> |
33 | 33 | <input type="password" id="oldPassword" name="oldPassword" |
34 | - placeholder="<?php echo $l->t('Current password');?>" |
|
34 | + placeholder="<?php echo $l->t('Current password'); ?>" |
|
35 | 35 | autofocus autocomplete="off" autocapitalize="off" autocorrect="off" required/> |
36 | 36 | <label for="oldPassword" class="infield"><?php p($l->t('Current password')); ?></label> |
37 | 37 | </p> |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | <input type="checkbox" id="personal-show" name="show" class="hidden-visually" /><label for="personal-show"></label> |
41 | 41 | <label id="newPassword-label" for="newPassword" class="infield"><?php p($l->t('New password')); ?></label> |
42 | 42 | <input type="password" id="newPassword" name="newPassword" |
43 | - placeholder="<?php echo $l->t('New password');?>" |
|
43 | + placeholder="<?php echo $l->t('New password'); ?>" |
|
44 | 44 | data-typetoggle="#personal-show" autofocus autocomplete="off" autocapitalize="off" autocorrect="off" required/> |
45 | 45 | </p> |
46 | 46 |