@@ -30,9 +30,9 @@ |
||
| 30 | 30 | use OCP\IConfig; |
| 31 | 31 | |
| 32 | 32 | class UUIDFixGroup extends UUIDFix { |
| 33 | - public function __construct(GroupMapping $mapper, LDAP $ldap, IConfig $config, Helper $helper) { |
|
| 34 | - $this->mapper = $mapper; |
|
| 35 | - $this->proxy = new User_Proxy($helper->getServerConfigurationPrefixes(true), $ldap, $config, |
|
| 36 | - \OC::$server->getNotificationManager(), \OC::$server->getUserSession()); |
|
| 37 | - } |
|
| 33 | + public function __construct(GroupMapping $mapper, LDAP $ldap, IConfig $config, Helper $helper) { |
|
| 34 | + $this->mapper = $mapper; |
|
| 35 | + $this->proxy = new User_Proxy($helper->getServerConfigurationPrefixes(true), $ldap, $config, |
|
| 36 | + \OC::$server->getNotificationManager(), \OC::$server->getUserSession()); |
|
| 37 | + } |
|
| 38 | 38 | } |
@@ -40,196 +40,196 @@ |
||
| 40 | 40 | * @package OCA\User_LDAP\Jobs; |
| 41 | 41 | */ |
| 42 | 42 | class CleanUp extends TimedJob { |
| 43 | - /** @var int $limit amount of users that should be checked per run */ |
|
| 44 | - protected $limit = 50; |
|
| 45 | - |
|
| 46 | - /** @var int $defaultIntervalMin default interval in minutes */ |
|
| 47 | - protected $defaultIntervalMin = 51; |
|
| 48 | - |
|
| 49 | - /** @var User_LDAP|User_Proxy $userBackend */ |
|
| 50 | - protected $userBackend; |
|
| 51 | - |
|
| 52 | - /** @var \OCP\IConfig $ocConfig */ |
|
| 53 | - protected $ocConfig; |
|
| 54 | - |
|
| 55 | - /** @var \OCP\IDBConnection $db */ |
|
| 56 | - protected $db; |
|
| 57 | - |
|
| 58 | - /** @var Helper $ldapHelper */ |
|
| 59 | - protected $ldapHelper; |
|
| 60 | - |
|
| 61 | - /** @var \OCA\User_LDAP\Mapping\UserMapping */ |
|
| 62 | - protected $mapping; |
|
| 63 | - |
|
| 64 | - /** @var \OCA\User_LDAP\User\DeletedUsersIndex */ |
|
| 65 | - protected $dui; |
|
| 66 | - |
|
| 67 | - public function __construct() { |
|
| 68 | - $minutes = \OC::$server->getConfig()->getSystemValue( |
|
| 69 | - 'ldapUserCleanupInterval', strval($this->defaultIntervalMin)); |
|
| 70 | - $this->setInterval(intval($minutes) * 60); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * assigns the instances passed to run() to the class properties |
|
| 75 | - * @param array $arguments |
|
| 76 | - */ |
|
| 77 | - public function setArguments($arguments) { |
|
| 78 | - //Dependency Injection is not possible, because the constructor will |
|
| 79 | - //only get values that are serialized to JSON. I.e. whatever we would |
|
| 80 | - //pass in app.php we do add here, except something else is passed e.g. |
|
| 81 | - //in tests. |
|
| 82 | - |
|
| 83 | - if(isset($arguments['helper'])) { |
|
| 84 | - $this->ldapHelper = $arguments['helper']; |
|
| 85 | - } else { |
|
| 86 | - $this->ldapHelper = new Helper(\OC::$server->getConfig()); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - if(isset($arguments['ocConfig'])) { |
|
| 90 | - $this->ocConfig = $arguments['ocConfig']; |
|
| 91 | - } else { |
|
| 92 | - $this->ocConfig = \OC::$server->getConfig(); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - if(isset($arguments['userBackend'])) { |
|
| 96 | - $this->userBackend = $arguments['userBackend']; |
|
| 97 | - } else { |
|
| 98 | - $this->userBackend = new User_Proxy( |
|
| 99 | - $this->ldapHelper->getServerConfigurationPrefixes(true), |
|
| 100 | - new LDAP(), |
|
| 101 | - $this->ocConfig, |
|
| 102 | - \OC::$server->getNotificationManager(), |
|
| 103 | - \OC::$server->getUserSession() |
|
| 104 | - ); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - if(isset($arguments['db'])) { |
|
| 108 | - $this->db = $arguments['db']; |
|
| 109 | - } else { |
|
| 110 | - $this->db = \OC::$server->getDatabaseConnection(); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - if(isset($arguments['mapping'])) { |
|
| 114 | - $this->mapping = $arguments['mapping']; |
|
| 115 | - } else { |
|
| 116 | - $this->mapping = new UserMapping($this->db); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - if(isset($arguments['deletedUsersIndex'])) { |
|
| 120 | - $this->dui = $arguments['deletedUsersIndex']; |
|
| 121 | - } else { |
|
| 122 | - $this->dui = new DeletedUsersIndex( |
|
| 123 | - $this->ocConfig, $this->db, $this->mapping); |
|
| 124 | - } |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * makes the background job do its work |
|
| 129 | - * @param array $argument |
|
| 130 | - */ |
|
| 131 | - public function run($argument) { |
|
| 132 | - $this->setArguments($argument); |
|
| 133 | - |
|
| 134 | - if(!$this->isCleanUpAllowed()) { |
|
| 135 | - return; |
|
| 136 | - } |
|
| 137 | - $users = $this->mapping->getList($this->getOffset(), $this->limit); |
|
| 138 | - if(!is_array($users)) { |
|
| 139 | - //something wrong? Let's start from the beginning next time and |
|
| 140 | - //abort |
|
| 141 | - $this->setOffset(true); |
|
| 142 | - return; |
|
| 143 | - } |
|
| 144 | - $resetOffset = $this->isOffsetResetNecessary(count($users)); |
|
| 145 | - $this->checkUsers($users); |
|
| 146 | - $this->setOffset($resetOffset); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * checks whether next run should start at 0 again |
|
| 151 | - * @param int $resultCount |
|
| 152 | - * @return bool |
|
| 153 | - */ |
|
| 154 | - public function isOffsetResetNecessary($resultCount) { |
|
| 155 | - return ($resultCount < $this->limit) ? true : false; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * checks whether cleaning up LDAP users is allowed |
|
| 160 | - * @return bool |
|
| 161 | - */ |
|
| 162 | - public function isCleanUpAllowed() { |
|
| 163 | - try { |
|
| 164 | - if($this->ldapHelper->haveDisabledConfigurations()) { |
|
| 165 | - return false; |
|
| 166 | - } |
|
| 167 | - } catch (\Exception $e) { |
|
| 168 | - return false; |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - $enabled = $this->isCleanUpEnabled(); |
|
| 172 | - |
|
| 173 | - return $enabled; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * checks whether clean up is enabled by configuration |
|
| 178 | - * @return bool |
|
| 179 | - */ |
|
| 180 | - private function isCleanUpEnabled() { |
|
| 181 | - return (bool)$this->ocConfig->getSystemValue( |
|
| 182 | - 'ldapUserCleanupInterval', strval($this->defaultIntervalMin)); |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * checks users whether they are still existing |
|
| 187 | - * @param array $users result from getMappedUsers() |
|
| 188 | - */ |
|
| 189 | - private function checkUsers(array $users) { |
|
| 190 | - foreach($users as $user) { |
|
| 191 | - $this->checkUser($user); |
|
| 192 | - } |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * checks whether a user is still existing in LDAP |
|
| 197 | - * @param string[] $user |
|
| 198 | - */ |
|
| 199 | - private function checkUser(array $user) { |
|
| 200 | - if($this->userBackend->userExistsOnLDAP($user['name'])) { |
|
| 201 | - //still available, all good |
|
| 202 | - |
|
| 203 | - return; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - $this->dui->markUser($user['name']); |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * gets the offset to fetch users from the mappings table |
|
| 211 | - * @return int |
|
| 212 | - */ |
|
| 213 | - private function getOffset() { |
|
| 214 | - return intval($this->ocConfig->getAppValue('user_ldap', 'cleanUpJobOffset', 0)); |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - /** |
|
| 218 | - * sets the new offset for the next run |
|
| 219 | - * @param bool $reset whether the offset should be set to 0 |
|
| 220 | - */ |
|
| 221 | - public function setOffset($reset = false) { |
|
| 222 | - $newOffset = $reset ? 0 : |
|
| 223 | - $this->getOffset() + $this->limit; |
|
| 224 | - $this->ocConfig->setAppValue('user_ldap', 'cleanUpJobOffset', $newOffset); |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - /** |
|
| 228 | - * returns the chunk size (limit in DB speak) |
|
| 229 | - * @return int |
|
| 230 | - */ |
|
| 231 | - public function getChunkSize() { |
|
| 232 | - return $this->limit; |
|
| 233 | - } |
|
| 43 | + /** @var int $limit amount of users that should be checked per run */ |
|
| 44 | + protected $limit = 50; |
|
| 45 | + |
|
| 46 | + /** @var int $defaultIntervalMin default interval in minutes */ |
|
| 47 | + protected $defaultIntervalMin = 51; |
|
| 48 | + |
|
| 49 | + /** @var User_LDAP|User_Proxy $userBackend */ |
|
| 50 | + protected $userBackend; |
|
| 51 | + |
|
| 52 | + /** @var \OCP\IConfig $ocConfig */ |
|
| 53 | + protected $ocConfig; |
|
| 54 | + |
|
| 55 | + /** @var \OCP\IDBConnection $db */ |
|
| 56 | + protected $db; |
|
| 57 | + |
|
| 58 | + /** @var Helper $ldapHelper */ |
|
| 59 | + protected $ldapHelper; |
|
| 60 | + |
|
| 61 | + /** @var \OCA\User_LDAP\Mapping\UserMapping */ |
|
| 62 | + protected $mapping; |
|
| 63 | + |
|
| 64 | + /** @var \OCA\User_LDAP\User\DeletedUsersIndex */ |
|
| 65 | + protected $dui; |
|
| 66 | + |
|
| 67 | + public function __construct() { |
|
| 68 | + $minutes = \OC::$server->getConfig()->getSystemValue( |
|
| 69 | + 'ldapUserCleanupInterval', strval($this->defaultIntervalMin)); |
|
| 70 | + $this->setInterval(intval($minutes) * 60); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * assigns the instances passed to run() to the class properties |
|
| 75 | + * @param array $arguments |
|
| 76 | + */ |
|
| 77 | + public function setArguments($arguments) { |
|
| 78 | + //Dependency Injection is not possible, because the constructor will |
|
| 79 | + //only get values that are serialized to JSON. I.e. whatever we would |
|
| 80 | + //pass in app.php we do add here, except something else is passed e.g. |
|
| 81 | + //in tests. |
|
| 82 | + |
|
| 83 | + if(isset($arguments['helper'])) { |
|
| 84 | + $this->ldapHelper = $arguments['helper']; |
|
| 85 | + } else { |
|
| 86 | + $this->ldapHelper = new Helper(\OC::$server->getConfig()); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + if(isset($arguments['ocConfig'])) { |
|
| 90 | + $this->ocConfig = $arguments['ocConfig']; |
|
| 91 | + } else { |
|
| 92 | + $this->ocConfig = \OC::$server->getConfig(); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + if(isset($arguments['userBackend'])) { |
|
| 96 | + $this->userBackend = $arguments['userBackend']; |
|
| 97 | + } else { |
|
| 98 | + $this->userBackend = new User_Proxy( |
|
| 99 | + $this->ldapHelper->getServerConfigurationPrefixes(true), |
|
| 100 | + new LDAP(), |
|
| 101 | + $this->ocConfig, |
|
| 102 | + \OC::$server->getNotificationManager(), |
|
| 103 | + \OC::$server->getUserSession() |
|
| 104 | + ); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + if(isset($arguments['db'])) { |
|
| 108 | + $this->db = $arguments['db']; |
|
| 109 | + } else { |
|
| 110 | + $this->db = \OC::$server->getDatabaseConnection(); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + if(isset($arguments['mapping'])) { |
|
| 114 | + $this->mapping = $arguments['mapping']; |
|
| 115 | + } else { |
|
| 116 | + $this->mapping = new UserMapping($this->db); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + if(isset($arguments['deletedUsersIndex'])) { |
|
| 120 | + $this->dui = $arguments['deletedUsersIndex']; |
|
| 121 | + } else { |
|
| 122 | + $this->dui = new DeletedUsersIndex( |
|
| 123 | + $this->ocConfig, $this->db, $this->mapping); |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * makes the background job do its work |
|
| 129 | + * @param array $argument |
|
| 130 | + */ |
|
| 131 | + public function run($argument) { |
|
| 132 | + $this->setArguments($argument); |
|
| 133 | + |
|
| 134 | + if(!$this->isCleanUpAllowed()) { |
|
| 135 | + return; |
|
| 136 | + } |
|
| 137 | + $users = $this->mapping->getList($this->getOffset(), $this->limit); |
|
| 138 | + if(!is_array($users)) { |
|
| 139 | + //something wrong? Let's start from the beginning next time and |
|
| 140 | + //abort |
|
| 141 | + $this->setOffset(true); |
|
| 142 | + return; |
|
| 143 | + } |
|
| 144 | + $resetOffset = $this->isOffsetResetNecessary(count($users)); |
|
| 145 | + $this->checkUsers($users); |
|
| 146 | + $this->setOffset($resetOffset); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * checks whether next run should start at 0 again |
|
| 151 | + * @param int $resultCount |
|
| 152 | + * @return bool |
|
| 153 | + */ |
|
| 154 | + public function isOffsetResetNecessary($resultCount) { |
|
| 155 | + return ($resultCount < $this->limit) ? true : false; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * checks whether cleaning up LDAP users is allowed |
|
| 160 | + * @return bool |
|
| 161 | + */ |
|
| 162 | + public function isCleanUpAllowed() { |
|
| 163 | + try { |
|
| 164 | + if($this->ldapHelper->haveDisabledConfigurations()) { |
|
| 165 | + return false; |
|
| 166 | + } |
|
| 167 | + } catch (\Exception $e) { |
|
| 168 | + return false; |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + $enabled = $this->isCleanUpEnabled(); |
|
| 172 | + |
|
| 173 | + return $enabled; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * checks whether clean up is enabled by configuration |
|
| 178 | + * @return bool |
|
| 179 | + */ |
|
| 180 | + private function isCleanUpEnabled() { |
|
| 181 | + return (bool)$this->ocConfig->getSystemValue( |
|
| 182 | + 'ldapUserCleanupInterval', strval($this->defaultIntervalMin)); |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + /** |
|
| 186 | + * checks users whether they are still existing |
|
| 187 | + * @param array $users result from getMappedUsers() |
|
| 188 | + */ |
|
| 189 | + private function checkUsers(array $users) { |
|
| 190 | + foreach($users as $user) { |
|
| 191 | + $this->checkUser($user); |
|
| 192 | + } |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * checks whether a user is still existing in LDAP |
|
| 197 | + * @param string[] $user |
|
| 198 | + */ |
|
| 199 | + private function checkUser(array $user) { |
|
| 200 | + if($this->userBackend->userExistsOnLDAP($user['name'])) { |
|
| 201 | + //still available, all good |
|
| 202 | + |
|
| 203 | + return; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + $this->dui->markUser($user['name']); |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * gets the offset to fetch users from the mappings table |
|
| 211 | + * @return int |
|
| 212 | + */ |
|
| 213 | + private function getOffset() { |
|
| 214 | + return intval($this->ocConfig->getAppValue('user_ldap', 'cleanUpJobOffset', 0)); |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + /** |
|
| 218 | + * sets the new offset for the next run |
|
| 219 | + * @param bool $reset whether the offset should be set to 0 |
|
| 220 | + */ |
|
| 221 | + public function setOffset($reset = false) { |
|
| 222 | + $newOffset = $reset ? 0 : |
|
| 223 | + $this->getOffset() + $this->limit; |
|
| 224 | + $this->ocConfig->setAppValue('user_ldap', 'cleanUpJobOffset', $newOffset); |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * returns the chunk size (limit in DB speak) |
|
| 229 | + * @return int |
|
| 230 | + */ |
|
| 231 | + public function getChunkSize() { |
|
| 232 | + return $this->limit; |
|
| 233 | + } |
|
| 234 | 234 | |
| 235 | 235 | } |
@@ -34,126 +34,126 @@ discard block |
||
| 34 | 34 | |
| 35 | 35 | class Helper { |
| 36 | 36 | |
| 37 | - /** @var IConfig */ |
|
| 38 | - private $config; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * Helper constructor. |
|
| 42 | - * |
|
| 43 | - * @param IConfig $config |
|
| 44 | - */ |
|
| 45 | - public function __construct(IConfig $config) { |
|
| 46 | - $this->config = $config; |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * returns prefixes for each saved LDAP/AD server configuration. |
|
| 51 | - * @param bool $activeConfigurations optional, whether only active configuration shall be |
|
| 52 | - * retrieved, defaults to false |
|
| 53 | - * @return array with a list of the available prefixes |
|
| 54 | - * |
|
| 55 | - * Configuration prefixes are used to set up configurations for n LDAP or |
|
| 56 | - * AD servers. Since configuration is stored in the database, table |
|
| 57 | - * appconfig under appid user_ldap, the common identifiers in column |
|
| 58 | - * 'configkey' have a prefix. The prefix for the very first server |
|
| 59 | - * configuration is empty. |
|
| 60 | - * Configkey Examples: |
|
| 61 | - * Server 1: ldap_login_filter |
|
| 62 | - * Server 2: s1_ldap_login_filter |
|
| 63 | - * Server 3: s2_ldap_login_filter |
|
| 64 | - * |
|
| 65 | - * The prefix needs to be passed to the constructor of Connection class, |
|
| 66 | - * except the default (first) server shall be connected to. |
|
| 67 | - * |
|
| 68 | - */ |
|
| 69 | - public function getServerConfigurationPrefixes($activeConfigurations = false) { |
|
| 70 | - $referenceConfigkey = 'ldap_configuration_active'; |
|
| 71 | - |
|
| 72 | - $keys = $this->getServersConfig($referenceConfigkey); |
|
| 73 | - |
|
| 74 | - $prefixes = []; |
|
| 75 | - foreach ($keys as $key) { |
|
| 76 | - if ($activeConfigurations && $this->config->getAppValue('user_ldap', $key, '0') !== '1') { |
|
| 77 | - continue; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - $len = strlen($key) - strlen($referenceConfigkey); |
|
| 81 | - $prefixes[] = substr($key, 0, $len); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - return $prefixes; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * |
|
| 89 | - * determines the host for every configured connection |
|
| 90 | - * @return array an array with configprefix as keys |
|
| 91 | - * |
|
| 92 | - */ |
|
| 93 | - public function getServerConfigurationHosts() { |
|
| 94 | - $referenceConfigkey = 'ldap_host'; |
|
| 95 | - |
|
| 96 | - $keys = $this->getServersConfig($referenceConfigkey); |
|
| 97 | - |
|
| 98 | - $result = array(); |
|
| 99 | - foreach($keys as $key) { |
|
| 100 | - $len = strlen($key) - strlen($referenceConfigkey); |
|
| 101 | - $prefix = substr($key, 0, $len); |
|
| 102 | - $result[$prefix] = $this->config->getAppValue('user_ldap', $key); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - return $result; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * return the next available configuration prefix |
|
| 110 | - * |
|
| 111 | - * @return string |
|
| 112 | - */ |
|
| 113 | - public function getNextServerConfigurationPrefix() { |
|
| 114 | - $serverConnections = $this->getServerConfigurationPrefixes(); |
|
| 115 | - |
|
| 116 | - if(count($serverConnections) === 0) { |
|
| 117 | - return 's01'; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - sort($serverConnections); |
|
| 121 | - $lastKey = array_pop($serverConnections); |
|
| 122 | - $lastNumber = intval(str_replace('s', '', $lastKey)); |
|
| 123 | - $nextPrefix = 's' . str_pad($lastNumber + 1, 2, '0', STR_PAD_LEFT); |
|
| 124 | - return $nextPrefix; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - private function getServersConfig($value) { |
|
| 128 | - $regex = '/' . $value . '$/S'; |
|
| 129 | - |
|
| 130 | - $keys = $this->config->getAppKeys('user_ldap'); |
|
| 131 | - $result = []; |
|
| 132 | - foreach ($keys as $key) { |
|
| 133 | - if (preg_match($regex, $key) === 1) { |
|
| 134 | - $result[] = $key; |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - return $result; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * deletes a given saved LDAP/AD server configuration. |
|
| 143 | - * @param string $prefix the configuration prefix of the config to delete |
|
| 144 | - * @return bool true on success, false otherwise |
|
| 145 | - */ |
|
| 146 | - public function deleteServerConfiguration($prefix) { |
|
| 147 | - if(!in_array($prefix, self::getServerConfigurationPrefixes())) { |
|
| 148 | - return false; |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - $saveOtherConfigurations = ''; |
|
| 152 | - if(empty($prefix)) { |
|
| 153 | - $saveOtherConfigurations = 'AND `configkey` NOT LIKE \'s%\''; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - $query = \OCP\DB::prepare(' |
|
| 37 | + /** @var IConfig */ |
|
| 38 | + private $config; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * Helper constructor. |
|
| 42 | + * |
|
| 43 | + * @param IConfig $config |
|
| 44 | + */ |
|
| 45 | + public function __construct(IConfig $config) { |
|
| 46 | + $this->config = $config; |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * returns prefixes for each saved LDAP/AD server configuration. |
|
| 51 | + * @param bool $activeConfigurations optional, whether only active configuration shall be |
|
| 52 | + * retrieved, defaults to false |
|
| 53 | + * @return array with a list of the available prefixes |
|
| 54 | + * |
|
| 55 | + * Configuration prefixes are used to set up configurations for n LDAP or |
|
| 56 | + * AD servers. Since configuration is stored in the database, table |
|
| 57 | + * appconfig under appid user_ldap, the common identifiers in column |
|
| 58 | + * 'configkey' have a prefix. The prefix for the very first server |
|
| 59 | + * configuration is empty. |
|
| 60 | + * Configkey Examples: |
|
| 61 | + * Server 1: ldap_login_filter |
|
| 62 | + * Server 2: s1_ldap_login_filter |
|
| 63 | + * Server 3: s2_ldap_login_filter |
|
| 64 | + * |
|
| 65 | + * The prefix needs to be passed to the constructor of Connection class, |
|
| 66 | + * except the default (first) server shall be connected to. |
|
| 67 | + * |
|
| 68 | + */ |
|
| 69 | + public function getServerConfigurationPrefixes($activeConfigurations = false) { |
|
| 70 | + $referenceConfigkey = 'ldap_configuration_active'; |
|
| 71 | + |
|
| 72 | + $keys = $this->getServersConfig($referenceConfigkey); |
|
| 73 | + |
|
| 74 | + $prefixes = []; |
|
| 75 | + foreach ($keys as $key) { |
|
| 76 | + if ($activeConfigurations && $this->config->getAppValue('user_ldap', $key, '0') !== '1') { |
|
| 77 | + continue; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + $len = strlen($key) - strlen($referenceConfigkey); |
|
| 81 | + $prefixes[] = substr($key, 0, $len); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + return $prefixes; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * |
|
| 89 | + * determines the host for every configured connection |
|
| 90 | + * @return array an array with configprefix as keys |
|
| 91 | + * |
|
| 92 | + */ |
|
| 93 | + public function getServerConfigurationHosts() { |
|
| 94 | + $referenceConfigkey = 'ldap_host'; |
|
| 95 | + |
|
| 96 | + $keys = $this->getServersConfig($referenceConfigkey); |
|
| 97 | + |
|
| 98 | + $result = array(); |
|
| 99 | + foreach($keys as $key) { |
|
| 100 | + $len = strlen($key) - strlen($referenceConfigkey); |
|
| 101 | + $prefix = substr($key, 0, $len); |
|
| 102 | + $result[$prefix] = $this->config->getAppValue('user_ldap', $key); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + return $result; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * return the next available configuration prefix |
|
| 110 | + * |
|
| 111 | + * @return string |
|
| 112 | + */ |
|
| 113 | + public function getNextServerConfigurationPrefix() { |
|
| 114 | + $serverConnections = $this->getServerConfigurationPrefixes(); |
|
| 115 | + |
|
| 116 | + if(count($serverConnections) === 0) { |
|
| 117 | + return 's01'; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + sort($serverConnections); |
|
| 121 | + $lastKey = array_pop($serverConnections); |
|
| 122 | + $lastNumber = intval(str_replace('s', '', $lastKey)); |
|
| 123 | + $nextPrefix = 's' . str_pad($lastNumber + 1, 2, '0', STR_PAD_LEFT); |
|
| 124 | + return $nextPrefix; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + private function getServersConfig($value) { |
|
| 128 | + $regex = '/' . $value . '$/S'; |
|
| 129 | + |
|
| 130 | + $keys = $this->config->getAppKeys('user_ldap'); |
|
| 131 | + $result = []; |
|
| 132 | + foreach ($keys as $key) { |
|
| 133 | + if (preg_match($regex, $key) === 1) { |
|
| 134 | + $result[] = $key; |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + return $result; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * deletes a given saved LDAP/AD server configuration. |
|
| 143 | + * @param string $prefix the configuration prefix of the config to delete |
|
| 144 | + * @return bool true on success, false otherwise |
|
| 145 | + */ |
|
| 146 | + public function deleteServerConfiguration($prefix) { |
|
| 147 | + if(!in_array($prefix, self::getServerConfigurationPrefixes())) { |
|
| 148 | + return false; |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + $saveOtherConfigurations = ''; |
|
| 152 | + if(empty($prefix)) { |
|
| 153 | + $saveOtherConfigurations = 'AND `configkey` NOT LIKE \'s%\''; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + $query = \OCP\DB::prepare(' |
|
| 157 | 157 | DELETE |
| 158 | 158 | FROM `*PREFIX*appconfig` |
| 159 | 159 | WHERE `configkey` LIKE ? |
@@ -161,147 +161,147 @@ discard block |
||
| 161 | 161 | AND `appid` = \'user_ldap\' |
| 162 | 162 | AND `configkey` NOT IN (\'enabled\', \'installed_version\', \'types\', \'bgjUpdateGroupsLastRun\') |
| 163 | 163 | '); |
| 164 | - $delRows = $query->execute(array($prefix.'%')); |
|
| 165 | - |
|
| 166 | - if(\OCP\DB::isError($delRows)) { |
|
| 167 | - return false; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - if($delRows === 0) { |
|
| 171 | - return false; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - return true; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * checks whether there is one or more disabled LDAP configurations |
|
| 179 | - * @throws \Exception |
|
| 180 | - * @return bool |
|
| 181 | - */ |
|
| 182 | - public function haveDisabledConfigurations() { |
|
| 183 | - $all = $this->getServerConfigurationPrefixes(false); |
|
| 184 | - $active = $this->getServerConfigurationPrefixes(true); |
|
| 185 | - |
|
| 186 | - if(!is_array($all) || !is_array($active)) { |
|
| 187 | - throw new \Exception('Unexpected Return Value'); |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - return count($all) !== count($active) || count($all) === 0; |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * extracts the domain from a given URL |
|
| 195 | - * @param string $url the URL |
|
| 196 | - * @return string|false domain as string on success, false otherwise |
|
| 197 | - */ |
|
| 198 | - public function getDomainFromURL($url) { |
|
| 199 | - $uinfo = parse_url($url); |
|
| 200 | - if(!is_array($uinfo)) { |
|
| 201 | - return false; |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - $domain = false; |
|
| 205 | - if(isset($uinfo['host'])) { |
|
| 206 | - $domain = $uinfo['host']; |
|
| 207 | - } else if(isset($uinfo['path'])) { |
|
| 208 | - $domain = $uinfo['path']; |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - return $domain; |
|
| 212 | - } |
|
| 164 | + $delRows = $query->execute(array($prefix.'%')); |
|
| 165 | + |
|
| 166 | + if(\OCP\DB::isError($delRows)) { |
|
| 167 | + return false; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + if($delRows === 0) { |
|
| 171 | + return false; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + return true; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * checks whether there is one or more disabled LDAP configurations |
|
| 179 | + * @throws \Exception |
|
| 180 | + * @return bool |
|
| 181 | + */ |
|
| 182 | + public function haveDisabledConfigurations() { |
|
| 183 | + $all = $this->getServerConfigurationPrefixes(false); |
|
| 184 | + $active = $this->getServerConfigurationPrefixes(true); |
|
| 185 | + |
|
| 186 | + if(!is_array($all) || !is_array($active)) { |
|
| 187 | + throw new \Exception('Unexpected Return Value'); |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + return count($all) !== count($active) || count($all) === 0; |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * extracts the domain from a given URL |
|
| 195 | + * @param string $url the URL |
|
| 196 | + * @return string|false domain as string on success, false otherwise |
|
| 197 | + */ |
|
| 198 | + public function getDomainFromURL($url) { |
|
| 199 | + $uinfo = parse_url($url); |
|
| 200 | + if(!is_array($uinfo)) { |
|
| 201 | + return false; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + $domain = false; |
|
| 205 | + if(isset($uinfo['host'])) { |
|
| 206 | + $domain = $uinfo['host']; |
|
| 207 | + } else if(isset($uinfo['path'])) { |
|
| 208 | + $domain = $uinfo['path']; |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + return $domain; |
|
| 212 | + } |
|
| 213 | 213 | |
| 214 | - /** |
|
| 215 | - * |
|
| 216 | - * Set the LDAPProvider in the config |
|
| 217 | - * |
|
| 218 | - */ |
|
| 219 | - public function setLDAPProvider() { |
|
| 220 | - $current = \OC::$server->getConfig()->getSystemValue('ldapProviderFactory', null); |
|
| 221 | - if(is_null($current)) { |
|
| 222 | - \OC::$server->getConfig()->setSystemValue('ldapProviderFactory', '\\OCA\\User_LDAP\\LDAPProviderFactory'); |
|
| 223 | - } |
|
| 224 | - } |
|
| 214 | + /** |
|
| 215 | + * |
|
| 216 | + * Set the LDAPProvider in the config |
|
| 217 | + * |
|
| 218 | + */ |
|
| 219 | + public function setLDAPProvider() { |
|
| 220 | + $current = \OC::$server->getConfig()->getSystemValue('ldapProviderFactory', null); |
|
| 221 | + if(is_null($current)) { |
|
| 222 | + \OC::$server->getConfig()->setSystemValue('ldapProviderFactory', '\\OCA\\User_LDAP\\LDAPProviderFactory'); |
|
| 223 | + } |
|
| 224 | + } |
|
| 225 | 225 | |
| 226 | - /** |
|
| 227 | - * sanitizes a DN received from the LDAP server |
|
| 228 | - * @param array $dn the DN in question |
|
| 229 | - * @return array the sanitized DN |
|
| 230 | - */ |
|
| 231 | - public function sanitizeDN($dn) { |
|
| 232 | - //treating multiple base DNs |
|
| 233 | - if(is_array($dn)) { |
|
| 234 | - $result = array(); |
|
| 235 | - foreach($dn as $singleDN) { |
|
| 236 | - $result[] = $this->sanitizeDN($singleDN); |
|
| 237 | - } |
|
| 238 | - return $result; |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - //OID sometimes gives back DNs with whitespace after the comma |
|
| 242 | - // a la "uid=foo, cn=bar, dn=..." We need to tackle this! |
|
| 243 | - $dn = preg_replace('/([^\\\]),(\s+)/u', '\1,', $dn); |
|
| 244 | - |
|
| 245 | - //make comparisons and everything work |
|
| 246 | - $dn = mb_strtolower($dn, 'UTF-8'); |
|
| 247 | - |
|
| 248 | - //escape DN values according to RFC 2253 – this is already done by ldap_explode_dn |
|
| 249 | - //to use the DN in search filters, \ needs to be escaped to \5c additionally |
|
| 250 | - //to use them in bases, we convert them back to simple backslashes in readAttribute() |
|
| 251 | - $replacements = array( |
|
| 252 | - '\,' => '\5c2C', |
|
| 253 | - '\=' => '\5c3D', |
|
| 254 | - '\+' => '\5c2B', |
|
| 255 | - '\<' => '\5c3C', |
|
| 256 | - '\>' => '\5c3E', |
|
| 257 | - '\;' => '\5c3B', |
|
| 258 | - '\"' => '\5c22', |
|
| 259 | - '\#' => '\5c23', |
|
| 260 | - '(' => '\28', |
|
| 261 | - ')' => '\29', |
|
| 262 | - '*' => '\2A', |
|
| 263 | - ); |
|
| 264 | - $dn = str_replace(array_keys($replacements), array_values($replacements), $dn); |
|
| 265 | - |
|
| 266 | - return $dn; |
|
| 267 | - } |
|
| 226 | + /** |
|
| 227 | + * sanitizes a DN received from the LDAP server |
|
| 228 | + * @param array $dn the DN in question |
|
| 229 | + * @return array the sanitized DN |
|
| 230 | + */ |
|
| 231 | + public function sanitizeDN($dn) { |
|
| 232 | + //treating multiple base DNs |
|
| 233 | + if(is_array($dn)) { |
|
| 234 | + $result = array(); |
|
| 235 | + foreach($dn as $singleDN) { |
|
| 236 | + $result[] = $this->sanitizeDN($singleDN); |
|
| 237 | + } |
|
| 238 | + return $result; |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + //OID sometimes gives back DNs with whitespace after the comma |
|
| 242 | + // a la "uid=foo, cn=bar, dn=..." We need to tackle this! |
|
| 243 | + $dn = preg_replace('/([^\\\]),(\s+)/u', '\1,', $dn); |
|
| 244 | + |
|
| 245 | + //make comparisons and everything work |
|
| 246 | + $dn = mb_strtolower($dn, 'UTF-8'); |
|
| 247 | + |
|
| 248 | + //escape DN values according to RFC 2253 – this is already done by ldap_explode_dn |
|
| 249 | + //to use the DN in search filters, \ needs to be escaped to \5c additionally |
|
| 250 | + //to use them in bases, we convert them back to simple backslashes in readAttribute() |
|
| 251 | + $replacements = array( |
|
| 252 | + '\,' => '\5c2C', |
|
| 253 | + '\=' => '\5c3D', |
|
| 254 | + '\+' => '\5c2B', |
|
| 255 | + '\<' => '\5c3C', |
|
| 256 | + '\>' => '\5c3E', |
|
| 257 | + '\;' => '\5c3B', |
|
| 258 | + '\"' => '\5c22', |
|
| 259 | + '\#' => '\5c23', |
|
| 260 | + '(' => '\28', |
|
| 261 | + ')' => '\29', |
|
| 262 | + '*' => '\2A', |
|
| 263 | + ); |
|
| 264 | + $dn = str_replace(array_keys($replacements), array_values($replacements), $dn); |
|
| 265 | + |
|
| 266 | + return $dn; |
|
| 267 | + } |
|
| 268 | 268 | |
| 269 | - /** |
|
| 270 | - * converts a stored DN so it can be used as base parameter for LDAP queries, internally we store them for usage in LDAP filters |
|
| 271 | - * @param string $dn the DN |
|
| 272 | - * @return string |
|
| 273 | - */ |
|
| 274 | - public function DNasBaseParameter($dn) { |
|
| 275 | - return str_ireplace('\\5c', '\\', $dn); |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - /** |
|
| 279 | - * listens to a hook thrown by server2server sharing and replaces the given |
|
| 280 | - * login name by a username, if it matches an LDAP user. |
|
| 281 | - * |
|
| 282 | - * @param array $param |
|
| 283 | - * @throws \Exception |
|
| 284 | - */ |
|
| 285 | - public static function loginName2UserName($param) { |
|
| 286 | - if(!isset($param['uid'])) { |
|
| 287 | - throw new \Exception('key uid is expected to be set in $param'); |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - //ain't it ironic? |
|
| 291 | - $helper = new Helper(\OC::$server->getConfig()); |
|
| 292 | - |
|
| 293 | - $configPrefixes = $helper->getServerConfigurationPrefixes(true); |
|
| 294 | - $ldapWrapper = new LDAP(); |
|
| 295 | - $ocConfig = \OC::$server->getConfig(); |
|
| 296 | - $notificationManager = \OC::$server->getNotificationManager(); |
|
| 297 | - $userSession = \OC::$server->getUserSession(); |
|
| 298 | - |
|
| 299 | - $userBackend = new User_Proxy( |
|
| 300 | - $configPrefixes, $ldapWrapper, $ocConfig, $notificationManager, $userSession |
|
| 301 | - ); |
|
| 302 | - $uid = $userBackend->loginName2UserName($param['uid'] ); |
|
| 303 | - if($uid !== false) { |
|
| 304 | - $param['uid'] = $uid; |
|
| 305 | - } |
|
| 306 | - } |
|
| 269 | + /** |
|
| 270 | + * converts a stored DN so it can be used as base parameter for LDAP queries, internally we store them for usage in LDAP filters |
|
| 271 | + * @param string $dn the DN |
|
| 272 | + * @return string |
|
| 273 | + */ |
|
| 274 | + public function DNasBaseParameter($dn) { |
|
| 275 | + return str_ireplace('\\5c', '\\', $dn); |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + /** |
|
| 279 | + * listens to a hook thrown by server2server sharing and replaces the given |
|
| 280 | + * login name by a username, if it matches an LDAP user. |
|
| 281 | + * |
|
| 282 | + * @param array $param |
|
| 283 | + * @throws \Exception |
|
| 284 | + */ |
|
| 285 | + public static function loginName2UserName($param) { |
|
| 286 | + if(!isset($param['uid'])) { |
|
| 287 | + throw new \Exception('key uid is expected to be set in $param'); |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + //ain't it ironic? |
|
| 291 | + $helper = new Helper(\OC::$server->getConfig()); |
|
| 292 | + |
|
| 293 | + $configPrefixes = $helper->getServerConfigurationPrefixes(true); |
|
| 294 | + $ldapWrapper = new LDAP(); |
|
| 295 | + $ocConfig = \OC::$server->getConfig(); |
|
| 296 | + $notificationManager = \OC::$server->getNotificationManager(); |
|
| 297 | + $userSession = \OC::$server->getUserSession(); |
|
| 298 | + |
|
| 299 | + $userBackend = new User_Proxy( |
|
| 300 | + $configPrefixes, $ldapWrapper, $ocConfig, $notificationManager, $userSession |
|
| 301 | + ); |
|
| 302 | + $uid = $userBackend->loginName2UserName($param['uid'] ); |
|
| 303 | + if($uid !== false) { |
|
| 304 | + $param['uid'] = $uid; |
|
| 305 | + } |
|
| 306 | + } |
|
| 307 | 307 | } |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | $keys = $this->getServersConfig($referenceConfigkey); |
| 97 | 97 | |
| 98 | 98 | $result = array(); |
| 99 | - foreach($keys as $key) { |
|
| 99 | + foreach ($keys as $key) { |
|
| 100 | 100 | $len = strlen($key) - strlen($referenceConfigkey); |
| 101 | 101 | $prefix = substr($key, 0, $len); |
| 102 | 102 | $result[$prefix] = $this->config->getAppValue('user_ldap', $key); |
@@ -113,19 +113,19 @@ discard block |
||
| 113 | 113 | public function getNextServerConfigurationPrefix() { |
| 114 | 114 | $serverConnections = $this->getServerConfigurationPrefixes(); |
| 115 | 115 | |
| 116 | - if(count($serverConnections) === 0) { |
|
| 116 | + if (count($serverConnections) === 0) { |
|
| 117 | 117 | return 's01'; |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | sort($serverConnections); |
| 121 | 121 | $lastKey = array_pop($serverConnections); |
| 122 | 122 | $lastNumber = intval(str_replace('s', '', $lastKey)); |
| 123 | - $nextPrefix = 's' . str_pad($lastNumber + 1, 2, '0', STR_PAD_LEFT); |
|
| 123 | + $nextPrefix = 's'.str_pad($lastNumber + 1, 2, '0', STR_PAD_LEFT); |
|
| 124 | 124 | return $nextPrefix; |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | private function getServersConfig($value) { |
| 128 | - $regex = '/' . $value . '$/S'; |
|
| 128 | + $regex = '/'.$value.'$/S'; |
|
| 129 | 129 | |
| 130 | 130 | $keys = $this->config->getAppKeys('user_ldap'); |
| 131 | 131 | $result = []; |
@@ -144,12 +144,12 @@ discard block |
||
| 144 | 144 | * @return bool true on success, false otherwise |
| 145 | 145 | */ |
| 146 | 146 | public function deleteServerConfiguration($prefix) { |
| 147 | - if(!in_array($prefix, self::getServerConfigurationPrefixes())) { |
|
| 147 | + if (!in_array($prefix, self::getServerConfigurationPrefixes())) { |
|
| 148 | 148 | return false; |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | $saveOtherConfigurations = ''; |
| 152 | - if(empty($prefix)) { |
|
| 152 | + if (empty($prefix)) { |
|
| 153 | 153 | $saveOtherConfigurations = 'AND `configkey` NOT LIKE \'s%\''; |
| 154 | 154 | } |
| 155 | 155 | |
@@ -163,11 +163,11 @@ discard block |
||
| 163 | 163 | '); |
| 164 | 164 | $delRows = $query->execute(array($prefix.'%')); |
| 165 | 165 | |
| 166 | - if(\OCP\DB::isError($delRows)) { |
|
| 166 | + if (\OCP\DB::isError($delRows)) { |
|
| 167 | 167 | return false; |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | - if($delRows === 0) { |
|
| 170 | + if ($delRows === 0) { |
|
| 171 | 171 | return false; |
| 172 | 172 | } |
| 173 | 173 | |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | $all = $this->getServerConfigurationPrefixes(false); |
| 184 | 184 | $active = $this->getServerConfigurationPrefixes(true); |
| 185 | 185 | |
| 186 | - if(!is_array($all) || !is_array($active)) { |
|
| 186 | + if (!is_array($all) || !is_array($active)) { |
|
| 187 | 187 | throw new \Exception('Unexpected Return Value'); |
| 188 | 188 | } |
| 189 | 189 | |
@@ -197,14 +197,14 @@ discard block |
||
| 197 | 197 | */ |
| 198 | 198 | public function getDomainFromURL($url) { |
| 199 | 199 | $uinfo = parse_url($url); |
| 200 | - if(!is_array($uinfo)) { |
|
| 200 | + if (!is_array($uinfo)) { |
|
| 201 | 201 | return false; |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | $domain = false; |
| 205 | - if(isset($uinfo['host'])) { |
|
| 205 | + if (isset($uinfo['host'])) { |
|
| 206 | 206 | $domain = $uinfo['host']; |
| 207 | - } else if(isset($uinfo['path'])) { |
|
| 207 | + } else if (isset($uinfo['path'])) { |
|
| 208 | 208 | $domain = $uinfo['path']; |
| 209 | 209 | } |
| 210 | 210 | |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | */ |
| 219 | 219 | public function setLDAPProvider() { |
| 220 | 220 | $current = \OC::$server->getConfig()->getSystemValue('ldapProviderFactory', null); |
| 221 | - if(is_null($current)) { |
|
| 221 | + if (is_null($current)) { |
|
| 222 | 222 | \OC::$server->getConfig()->setSystemValue('ldapProviderFactory', '\\OCA\\User_LDAP\\LDAPProviderFactory'); |
| 223 | 223 | } |
| 224 | 224 | } |
@@ -230,9 +230,9 @@ discard block |
||
| 230 | 230 | */ |
| 231 | 231 | public function sanitizeDN($dn) { |
| 232 | 232 | //treating multiple base DNs |
| 233 | - if(is_array($dn)) { |
|
| 233 | + if (is_array($dn)) { |
|
| 234 | 234 | $result = array(); |
| 235 | - foreach($dn as $singleDN) { |
|
| 235 | + foreach ($dn as $singleDN) { |
|
| 236 | 236 | $result[] = $this->sanitizeDN($singleDN); |
| 237 | 237 | } |
| 238 | 238 | return $result; |
@@ -283,7 +283,7 @@ discard block |
||
| 283 | 283 | * @throws \Exception |
| 284 | 284 | */ |
| 285 | 285 | public static function loginName2UserName($param) { |
| 286 | - if(!isset($param['uid'])) { |
|
| 286 | + if (!isset($param['uid'])) { |
|
| 287 | 287 | throw new \Exception('key uid is expected to be set in $param'); |
| 288 | 288 | } |
| 289 | 289 | |
@@ -296,11 +296,11 @@ discard block |
||
| 296 | 296 | $notificationManager = \OC::$server->getNotificationManager(); |
| 297 | 297 | $userSession = \OC::$server->getUserSession(); |
| 298 | 298 | |
| 299 | - $userBackend = new User_Proxy( |
|
| 299 | + $userBackend = new User_Proxy( |
|
| 300 | 300 | $configPrefixes, $ldapWrapper, $ocConfig, $notificationManager, $userSession |
| 301 | 301 | ); |
| 302 | - $uid = $userBackend->loginName2UserName($param['uid'] ); |
|
| 303 | - if($uid !== false) { |
|
| 302 | + $uid = $userBackend->loginName2UserName($param['uid']); |
|
| 303 | + if ($uid !== false) { |
|
| 304 | 304 | $param['uid'] = $uid; |
| 305 | 305 | } |
| 306 | 306 | } |
@@ -35,291 +35,291 @@ |
||
| 35 | 35 | use OCP\Notification\IManager as INotificationManager; |
| 36 | 36 | |
| 37 | 37 | class User_Proxy extends Proxy implements \OCP\IUserBackend, \OCP\UserInterface, IUserLDAP { |
| 38 | - private $backends = array(); |
|
| 39 | - private $refBackend = null; |
|
| 38 | + private $backends = array(); |
|
| 39 | + private $refBackend = null; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Constructor |
|
| 43 | - * |
|
| 44 | - * @param array $serverConfigPrefixes array containing the config Prefixes |
|
| 45 | - * @param ILDAPWrapper $ldap |
|
| 46 | - * @param IConfig $ocConfig |
|
| 47 | - * @param INotificationManager $notificationManager |
|
| 48 | - * @param IUserSession $userSession |
|
| 49 | - */ |
|
| 50 | - public function __construct(array $serverConfigPrefixes, ILDAPWrapper $ldap, IConfig $ocConfig, |
|
| 51 | - INotificationManager $notificationManager, IUserSession $userSession) { |
|
| 52 | - parent::__construct($ldap); |
|
| 53 | - foreach($serverConfigPrefixes as $configPrefix) { |
|
| 54 | - $this->backends[$configPrefix] = |
|
| 55 | - new User_LDAP($this->getAccess($configPrefix), $ocConfig, $notificationManager, $userSession); |
|
| 56 | - if(is_null($this->refBackend)) { |
|
| 57 | - $this->refBackend = &$this->backends[$configPrefix]; |
|
| 58 | - } |
|
| 59 | - } |
|
| 60 | - } |
|
| 41 | + /** |
|
| 42 | + * Constructor |
|
| 43 | + * |
|
| 44 | + * @param array $serverConfigPrefixes array containing the config Prefixes |
|
| 45 | + * @param ILDAPWrapper $ldap |
|
| 46 | + * @param IConfig $ocConfig |
|
| 47 | + * @param INotificationManager $notificationManager |
|
| 48 | + * @param IUserSession $userSession |
|
| 49 | + */ |
|
| 50 | + public function __construct(array $serverConfigPrefixes, ILDAPWrapper $ldap, IConfig $ocConfig, |
|
| 51 | + INotificationManager $notificationManager, IUserSession $userSession) { |
|
| 52 | + parent::__construct($ldap); |
|
| 53 | + foreach($serverConfigPrefixes as $configPrefix) { |
|
| 54 | + $this->backends[$configPrefix] = |
|
| 55 | + new User_LDAP($this->getAccess($configPrefix), $ocConfig, $notificationManager, $userSession); |
|
| 56 | + if(is_null($this->refBackend)) { |
|
| 57 | + $this->refBackend = &$this->backends[$configPrefix]; |
|
| 58 | + } |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * Tries the backends one after the other until a positive result is returned from the specified method |
|
| 64 | - * @param string $uid the uid connected to the request |
|
| 65 | - * @param string $method the method of the user backend that shall be called |
|
| 66 | - * @param array $parameters an array of parameters to be passed |
|
| 67 | - * @return mixed the result of the method or false |
|
| 68 | - */ |
|
| 69 | - protected function walkBackends($uid, $method, $parameters) { |
|
| 70 | - $cacheKey = $this->getUserCacheKey($uid); |
|
| 71 | - foreach($this->backends as $configPrefix => $backend) { |
|
| 72 | - $instance = $backend; |
|
| 73 | - if(!method_exists($instance, $method) |
|
| 74 | - && method_exists($this->getAccess($configPrefix), $method)) { |
|
| 75 | - $instance = $this->getAccess($configPrefix); |
|
| 76 | - } |
|
| 77 | - if($result = call_user_func_array(array($instance, $method), $parameters)) { |
|
| 78 | - $this->writeToCache($cacheKey, $configPrefix); |
|
| 79 | - return $result; |
|
| 80 | - } |
|
| 81 | - } |
|
| 82 | - return false; |
|
| 83 | - } |
|
| 62 | + /** |
|
| 63 | + * Tries the backends one after the other until a positive result is returned from the specified method |
|
| 64 | + * @param string $uid the uid connected to the request |
|
| 65 | + * @param string $method the method of the user backend that shall be called |
|
| 66 | + * @param array $parameters an array of parameters to be passed |
|
| 67 | + * @return mixed the result of the method or false |
|
| 68 | + */ |
|
| 69 | + protected function walkBackends($uid, $method, $parameters) { |
|
| 70 | + $cacheKey = $this->getUserCacheKey($uid); |
|
| 71 | + foreach($this->backends as $configPrefix => $backend) { |
|
| 72 | + $instance = $backend; |
|
| 73 | + if(!method_exists($instance, $method) |
|
| 74 | + && method_exists($this->getAccess($configPrefix), $method)) { |
|
| 75 | + $instance = $this->getAccess($configPrefix); |
|
| 76 | + } |
|
| 77 | + if($result = call_user_func_array(array($instance, $method), $parameters)) { |
|
| 78 | + $this->writeToCache($cacheKey, $configPrefix); |
|
| 79 | + return $result; |
|
| 80 | + } |
|
| 81 | + } |
|
| 82 | + return false; |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * Asks the backend connected to the server that supposely takes care of the uid from the request. |
|
| 87 | - * @param string $uid the uid connected to the request |
|
| 88 | - * @param string $method the method of the user backend that shall be called |
|
| 89 | - * @param array $parameters an array of parameters to be passed |
|
| 90 | - * @param mixed $passOnWhen the result matches this variable |
|
| 91 | - * @return mixed the result of the method or false |
|
| 92 | - */ |
|
| 93 | - protected function callOnLastSeenOn($uid, $method, $parameters, $passOnWhen) { |
|
| 94 | - $cacheKey = $this->getUserCacheKey($uid); |
|
| 95 | - $prefix = $this->getFromCache($cacheKey); |
|
| 96 | - //in case the uid has been found in the past, try this stored connection first |
|
| 97 | - if(!is_null($prefix)) { |
|
| 98 | - if(isset($this->backends[$prefix])) { |
|
| 99 | - $instance = $this->backends[$prefix]; |
|
| 100 | - if(!method_exists($instance, $method) |
|
| 101 | - && method_exists($this->getAccess($prefix), $method)) { |
|
| 102 | - $instance = $this->getAccess($prefix); |
|
| 103 | - } |
|
| 104 | - $result = call_user_func_array(array($instance, $method), $parameters); |
|
| 105 | - if($result === $passOnWhen) { |
|
| 106 | - //not found here, reset cache to null if user vanished |
|
| 107 | - //because sometimes methods return false with a reason |
|
| 108 | - $userExists = call_user_func_array( |
|
| 109 | - array($this->backends[$prefix], 'userExists'), |
|
| 110 | - array($uid) |
|
| 111 | - ); |
|
| 112 | - if(!$userExists) { |
|
| 113 | - $this->writeToCache($cacheKey, null); |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - return $result; |
|
| 117 | - } |
|
| 118 | - } |
|
| 119 | - return false; |
|
| 120 | - } |
|
| 85 | + /** |
|
| 86 | + * Asks the backend connected to the server that supposely takes care of the uid from the request. |
|
| 87 | + * @param string $uid the uid connected to the request |
|
| 88 | + * @param string $method the method of the user backend that shall be called |
|
| 89 | + * @param array $parameters an array of parameters to be passed |
|
| 90 | + * @param mixed $passOnWhen the result matches this variable |
|
| 91 | + * @return mixed the result of the method or false |
|
| 92 | + */ |
|
| 93 | + protected function callOnLastSeenOn($uid, $method, $parameters, $passOnWhen) { |
|
| 94 | + $cacheKey = $this->getUserCacheKey($uid); |
|
| 95 | + $prefix = $this->getFromCache($cacheKey); |
|
| 96 | + //in case the uid has been found in the past, try this stored connection first |
|
| 97 | + if(!is_null($prefix)) { |
|
| 98 | + if(isset($this->backends[$prefix])) { |
|
| 99 | + $instance = $this->backends[$prefix]; |
|
| 100 | + if(!method_exists($instance, $method) |
|
| 101 | + && method_exists($this->getAccess($prefix), $method)) { |
|
| 102 | + $instance = $this->getAccess($prefix); |
|
| 103 | + } |
|
| 104 | + $result = call_user_func_array(array($instance, $method), $parameters); |
|
| 105 | + if($result === $passOnWhen) { |
|
| 106 | + //not found here, reset cache to null if user vanished |
|
| 107 | + //because sometimes methods return false with a reason |
|
| 108 | + $userExists = call_user_func_array( |
|
| 109 | + array($this->backends[$prefix], 'userExists'), |
|
| 110 | + array($uid) |
|
| 111 | + ); |
|
| 112 | + if(!$userExists) { |
|
| 113 | + $this->writeToCache($cacheKey, null); |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | + return $result; |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | + return false; |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - /** |
|
| 123 | - * Check if backend implements actions |
|
| 124 | - * @param int $actions bitwise-or'ed actions |
|
| 125 | - * @return boolean |
|
| 126 | - * |
|
| 127 | - * Returns the supported actions as int to be |
|
| 128 | - * compared with \OC\User\Backend::CREATE_USER etc. |
|
| 129 | - */ |
|
| 130 | - public function implementsActions($actions) { |
|
| 131 | - //it's the same across all our user backends obviously |
|
| 132 | - return $this->refBackend->implementsActions($actions); |
|
| 133 | - } |
|
| 122 | + /** |
|
| 123 | + * Check if backend implements actions |
|
| 124 | + * @param int $actions bitwise-or'ed actions |
|
| 125 | + * @return boolean |
|
| 126 | + * |
|
| 127 | + * Returns the supported actions as int to be |
|
| 128 | + * compared with \OC\User\Backend::CREATE_USER etc. |
|
| 129 | + */ |
|
| 130 | + public function implementsActions($actions) { |
|
| 131 | + //it's the same across all our user backends obviously |
|
| 132 | + return $this->refBackend->implementsActions($actions); |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | - /** |
|
| 136 | - * Backend name to be shown in user management |
|
| 137 | - * @return string the name of the backend to be shown |
|
| 138 | - */ |
|
| 139 | - public function getBackendName() { |
|
| 140 | - return $this->refBackend->getBackendName(); |
|
| 141 | - } |
|
| 135 | + /** |
|
| 136 | + * Backend name to be shown in user management |
|
| 137 | + * @return string the name of the backend to be shown |
|
| 138 | + */ |
|
| 139 | + public function getBackendName() { |
|
| 140 | + return $this->refBackend->getBackendName(); |
|
| 141 | + } |
|
| 142 | 142 | |
| 143 | - /** |
|
| 144 | - * Get a list of all users |
|
| 145 | - * |
|
| 146 | - * @param string $search |
|
| 147 | - * @param null|int $limit |
|
| 148 | - * @param null|int $offset |
|
| 149 | - * @return string[] an array of all uids |
|
| 150 | - */ |
|
| 151 | - public function getUsers($search = '', $limit = 10, $offset = 0) { |
|
| 152 | - //we do it just as the /OC_User implementation: do not play around with limit and offset but ask all backends |
|
| 153 | - $users = array(); |
|
| 154 | - foreach($this->backends as $backend) { |
|
| 155 | - $backendUsers = $backend->getUsers($search, $limit, $offset); |
|
| 156 | - if (is_array($backendUsers)) { |
|
| 157 | - $users = array_merge($users, $backendUsers); |
|
| 158 | - } |
|
| 159 | - } |
|
| 160 | - return $users; |
|
| 161 | - } |
|
| 143 | + /** |
|
| 144 | + * Get a list of all users |
|
| 145 | + * |
|
| 146 | + * @param string $search |
|
| 147 | + * @param null|int $limit |
|
| 148 | + * @param null|int $offset |
|
| 149 | + * @return string[] an array of all uids |
|
| 150 | + */ |
|
| 151 | + public function getUsers($search = '', $limit = 10, $offset = 0) { |
|
| 152 | + //we do it just as the /OC_User implementation: do not play around with limit and offset but ask all backends |
|
| 153 | + $users = array(); |
|
| 154 | + foreach($this->backends as $backend) { |
|
| 155 | + $backendUsers = $backend->getUsers($search, $limit, $offset); |
|
| 156 | + if (is_array($backendUsers)) { |
|
| 157 | + $users = array_merge($users, $backendUsers); |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | + return $users; |
|
| 161 | + } |
|
| 162 | 162 | |
| 163 | - /** |
|
| 164 | - * check if a user exists |
|
| 165 | - * @param string $uid the username |
|
| 166 | - * @return boolean |
|
| 167 | - */ |
|
| 168 | - public function userExists($uid) { |
|
| 169 | - return $this->handleRequest($uid, 'userExists', array($uid)); |
|
| 170 | - } |
|
| 163 | + /** |
|
| 164 | + * check if a user exists |
|
| 165 | + * @param string $uid the username |
|
| 166 | + * @return boolean |
|
| 167 | + */ |
|
| 168 | + public function userExists($uid) { |
|
| 169 | + return $this->handleRequest($uid, 'userExists', array($uid)); |
|
| 170 | + } |
|
| 171 | 171 | |
| 172 | - /** |
|
| 173 | - * check if a user exists on LDAP |
|
| 174 | - * @param string|\OCA\User_LDAP\User\User $user either the Nextcloud user |
|
| 175 | - * name or an instance of that user |
|
| 176 | - * @return boolean |
|
| 177 | - */ |
|
| 178 | - public function userExistsOnLDAP($user) { |
|
| 179 | - $id = ($user instanceof User) ? $user->getUsername() : $user; |
|
| 180 | - return $this->handleRequest($id, 'userExistsOnLDAP', array($user)); |
|
| 181 | - } |
|
| 172 | + /** |
|
| 173 | + * check if a user exists on LDAP |
|
| 174 | + * @param string|\OCA\User_LDAP\User\User $user either the Nextcloud user |
|
| 175 | + * name or an instance of that user |
|
| 176 | + * @return boolean |
|
| 177 | + */ |
|
| 178 | + public function userExistsOnLDAP($user) { |
|
| 179 | + $id = ($user instanceof User) ? $user->getUsername() : $user; |
|
| 180 | + return $this->handleRequest($id, 'userExistsOnLDAP', array($user)); |
|
| 181 | + } |
|
| 182 | 182 | |
| 183 | - /** |
|
| 184 | - * Check if the password is correct |
|
| 185 | - * @param string $uid The username |
|
| 186 | - * @param string $password The password |
|
| 187 | - * @return bool |
|
| 188 | - * |
|
| 189 | - * Check if the password is correct without logging in the user |
|
| 190 | - */ |
|
| 191 | - public function checkPassword($uid, $password) { |
|
| 192 | - return $this->handleRequest($uid, 'checkPassword', array($uid, $password)); |
|
| 193 | - } |
|
| 183 | + /** |
|
| 184 | + * Check if the password is correct |
|
| 185 | + * @param string $uid The username |
|
| 186 | + * @param string $password The password |
|
| 187 | + * @return bool |
|
| 188 | + * |
|
| 189 | + * Check if the password is correct without logging in the user |
|
| 190 | + */ |
|
| 191 | + public function checkPassword($uid, $password) { |
|
| 192 | + return $this->handleRequest($uid, 'checkPassword', array($uid, $password)); |
|
| 193 | + } |
|
| 194 | 194 | |
| 195 | - /** |
|
| 196 | - * returns the username for the given login name, if available |
|
| 197 | - * |
|
| 198 | - * @param string $loginName |
|
| 199 | - * @return string|false |
|
| 200 | - */ |
|
| 201 | - public function loginName2UserName($loginName) { |
|
| 202 | - $id = 'LOGINNAME,' . $loginName; |
|
| 203 | - return $this->handleRequest($id, 'loginName2UserName', array($loginName)); |
|
| 204 | - } |
|
| 195 | + /** |
|
| 196 | + * returns the username for the given login name, if available |
|
| 197 | + * |
|
| 198 | + * @param string $loginName |
|
| 199 | + * @return string|false |
|
| 200 | + */ |
|
| 201 | + public function loginName2UserName($loginName) { |
|
| 202 | + $id = 'LOGINNAME,' . $loginName; |
|
| 203 | + return $this->handleRequest($id, 'loginName2UserName', array($loginName)); |
|
| 204 | + } |
|
| 205 | 205 | |
| 206 | - /** |
|
| 207 | - * returns the username for the given LDAP DN, if available |
|
| 208 | - * |
|
| 209 | - * @param string $dn |
|
| 210 | - * @return string|false with the username |
|
| 211 | - */ |
|
| 212 | - public function dn2UserName($dn) { |
|
| 213 | - $id = 'DN,' . $dn; |
|
| 214 | - return $this->handleRequest($id, 'dn2UserName', array($dn)); |
|
| 215 | - } |
|
| 206 | + /** |
|
| 207 | + * returns the username for the given LDAP DN, if available |
|
| 208 | + * |
|
| 209 | + * @param string $dn |
|
| 210 | + * @return string|false with the username |
|
| 211 | + */ |
|
| 212 | + public function dn2UserName($dn) { |
|
| 213 | + $id = 'DN,' . $dn; |
|
| 214 | + return $this->handleRequest($id, 'dn2UserName', array($dn)); |
|
| 215 | + } |
|
| 216 | 216 | |
| 217 | - /** |
|
| 218 | - * get the user's home directory |
|
| 219 | - * @param string $uid the username |
|
| 220 | - * @return boolean |
|
| 221 | - */ |
|
| 222 | - public function getHome($uid) { |
|
| 223 | - return $this->handleRequest($uid, 'getHome', array($uid)); |
|
| 224 | - } |
|
| 217 | + /** |
|
| 218 | + * get the user's home directory |
|
| 219 | + * @param string $uid the username |
|
| 220 | + * @return boolean |
|
| 221 | + */ |
|
| 222 | + public function getHome($uid) { |
|
| 223 | + return $this->handleRequest($uid, 'getHome', array($uid)); |
|
| 224 | + } |
|
| 225 | 225 | |
| 226 | - /** |
|
| 227 | - * get display name of the user |
|
| 228 | - * @param string $uid user ID of the user |
|
| 229 | - * @return string display name |
|
| 230 | - */ |
|
| 231 | - public function getDisplayName($uid) { |
|
| 232 | - return $this->handleRequest($uid, 'getDisplayName', array($uid)); |
|
| 233 | - } |
|
| 226 | + /** |
|
| 227 | + * get display name of the user |
|
| 228 | + * @param string $uid user ID of the user |
|
| 229 | + * @return string display name |
|
| 230 | + */ |
|
| 231 | + public function getDisplayName($uid) { |
|
| 232 | + return $this->handleRequest($uid, 'getDisplayName', array($uid)); |
|
| 233 | + } |
|
| 234 | 234 | |
| 235 | - /** |
|
| 236 | - * checks whether the user is allowed to change his avatar in Nextcloud |
|
| 237 | - * @param string $uid the Nextcloud user name |
|
| 238 | - * @return boolean either the user can or cannot |
|
| 239 | - */ |
|
| 240 | - public function canChangeAvatar($uid) { |
|
| 241 | - return $this->handleRequest($uid, 'canChangeAvatar', array($uid), true); |
|
| 242 | - } |
|
| 235 | + /** |
|
| 236 | + * checks whether the user is allowed to change his avatar in Nextcloud |
|
| 237 | + * @param string $uid the Nextcloud user name |
|
| 238 | + * @return boolean either the user can or cannot |
|
| 239 | + */ |
|
| 240 | + public function canChangeAvatar($uid) { |
|
| 241 | + return $this->handleRequest($uid, 'canChangeAvatar', array($uid), true); |
|
| 242 | + } |
|
| 243 | 243 | |
| 244 | - /** |
|
| 245 | - * Get a list of all display names and user ids. |
|
| 246 | - * @param string $search |
|
| 247 | - * @param string|null $limit |
|
| 248 | - * @param string|null $offset |
|
| 249 | - * @return array an array of all displayNames (value) and the corresponding uids (key) |
|
| 250 | - */ |
|
| 251 | - public function getDisplayNames($search = '', $limit = null, $offset = null) { |
|
| 252 | - //we do it just as the /OC_User implementation: do not play around with limit and offset but ask all backends |
|
| 253 | - $users = array(); |
|
| 254 | - foreach($this->backends as $backend) { |
|
| 255 | - $backendUsers = $backend->getDisplayNames($search, $limit, $offset); |
|
| 256 | - if (is_array($backendUsers)) { |
|
| 257 | - $users = $users + $backendUsers; |
|
| 258 | - } |
|
| 259 | - } |
|
| 260 | - return $users; |
|
| 261 | - } |
|
| 244 | + /** |
|
| 245 | + * Get a list of all display names and user ids. |
|
| 246 | + * @param string $search |
|
| 247 | + * @param string|null $limit |
|
| 248 | + * @param string|null $offset |
|
| 249 | + * @return array an array of all displayNames (value) and the corresponding uids (key) |
|
| 250 | + */ |
|
| 251 | + public function getDisplayNames($search = '', $limit = null, $offset = null) { |
|
| 252 | + //we do it just as the /OC_User implementation: do not play around with limit and offset but ask all backends |
|
| 253 | + $users = array(); |
|
| 254 | + foreach($this->backends as $backend) { |
|
| 255 | + $backendUsers = $backend->getDisplayNames($search, $limit, $offset); |
|
| 256 | + if (is_array($backendUsers)) { |
|
| 257 | + $users = $users + $backendUsers; |
|
| 258 | + } |
|
| 259 | + } |
|
| 260 | + return $users; |
|
| 261 | + } |
|
| 262 | 262 | |
| 263 | - /** |
|
| 264 | - * delete a user |
|
| 265 | - * @param string $uid The username of the user to delete |
|
| 266 | - * @return bool |
|
| 267 | - * |
|
| 268 | - * Deletes a user |
|
| 269 | - */ |
|
| 270 | - public function deleteUser($uid) { |
|
| 271 | - return $this->handleRequest($uid, 'deleteUser', array($uid)); |
|
| 272 | - } |
|
| 263 | + /** |
|
| 264 | + * delete a user |
|
| 265 | + * @param string $uid The username of the user to delete |
|
| 266 | + * @return bool |
|
| 267 | + * |
|
| 268 | + * Deletes a user |
|
| 269 | + */ |
|
| 270 | + public function deleteUser($uid) { |
|
| 271 | + return $this->handleRequest($uid, 'deleteUser', array($uid)); |
|
| 272 | + } |
|
| 273 | 273 | |
| 274 | - /** |
|
| 275 | - * Set password |
|
| 276 | - * @param string $uid The username |
|
| 277 | - * @param string $password The new password |
|
| 278 | - * @return bool |
|
| 279 | - * |
|
| 280 | - */ |
|
| 281 | - public function setPassword($uid, $password) { |
|
| 282 | - return $this->handleRequest($uid, 'setPassword', array($uid, $password)); |
|
| 283 | - } |
|
| 274 | + /** |
|
| 275 | + * Set password |
|
| 276 | + * @param string $uid The username |
|
| 277 | + * @param string $password The new password |
|
| 278 | + * @return bool |
|
| 279 | + * |
|
| 280 | + */ |
|
| 281 | + public function setPassword($uid, $password) { |
|
| 282 | + return $this->handleRequest($uid, 'setPassword', array($uid, $password)); |
|
| 283 | + } |
|
| 284 | 284 | |
| 285 | - /** |
|
| 286 | - * @return bool |
|
| 287 | - */ |
|
| 288 | - public function hasUserListings() { |
|
| 289 | - return $this->refBackend->hasUserListings(); |
|
| 290 | - } |
|
| 285 | + /** |
|
| 286 | + * @return bool |
|
| 287 | + */ |
|
| 288 | + public function hasUserListings() { |
|
| 289 | + return $this->refBackend->hasUserListings(); |
|
| 290 | + } |
|
| 291 | 291 | |
| 292 | - /** |
|
| 293 | - * Count the number of users |
|
| 294 | - * @return int|bool |
|
| 295 | - */ |
|
| 296 | - public function countUsers() { |
|
| 297 | - $users = false; |
|
| 298 | - foreach($this->backends as $backend) { |
|
| 299 | - $backendUsers = $backend->countUsers(); |
|
| 300 | - if ($backendUsers !== false) { |
|
| 301 | - $users += $backendUsers; |
|
| 302 | - } |
|
| 303 | - } |
|
| 304 | - return $users; |
|
| 305 | - } |
|
| 292 | + /** |
|
| 293 | + * Count the number of users |
|
| 294 | + * @return int|bool |
|
| 295 | + */ |
|
| 296 | + public function countUsers() { |
|
| 297 | + $users = false; |
|
| 298 | + foreach($this->backends as $backend) { |
|
| 299 | + $backendUsers = $backend->countUsers(); |
|
| 300 | + if ($backendUsers !== false) { |
|
| 301 | + $users += $backendUsers; |
|
| 302 | + } |
|
| 303 | + } |
|
| 304 | + return $users; |
|
| 305 | + } |
|
| 306 | 306 | |
| 307 | - /** |
|
| 308 | - * Return access for LDAP interaction. |
|
| 309 | - * @param string $uid |
|
| 310 | - * @return Access instance of Access for LDAP interaction |
|
| 311 | - */ |
|
| 312 | - public function getLDAPAccess($uid) { |
|
| 313 | - return $this->handleRequest($uid, 'getLDAPAccess', array($uid)); |
|
| 314 | - } |
|
| 307 | + /** |
|
| 308 | + * Return access for LDAP interaction. |
|
| 309 | + * @param string $uid |
|
| 310 | + * @return Access instance of Access for LDAP interaction |
|
| 311 | + */ |
|
| 312 | + public function getLDAPAccess($uid) { |
|
| 313 | + return $this->handleRequest($uid, 'getLDAPAccess', array($uid)); |
|
| 314 | + } |
|
| 315 | 315 | |
| 316 | - /** |
|
| 317 | - * Return a new LDAP connection for the specified user. |
|
| 318 | - * The connection needs to be closed manually. |
|
| 319 | - * @param string $uid |
|
| 320 | - * @return resource of the LDAP connection |
|
| 321 | - */ |
|
| 322 | - public function getNewLDAPConnection($uid) { |
|
| 323 | - return $this->handleRequest($uid, 'getNewLDAPConnection', array($uid)); |
|
| 324 | - } |
|
| 316 | + /** |
|
| 317 | + * Return a new LDAP connection for the specified user. |
|
| 318 | + * The connection needs to be closed manually. |
|
| 319 | + * @param string $uid |
|
| 320 | + * @return resource of the LDAP connection |
|
| 321 | + */ |
|
| 322 | + public function getNewLDAPConnection($uid) { |
|
| 323 | + return $this->handleRequest($uid, 'getNewLDAPConnection', array($uid)); |
|
| 324 | + } |
|
| 325 | 325 | } |
@@ -50,10 +50,10 @@ discard block |
||
| 50 | 50 | public function __construct(array $serverConfigPrefixes, ILDAPWrapper $ldap, IConfig $ocConfig, |
| 51 | 51 | INotificationManager $notificationManager, IUserSession $userSession) { |
| 52 | 52 | parent::__construct($ldap); |
| 53 | - foreach($serverConfigPrefixes as $configPrefix) { |
|
| 53 | + foreach ($serverConfigPrefixes as $configPrefix) { |
|
| 54 | 54 | $this->backends[$configPrefix] = |
| 55 | 55 | new User_LDAP($this->getAccess($configPrefix), $ocConfig, $notificationManager, $userSession); |
| 56 | - if(is_null($this->refBackend)) { |
|
| 56 | + if (is_null($this->refBackend)) { |
|
| 57 | 57 | $this->refBackend = &$this->backends[$configPrefix]; |
| 58 | 58 | } |
| 59 | 59 | } |
@@ -68,13 +68,13 @@ discard block |
||
| 68 | 68 | */ |
| 69 | 69 | protected function walkBackends($uid, $method, $parameters) { |
| 70 | 70 | $cacheKey = $this->getUserCacheKey($uid); |
| 71 | - foreach($this->backends as $configPrefix => $backend) { |
|
| 71 | + foreach ($this->backends as $configPrefix => $backend) { |
|
| 72 | 72 | $instance = $backend; |
| 73 | - if(!method_exists($instance, $method) |
|
| 73 | + if (!method_exists($instance, $method) |
|
| 74 | 74 | && method_exists($this->getAccess($configPrefix), $method)) { |
| 75 | 75 | $instance = $this->getAccess($configPrefix); |
| 76 | 76 | } |
| 77 | - if($result = call_user_func_array(array($instance, $method), $parameters)) { |
|
| 77 | + if ($result = call_user_func_array(array($instance, $method), $parameters)) { |
|
| 78 | 78 | $this->writeToCache($cacheKey, $configPrefix); |
| 79 | 79 | return $result; |
| 80 | 80 | } |
@@ -94,22 +94,22 @@ discard block |
||
| 94 | 94 | $cacheKey = $this->getUserCacheKey($uid); |
| 95 | 95 | $prefix = $this->getFromCache($cacheKey); |
| 96 | 96 | //in case the uid has been found in the past, try this stored connection first |
| 97 | - if(!is_null($prefix)) { |
|
| 98 | - if(isset($this->backends[$prefix])) { |
|
| 97 | + if (!is_null($prefix)) { |
|
| 98 | + if (isset($this->backends[$prefix])) { |
|
| 99 | 99 | $instance = $this->backends[$prefix]; |
| 100 | - if(!method_exists($instance, $method) |
|
| 100 | + if (!method_exists($instance, $method) |
|
| 101 | 101 | && method_exists($this->getAccess($prefix), $method)) { |
| 102 | 102 | $instance = $this->getAccess($prefix); |
| 103 | 103 | } |
| 104 | 104 | $result = call_user_func_array(array($instance, $method), $parameters); |
| 105 | - if($result === $passOnWhen) { |
|
| 105 | + if ($result === $passOnWhen) { |
|
| 106 | 106 | //not found here, reset cache to null if user vanished |
| 107 | 107 | //because sometimes methods return false with a reason |
| 108 | 108 | $userExists = call_user_func_array( |
| 109 | 109 | array($this->backends[$prefix], 'userExists'), |
| 110 | 110 | array($uid) |
| 111 | 111 | ); |
| 112 | - if(!$userExists) { |
|
| 112 | + if (!$userExists) { |
|
| 113 | 113 | $this->writeToCache($cacheKey, null); |
| 114 | 114 | } |
| 115 | 115 | } |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | public function getUsers($search = '', $limit = 10, $offset = 0) { |
| 152 | 152 | //we do it just as the /OC_User implementation: do not play around with limit and offset but ask all backends |
| 153 | 153 | $users = array(); |
| 154 | - foreach($this->backends as $backend) { |
|
| 154 | + foreach ($this->backends as $backend) { |
|
| 155 | 155 | $backendUsers = $backend->getUsers($search, $limit, $offset); |
| 156 | 156 | if (is_array($backendUsers)) { |
| 157 | 157 | $users = array_merge($users, $backendUsers); |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | * @return string|false |
| 200 | 200 | */ |
| 201 | 201 | public function loginName2UserName($loginName) { |
| 202 | - $id = 'LOGINNAME,' . $loginName; |
|
| 202 | + $id = 'LOGINNAME,'.$loginName; |
|
| 203 | 203 | return $this->handleRequest($id, 'loginName2UserName', array($loginName)); |
| 204 | 204 | } |
| 205 | 205 | |
@@ -210,7 +210,7 @@ discard block |
||
| 210 | 210 | * @return string|false with the username |
| 211 | 211 | */ |
| 212 | 212 | public function dn2UserName($dn) { |
| 213 | - $id = 'DN,' . $dn; |
|
| 213 | + $id = 'DN,'.$dn; |
|
| 214 | 214 | return $this->handleRequest($id, 'dn2UserName', array($dn)); |
| 215 | 215 | } |
| 216 | 216 | |
@@ -251,7 +251,7 @@ discard block |
||
| 251 | 251 | public function getDisplayNames($search = '', $limit = null, $offset = null) { |
| 252 | 252 | //we do it just as the /OC_User implementation: do not play around with limit and offset but ask all backends |
| 253 | 253 | $users = array(); |
| 254 | - foreach($this->backends as $backend) { |
|
| 254 | + foreach ($this->backends as $backend) { |
|
| 255 | 255 | $backendUsers = $backend->getDisplayNames($search, $limit, $offset); |
| 256 | 256 | if (is_array($backendUsers)) { |
| 257 | 257 | $users = $users + $backendUsers; |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | */ |
| 296 | 296 | public function countUsers() { |
| 297 | 297 | $users = false; |
| 298 | - foreach($this->backends as $backend) { |
|
| 298 | + foreach ($this->backends as $backend) { |
|
| 299 | 299 | $backendUsers = $backend->countUsers(); |
| 300 | 300 | if ($backendUsers !== false) { |
| 301 | 301 | $users += $backendUsers; |
@@ -47,518 +47,518 @@ |
||
| 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 owncloud 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 owncloud 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 | } |
@@ -89,10 +89,10 @@ discard block |
||
| 89 | 89 | */ |
| 90 | 90 | public function canChangeAvatar($uid) { |
| 91 | 91 | $user = $this->access->userManager->get($uid); |
| 92 | - if(!$user instanceof User) { |
|
| 92 | + if (!$user instanceof User) { |
|
| 93 | 93 | return false; |
| 94 | 94 | } |
| 95 | - if($user->getAvatarImage() === false) { |
|
| 95 | + if ($user->getAvatarImage() === false) { |
|
| 96 | 96 | return true; |
| 97 | 97 | } |
| 98 | 98 | |
@@ -108,14 +108,14 @@ discard block |
||
| 108 | 108 | public function loginName2UserName($loginName) { |
| 109 | 109 | $cacheKey = 'loginName2UserName-'.$loginName; |
| 110 | 110 | $username = $this->access->connection->getFromCache($cacheKey); |
| 111 | - if(!is_null($username)) { |
|
| 111 | + if (!is_null($username)) { |
|
| 112 | 112 | return $username; |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | try { |
| 116 | 116 | $ldapRecord = $this->getLDAPUserByLoginName($loginName); |
| 117 | 117 | $user = $this->access->userManager->get($ldapRecord['dn'][0]); |
| 118 | - if($user instanceof OfflineUser) { |
|
| 118 | + if ($user instanceof OfflineUser) { |
|
| 119 | 119 | // this path is not really possible, however get() is documented |
| 120 | 120 | // to return User or OfflineUser so we are very defensive here. |
| 121 | 121 | $this->access->connection->writeToCache($cacheKey, false); |
@@ -151,9 +151,9 @@ discard block |
||
| 151 | 151 | //find out dn of the user name |
| 152 | 152 | $attrs = $this->access->userManager->getAttributes(); |
| 153 | 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); |
|
| 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 | 157 | } |
| 158 | 158 | return $users[0]; |
| 159 | 159 | } |
@@ -168,8 +168,8 @@ discard block |
||
| 168 | 168 | public function checkPassword($uid, $password) { |
| 169 | 169 | try { |
| 170 | 170 | $ldapRecord = $this->getLDAPUserByLoginName($uid); |
| 171 | - } catch(NotOnLDAP $e) { |
|
| 172 | - if($this->ocConfig->getSystemValue('loglevel', Util::WARN) === Util::DEBUG) { |
|
| 171 | + } catch (NotOnLDAP $e) { |
|
| 172 | + if ($this->ocConfig->getSystemValue('loglevel', Util::WARN) === Util::DEBUG) { |
|
| 173 | 173 | \OC::$server->getLogger()->logException($e, ['app' => 'user_ldap']); |
| 174 | 174 | } |
| 175 | 175 | return false; |
@@ -177,16 +177,16 @@ discard block |
||
| 177 | 177 | $dn = $ldapRecord['dn'][0]; |
| 178 | 178 | $user = $this->access->userManager->get($dn); |
| 179 | 179 | |
| 180 | - if(!$user instanceof User) { |
|
| 180 | + if (!$user instanceof User) { |
|
| 181 | 181 | Util::writeLog('user_ldap', |
| 182 | - 'LDAP Login: Could not get user object for DN ' . $dn . |
|
| 182 | + 'LDAP Login: Could not get user object for DN '.$dn. |
|
| 183 | 183 | '. Maybe the LDAP entry has no set display name attribute?', |
| 184 | 184 | Util::WARN); |
| 185 | 185 | return false; |
| 186 | 186 | } |
| 187 | - if($user->getUsername() !== false) { |
|
| 187 | + if ($user->getUsername() !== false) { |
|
| 188 | 188 | //are the credentials OK? |
| 189 | - if(!$this->access->areCredentialsValid($dn, $password)) { |
|
| 189 | + if (!$this->access->areCredentialsValid($dn, $password)) { |
|
| 190 | 190 | return false; |
| 191 | 191 | } |
| 192 | 192 | |
@@ -209,11 +209,11 @@ discard block |
||
| 209 | 209 | public function setPassword($uid, $password) { |
| 210 | 210 | $user = $this->access->userManager->get($uid); |
| 211 | 211 | |
| 212 | - if(!$user instanceof User) { |
|
| 213 | - throw new \Exception('LDAP setPassword: Could not get user object for uid ' . $uid . |
|
| 212 | + if (!$user instanceof User) { |
|
| 213 | + throw new \Exception('LDAP setPassword: Could not get user object for uid '.$uid. |
|
| 214 | 214 | '. Maybe the LDAP entry has no set display name attribute?'); |
| 215 | 215 | } |
| 216 | - if($user->getUsername() !== false && $this->access->setPassword($user->getDN(), $password)) { |
|
| 216 | + if ($user->getUsername() !== false && $this->access->setPassword($user->getDN(), $password)) { |
|
| 217 | 217 | $ldapDefaultPPolicyDN = $this->access->connection->ldapDefaultPPolicyDN; |
| 218 | 218 | $turnOnPasswordChange = $this->access->connection->turnOnPasswordChange; |
| 219 | 219 | if (!empty($ldapDefaultPPolicyDN) && (intval($turnOnPasswordChange) === 1)) { |
@@ -245,18 +245,18 @@ discard block |
||
| 245 | 245 | |
| 246 | 246 | //check if users are cached, if so return |
| 247 | 247 | $ldap_users = $this->access->connection->getFromCache($cachekey); |
| 248 | - if(!is_null($ldap_users)) { |
|
| 248 | + if (!is_null($ldap_users)) { |
|
| 249 | 249 | return $ldap_users; |
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | // if we'd pass -1 to LDAP search, we'd end up in a Protocol |
| 253 | 253 | // error. With a limit of 0, we get 0 results. So we pass null. |
| 254 | - if($limit <= 0) { |
|
| 254 | + if ($limit <= 0) { |
|
| 255 | 255 | $limit = null; |
| 256 | 256 | } |
| 257 | 257 | $filter = $this->access->combineFilterWithAnd(array( |
| 258 | 258 | $this->access->connection->ldapUserFilter, |
| 259 | - $this->access->connection->ldapUserDisplayName . '=*', |
|
| 259 | + $this->access->connection->ldapUserDisplayName.'=*', |
|
| 260 | 260 | $this->access->getFilterPartForUserSearch($search) |
| 261 | 261 | )); |
| 262 | 262 | |
@@ -269,7 +269,7 @@ discard block |
||
| 269 | 269 | $this->access->userManager->getAttributes(true), |
| 270 | 270 | $limit, $offset); |
| 271 | 271 | $ldap_users = $this->access->nextcloudUserNames($ldap_users); |
| 272 | - Util::writeLog('user_ldap', 'getUsers: '.count($ldap_users). ' Users found', Util::DEBUG); |
|
| 272 | + Util::writeLog('user_ldap', 'getUsers: '.count($ldap_users).' Users found', Util::DEBUG); |
|
| 273 | 273 | |
| 274 | 274 | $this->access->connection->writeToCache($cachekey, $ldap_users); |
| 275 | 275 | return $ldap_users; |
@@ -285,29 +285,29 @@ discard block |
||
| 285 | 285 | * @throws \OC\ServerNotAvailableException |
| 286 | 286 | */ |
| 287 | 287 | public function userExistsOnLDAP($user) { |
| 288 | - if(is_string($user)) { |
|
| 288 | + if (is_string($user)) { |
|
| 289 | 289 | $user = $this->access->userManager->get($user); |
| 290 | 290 | } |
| 291 | - if(is_null($user)) { |
|
| 291 | + if (is_null($user)) { |
|
| 292 | 292 | return false; |
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | $dn = $user->getDN(); |
| 296 | 296 | //check if user really still exists by reading its entry |
| 297 | - if(!is_array($this->access->readAttribute($dn, '', $this->access->connection->ldapUserFilter))) { |
|
| 297 | + if (!is_array($this->access->readAttribute($dn, '', $this->access->connection->ldapUserFilter))) { |
|
| 298 | 298 | $lcr = $this->access->connection->getConnectionResource(); |
| 299 | - if(is_null($lcr)) { |
|
| 300 | - throw new \Exception('No LDAP Connection to server ' . $this->access->connection->ldapHost); |
|
| 299 | + if (is_null($lcr)) { |
|
| 300 | + throw new \Exception('No LDAP Connection to server '.$this->access->connection->ldapHost); |
|
| 301 | 301 | } |
| 302 | 302 | |
| 303 | 303 | try { |
| 304 | 304 | $uuid = $this->access->getUserMapper()->getUUIDByDN($dn); |
| 305 | - if(!$uuid) { |
|
| 305 | + if (!$uuid) { |
|
| 306 | 306 | return false; |
| 307 | 307 | } |
| 308 | 308 | $newDn = $this->access->getUserDnByUuid($uuid); |
| 309 | 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))) { |
|
| 310 | + if (!is_array($this->access->readAttribute($newDn, '', $this->access->connection->ldapUserFilter))) { |
|
| 311 | 311 | return false; |
| 312 | 312 | } |
| 313 | 313 | $this->access->getUserMapper()->setDNbyUUID($newDn, $uuid); |
@@ -317,7 +317,7 @@ discard block |
||
| 317 | 317 | } |
| 318 | 318 | } |
| 319 | 319 | |
| 320 | - if($user instanceof OfflineUser) { |
|
| 320 | + if ($user instanceof OfflineUser) { |
|
| 321 | 321 | $user->unmark(); |
| 322 | 322 | } |
| 323 | 323 | |
@@ -332,18 +332,18 @@ discard block |
||
| 332 | 332 | */ |
| 333 | 333 | public function userExists($uid) { |
| 334 | 334 | $userExists = $this->access->connection->getFromCache('userExists'.$uid); |
| 335 | - if(!is_null($userExists)) { |
|
| 336 | - return (bool)$userExists; |
|
| 335 | + if (!is_null($userExists)) { |
|
| 336 | + return (bool) $userExists; |
|
| 337 | 337 | } |
| 338 | 338 | //getting dn, if false the user does not exist. If dn, he may be mapped only, requires more checking. |
| 339 | 339 | $user = $this->access->userManager->get($uid); |
| 340 | 340 | |
| 341 | - if(is_null($user)) { |
|
| 341 | + if (is_null($user)) { |
|
| 342 | 342 | Util::writeLog('user_ldap', 'No DN found for '.$uid.' on '. |
| 343 | 343 | $this->access->connection->ldapHost, Util::DEBUG); |
| 344 | 344 | $this->access->connection->writeToCache('userExists'.$uid, false); |
| 345 | 345 | return false; |
| 346 | - } else if($user instanceof OfflineUser) { |
|
| 346 | + } else if ($user instanceof OfflineUser) { |
|
| 347 | 347 | //express check for users marked as deleted. Returning true is |
| 348 | 348 | //necessary for cleanup |
| 349 | 349 | return true; |
@@ -351,7 +351,7 @@ discard block |
||
| 351 | 351 | |
| 352 | 352 | $result = $this->userExistsOnLDAP($user); |
| 353 | 353 | $this->access->connection->writeToCache('userExists'.$uid, $result); |
| 354 | - if($result === true) { |
|
| 354 | + if ($result === true) { |
|
| 355 | 355 | $user->update(); |
| 356 | 356 | } |
| 357 | 357 | return $result; |
@@ -365,13 +365,13 @@ discard block |
||
| 365 | 365 | */ |
| 366 | 366 | public function deleteUser($uid) { |
| 367 | 367 | $marked = $this->ocConfig->getUserValue($uid, 'user_ldap', 'isDeleted', 0); |
| 368 | - if(intval($marked) === 0) { |
|
| 368 | + if (intval($marked) === 0) { |
|
| 369 | 369 | \OC::$server->getLogger()->notice( |
| 370 | - 'User '.$uid . ' is not marked as deleted, not cleaning up.', |
|
| 370 | + 'User '.$uid.' is not marked as deleted, not cleaning up.', |
|
| 371 | 371 | array('app' => 'user_ldap')); |
| 372 | 372 | return false; |
| 373 | 373 | } |
| 374 | - \OC::$server->getLogger()->info('Cleaning up after user ' . $uid, |
|
| 374 | + \OC::$server->getLogger()->info('Cleaning up after user '.$uid, |
|
| 375 | 375 | array('app' => 'user_ldap')); |
| 376 | 376 | |
| 377 | 377 | $this->access->getUserMapper()->unmap($uid); |
@@ -389,28 +389,28 @@ discard block |
||
| 389 | 389 | */ |
| 390 | 390 | public function getHome($uid) { |
| 391 | 391 | // user Exists check required as it is not done in user proxy! |
| 392 | - if(!$this->userExists($uid)) { |
|
| 392 | + if (!$this->userExists($uid)) { |
|
| 393 | 393 | return false; |
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | $cacheKey = 'getHome'.$uid; |
| 397 | 397 | $path = $this->access->connection->getFromCache($cacheKey); |
| 398 | - if(!is_null($path)) { |
|
| 398 | + if (!is_null($path)) { |
|
| 399 | 399 | return $path; |
| 400 | 400 | } |
| 401 | 401 | |
| 402 | 402 | // early return path if it is a deleted user |
| 403 | 403 | $user = $this->access->userManager->get($uid); |
| 404 | - if($user instanceof OfflineUser) { |
|
| 405 | - if($this->currentUserInDeletionProcess !== null |
|
| 404 | + if ($user instanceof OfflineUser) { |
|
| 405 | + if ($this->currentUserInDeletionProcess !== null |
|
| 406 | 406 | && $this->currentUserInDeletionProcess === $user->getOCName() |
| 407 | 407 | ) { |
| 408 | 408 | return $user->getHomePath(); |
| 409 | 409 | } else { |
| 410 | - throw new NoUserException($uid . ' is not a valid user anymore'); |
|
| 410 | + throw new NoUserException($uid.' is not a valid user anymore'); |
|
| 411 | 411 | } |
| 412 | 412 | } else if ($user === null) { |
| 413 | - throw new NoUserException($uid . ' is not a valid user anymore'); |
|
| 413 | + throw new NoUserException($uid.' is not a valid user anymore'); |
|
| 414 | 414 | } |
| 415 | 415 | |
| 416 | 416 | $path = $user->getHomePath(); |
@@ -425,12 +425,12 @@ discard block |
||
| 425 | 425 | * @return string|false display name |
| 426 | 426 | */ |
| 427 | 427 | public function getDisplayName($uid) { |
| 428 | - if(!$this->userExists($uid)) { |
|
| 428 | + if (!$this->userExists($uid)) { |
|
| 429 | 429 | return false; |
| 430 | 430 | } |
| 431 | 431 | |
| 432 | 432 | $cacheKey = 'getDisplayName'.$uid; |
| 433 | - if(!is_null($displayName = $this->access->connection->getFromCache($cacheKey))) { |
|
| 433 | + if (!is_null($displayName = $this->access->connection->getFromCache($cacheKey))) { |
|
| 434 | 434 | return $displayName; |
| 435 | 435 | } |
| 436 | 436 | |
@@ -447,10 +447,10 @@ discard block |
||
| 447 | 447 | $this->access->username2dn($uid), |
| 448 | 448 | $this->access->connection->ldapUserDisplayName); |
| 449 | 449 | |
| 450 | - if($displayName && (count($displayName) > 0)) { |
|
| 450 | + if ($displayName && (count($displayName) > 0)) { |
|
| 451 | 451 | $displayName = $displayName[0]; |
| 452 | 452 | |
| 453 | - if (is_array($displayName2)){ |
|
| 453 | + if (is_array($displayName2)) { |
|
| 454 | 454 | $displayName2 = count($displayName2) > 0 ? $displayName2[0] : ''; |
| 455 | 455 | } |
| 456 | 456 | |
@@ -479,7 +479,7 @@ discard block |
||
| 479 | 479 | */ |
| 480 | 480 | public function getDisplayNames($search = '', $limit = null, $offset = null) { |
| 481 | 481 | $cacheKey = 'getDisplayNames-'.$search.'-'.$limit.'-'.$offset; |
| 482 | - if(!is_null($displayNames = $this->access->connection->getFromCache($cacheKey))) { |
|
| 482 | + if (!is_null($displayNames = $this->access->connection->getFromCache($cacheKey))) { |
|
| 483 | 483 | return $displayNames; |
| 484 | 484 | } |
| 485 | 485 | |
@@ -501,12 +501,12 @@ discard block |
||
| 501 | 501 | * compared with \OC\User\Backend::CREATE_USER etc. |
| 502 | 502 | */ |
| 503 | 503 | public function implementsActions($actions) { |
| 504 | - return (bool)((Backend::CHECK_PASSWORD |
|
| 504 | + return (bool) ((Backend::CHECK_PASSWORD |
|
| 505 | 505 | | Backend::GET_HOME |
| 506 | 506 | | Backend::GET_DISPLAYNAME |
| 507 | 507 | | Backend::PROVIDE_AVATAR |
| 508 | 508 | | Backend::COUNT_USERS |
| 509 | - | ((intval($this->access->connection->turnOnPasswordChange) === 1)?(Backend::SET_PASSWORD):0)) |
|
| 509 | + | ((intval($this->access->connection->turnOnPasswordChange) === 1) ? (Backend::SET_PASSWORD) : 0)) |
|
| 510 | 510 | & $actions); |
| 511 | 511 | } |
| 512 | 512 | |
@@ -525,7 +525,7 @@ discard block |
||
| 525 | 525 | public function countUsers() { |
| 526 | 526 | $filter = $this->access->getFilterForUserCount(); |
| 527 | 527 | $cacheKey = 'countUsers-'.$filter; |
| 528 | - if(!is_null($entries = $this->access->connection->getFromCache($cacheKey))) { |
|
| 528 | + if (!is_null($entries = $this->access->connection->getFromCache($cacheKey))) { |
|
| 529 | 529 | return $entries; |
| 530 | 530 | } |
| 531 | 531 | $entries = $this->access->countUsers($filter); |
@@ -537,7 +537,7 @@ discard block |
||
| 537 | 537 | * Backend name to be shown in user management |
| 538 | 538 | * @return string the name of the backend to be shown |
| 539 | 539 | */ |
| 540 | - public function getBackendName(){ |
|
| 540 | + public function getBackendName() { |
|
| 541 | 541 | return 'LDAP'; |
| 542 | 542 | } |
| 543 | 543 | |
@@ -37,104 +37,104 @@ |
||
| 37 | 37 | use OCP\IConfig; |
| 38 | 38 | |
| 39 | 39 | class Search extends Command { |
| 40 | - /** @var \OCP\IConfig */ |
|
| 41 | - protected $ocConfig; |
|
| 40 | + /** @var \OCP\IConfig */ |
|
| 41 | + protected $ocConfig; |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * @param \OCP\IConfig $ocConfig |
|
| 45 | - */ |
|
| 46 | - public function __construct(IConfig $ocConfig) { |
|
| 47 | - $this->ocConfig = $ocConfig; |
|
| 48 | - parent::__construct(); |
|
| 49 | - } |
|
| 43 | + /** |
|
| 44 | + * @param \OCP\IConfig $ocConfig |
|
| 45 | + */ |
|
| 46 | + public function __construct(IConfig $ocConfig) { |
|
| 47 | + $this->ocConfig = $ocConfig; |
|
| 48 | + parent::__construct(); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - protected function configure() { |
|
| 52 | - $this |
|
| 53 | - ->setName('ldap:search') |
|
| 54 | - ->setDescription('executes a user or group search') |
|
| 55 | - ->addArgument( |
|
| 56 | - 'search', |
|
| 57 | - InputArgument::REQUIRED, |
|
| 58 | - 'the search string (can be empty)' |
|
| 59 | - ) |
|
| 60 | - ->addOption( |
|
| 61 | - 'group', |
|
| 62 | - null, |
|
| 63 | - InputOption::VALUE_NONE, |
|
| 64 | - 'searches groups instead of users' |
|
| 65 | - ) |
|
| 66 | - ->addOption( |
|
| 67 | - 'offset', |
|
| 68 | - null, |
|
| 69 | - InputOption::VALUE_REQUIRED, |
|
| 70 | - 'The offset of the result set. Needs to be a multiple of limit. defaults to 0.', |
|
| 71 | - 0 |
|
| 72 | - ) |
|
| 73 | - ->addOption( |
|
| 74 | - 'limit', |
|
| 75 | - null, |
|
| 76 | - InputOption::VALUE_REQUIRED, |
|
| 77 | - 'limit the results. 0 means no limit, defaults to 15', |
|
| 78 | - 15 |
|
| 79 | - ) |
|
| 80 | - ; |
|
| 81 | - } |
|
| 51 | + protected function configure() { |
|
| 52 | + $this |
|
| 53 | + ->setName('ldap:search') |
|
| 54 | + ->setDescription('executes a user or group search') |
|
| 55 | + ->addArgument( |
|
| 56 | + 'search', |
|
| 57 | + InputArgument::REQUIRED, |
|
| 58 | + 'the search string (can be empty)' |
|
| 59 | + ) |
|
| 60 | + ->addOption( |
|
| 61 | + 'group', |
|
| 62 | + null, |
|
| 63 | + InputOption::VALUE_NONE, |
|
| 64 | + 'searches groups instead of users' |
|
| 65 | + ) |
|
| 66 | + ->addOption( |
|
| 67 | + 'offset', |
|
| 68 | + null, |
|
| 69 | + InputOption::VALUE_REQUIRED, |
|
| 70 | + 'The offset of the result set. Needs to be a multiple of limit. defaults to 0.', |
|
| 71 | + 0 |
|
| 72 | + ) |
|
| 73 | + ->addOption( |
|
| 74 | + 'limit', |
|
| 75 | + null, |
|
| 76 | + InputOption::VALUE_REQUIRED, |
|
| 77 | + 'limit the results. 0 means no limit, defaults to 15', |
|
| 78 | + 15 |
|
| 79 | + ) |
|
| 80 | + ; |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * Tests whether the offset and limit options are valid |
|
| 85 | - * @param int $offset |
|
| 86 | - * @param int $limit |
|
| 87 | - * @throws \InvalidArgumentException |
|
| 88 | - */ |
|
| 89 | - protected function validateOffsetAndLimit($offset, $limit) { |
|
| 90 | - if($limit < 0) { |
|
| 91 | - throw new \InvalidArgumentException('limit must be 0 or greater'); |
|
| 92 | - } |
|
| 93 | - if($offset < 0) { |
|
| 94 | - throw new \InvalidArgumentException('offset must be 0 or greater'); |
|
| 95 | - } |
|
| 96 | - if($limit === 0 && $offset !== 0) { |
|
| 97 | - throw new \InvalidArgumentException('offset must be 0 if limit is also set to 0'); |
|
| 98 | - } |
|
| 99 | - if($offset > 0 && ($offset % $limit !== 0)) { |
|
| 100 | - throw new \InvalidArgumentException('offset must be a multiple of limit'); |
|
| 101 | - } |
|
| 102 | - } |
|
| 83 | + /** |
|
| 84 | + * Tests whether the offset and limit options are valid |
|
| 85 | + * @param int $offset |
|
| 86 | + * @param int $limit |
|
| 87 | + * @throws \InvalidArgumentException |
|
| 88 | + */ |
|
| 89 | + protected function validateOffsetAndLimit($offset, $limit) { |
|
| 90 | + if($limit < 0) { |
|
| 91 | + throw new \InvalidArgumentException('limit must be 0 or greater'); |
|
| 92 | + } |
|
| 93 | + if($offset < 0) { |
|
| 94 | + throw new \InvalidArgumentException('offset must be 0 or greater'); |
|
| 95 | + } |
|
| 96 | + if($limit === 0 && $offset !== 0) { |
|
| 97 | + throw new \InvalidArgumentException('offset must be 0 if limit is also set to 0'); |
|
| 98 | + } |
|
| 99 | + if($offset > 0 && ($offset % $limit !== 0)) { |
|
| 100 | + throw new \InvalidArgumentException('offset must be a multiple of limit'); |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 105 | - $helper = new Helper($this->ocConfig); |
|
| 106 | - $configPrefixes = $helper->getServerConfigurationPrefixes(true); |
|
| 107 | - $ldapWrapper = new LDAP(); |
|
| 104 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 105 | + $helper = new Helper($this->ocConfig); |
|
| 106 | + $configPrefixes = $helper->getServerConfigurationPrefixes(true); |
|
| 107 | + $ldapWrapper = new LDAP(); |
|
| 108 | 108 | |
| 109 | - $offset = intval($input->getOption('offset')); |
|
| 110 | - $limit = intval($input->getOption('limit')); |
|
| 111 | - $this->validateOffsetAndLimit($offset, $limit); |
|
| 109 | + $offset = intval($input->getOption('offset')); |
|
| 110 | + $limit = intval($input->getOption('limit')); |
|
| 111 | + $this->validateOffsetAndLimit($offset, $limit); |
|
| 112 | 112 | |
| 113 | - if($input->getOption('group')) { |
|
| 114 | - $proxy = new Group_Proxy($configPrefixes, $ldapWrapper); |
|
| 115 | - $getMethod = 'getGroups'; |
|
| 116 | - $printID = false; |
|
| 117 | - // convert the limit of groups to null. This will show all the groups available instead of |
|
| 118 | - // nothing, and will match the same behaviour the search for users has. |
|
| 119 | - if ($limit === 0) { |
|
| 120 | - $limit = null; |
|
| 121 | - } |
|
| 122 | - } else { |
|
| 123 | - $proxy = new User_Proxy( |
|
| 124 | - $configPrefixes, |
|
| 125 | - $ldapWrapper, |
|
| 126 | - $this->ocConfig, |
|
| 127 | - \OC::$server->getNotificationManager(), |
|
| 128 | - \OC::$server->getUserSession() |
|
| 129 | - ); |
|
| 130 | - $getMethod = 'getDisplayNames'; |
|
| 131 | - $printID = true; |
|
| 132 | - } |
|
| 113 | + if($input->getOption('group')) { |
|
| 114 | + $proxy = new Group_Proxy($configPrefixes, $ldapWrapper); |
|
| 115 | + $getMethod = 'getGroups'; |
|
| 116 | + $printID = false; |
|
| 117 | + // convert the limit of groups to null. This will show all the groups available instead of |
|
| 118 | + // nothing, and will match the same behaviour the search for users has. |
|
| 119 | + if ($limit === 0) { |
|
| 120 | + $limit = null; |
|
| 121 | + } |
|
| 122 | + } else { |
|
| 123 | + $proxy = new User_Proxy( |
|
| 124 | + $configPrefixes, |
|
| 125 | + $ldapWrapper, |
|
| 126 | + $this->ocConfig, |
|
| 127 | + \OC::$server->getNotificationManager(), |
|
| 128 | + \OC::$server->getUserSession() |
|
| 129 | + ); |
|
| 130 | + $getMethod = 'getDisplayNames'; |
|
| 131 | + $printID = true; |
|
| 132 | + } |
|
| 133 | 133 | |
| 134 | - $result = $proxy->$getMethod($input->getArgument('search'), $limit, $offset); |
|
| 135 | - foreach($result as $id => $name) { |
|
| 136 | - $line = $name . ($printID ? ' ('.$id.')' : ''); |
|
| 137 | - $output->writeln($line); |
|
| 138 | - } |
|
| 139 | - } |
|
| 134 | + $result = $proxy->$getMethod($input->getArgument('search'), $limit, $offset); |
|
| 135 | + foreach($result as $id => $name) { |
|
| 136 | + $line = $name . ($printID ? ' ('.$id.')' : ''); |
|
| 137 | + $output->writeln($line); |
|
| 138 | + } |
|
| 139 | + } |
|
| 140 | 140 | } |
@@ -30,34 +30,34 @@ |
||
| 30 | 30 | $helper = new \OCA\User_LDAP\Helper(\OC::$server->getConfig()); |
| 31 | 31 | $configPrefixes = $helper->getServerConfigurationPrefixes(true); |
| 32 | 32 | if(count($configPrefixes) > 0) { |
| 33 | - $ldapWrapper = new OCA\User_LDAP\LDAP(); |
|
| 34 | - $ocConfig = \OC::$server->getConfig(); |
|
| 35 | - $notificationManager = \OC::$server->getNotificationManager(); |
|
| 36 | - $notificationManager->registerNotifier(function() { |
|
| 37 | - return new \OCA\User_LDAP\Notification\Notifier( |
|
| 38 | - \OC::$server->getL10NFactory() |
|
| 39 | - ); |
|
| 40 | - }, function() { |
|
| 41 | - $l = \OC::$server->getL10N('user_ldap'); |
|
| 42 | - return [ |
|
| 43 | - 'id' => 'user_ldap', |
|
| 44 | - 'name' => $l->t('LDAP user and group backend'), |
|
| 45 | - ]; |
|
| 46 | - }); |
|
| 47 | - $userSession = \OC::$server->getUserSession(); |
|
| 33 | + $ldapWrapper = new OCA\User_LDAP\LDAP(); |
|
| 34 | + $ocConfig = \OC::$server->getConfig(); |
|
| 35 | + $notificationManager = \OC::$server->getNotificationManager(); |
|
| 36 | + $notificationManager->registerNotifier(function() { |
|
| 37 | + return new \OCA\User_LDAP\Notification\Notifier( |
|
| 38 | + \OC::$server->getL10NFactory() |
|
| 39 | + ); |
|
| 40 | + }, function() { |
|
| 41 | + $l = \OC::$server->getL10N('user_ldap'); |
|
| 42 | + return [ |
|
| 43 | + 'id' => 'user_ldap', |
|
| 44 | + 'name' => $l->t('LDAP user and group backend'), |
|
| 45 | + ]; |
|
| 46 | + }); |
|
| 47 | + $userSession = \OC::$server->getUserSession(); |
|
| 48 | 48 | |
| 49 | - $userBackend = new OCA\User_LDAP\User_Proxy( |
|
| 50 | - $configPrefixes, $ldapWrapper, $ocConfig, $notificationManager, $userSession |
|
| 51 | - ); |
|
| 52 | - $groupBackend = new OCA\User_LDAP\Group_Proxy($configPrefixes, $ldapWrapper); |
|
| 53 | - // register user backend |
|
| 54 | - OC_User::useBackend($userBackend); |
|
| 55 | - \OC::$server->getGroupManager()->addBackend($groupBackend); |
|
| 49 | + $userBackend = new OCA\User_LDAP\User_Proxy( |
|
| 50 | + $configPrefixes, $ldapWrapper, $ocConfig, $notificationManager, $userSession |
|
| 51 | + ); |
|
| 52 | + $groupBackend = new OCA\User_LDAP\Group_Proxy($configPrefixes, $ldapWrapper); |
|
| 53 | + // register user backend |
|
| 54 | + OC_User::useBackend($userBackend); |
|
| 55 | + \OC::$server->getGroupManager()->addBackend($groupBackend); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | \OCP\Util::connectHook( |
| 59 | - '\OCA\Files_Sharing\API\Server2Server', |
|
| 60 | - 'preLoginNameUsedAsUserName', |
|
| 61 | - '\OCA\User_LDAP\Helper', |
|
| 62 | - 'loginName2UserName' |
|
| 59 | + '\OCA\Files_Sharing\API\Server2Server', |
|
| 60 | + 'preLoginNameUsedAsUserName', |
|
| 61 | + '\OCA\User_LDAP\Helper', |
|
| 62 | + 'loginName2UserName' |
|
| 63 | 63 | ); |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | |
| 30 | 30 | $helper = new \OCA\User_LDAP\Helper(\OC::$server->getConfig()); |
| 31 | 31 | $configPrefixes = $helper->getServerConfigurationPrefixes(true); |
| 32 | -if(count($configPrefixes) > 0) { |
|
| 32 | +if (count($configPrefixes) > 0) { |
|
| 33 | 33 | $ldapWrapper = new OCA\User_LDAP\LDAP(); |
| 34 | 34 | $ocConfig = \OC::$server->getConfig(); |
| 35 | 35 | $notificationManager = \OC::$server->getNotificationManager(); |
@@ -46,10 +46,10 @@ discard block |
||
| 46 | 46 | }); |
| 47 | 47 | $userSession = \OC::$server->getUserSession(); |
| 48 | 48 | |
| 49 | - $userBackend = new OCA\User_LDAP\User_Proxy( |
|
| 49 | + $userBackend = new OCA\User_LDAP\User_Proxy( |
|
| 50 | 50 | $configPrefixes, $ldapWrapper, $ocConfig, $notificationManager, $userSession |
| 51 | 51 | ); |
| 52 | - $groupBackend = new OCA\User_LDAP\Group_Proxy($configPrefixes, $ldapWrapper); |
|
| 52 | + $groupBackend = new OCA\User_LDAP\Group_Proxy($configPrefixes, $ldapWrapper); |
|
| 53 | 53 | // register user backend |
| 54 | 54 | OC_User::useBackend($userBackend); |
| 55 | 55 | \OC::$server->getGroupManager()->addBackend($groupBackend); |
@@ -33,14 +33,14 @@ discard block |
||
| 33 | 33 | $helper = new Helper(\OC::$server->getConfig()); |
| 34 | 34 | $ocConfig = \OC::$server->getConfig(); |
| 35 | 35 | $uBackend = new User_Proxy( |
| 36 | - $helper->getServerConfigurationPrefixes(true), |
|
| 37 | - new LDAP(), |
|
| 38 | - $ocConfig, |
|
| 39 | - \OC::$server->getNotificationManager(), |
|
| 40 | - \OC::$server->getUserSession() |
|
| 36 | + $helper->getServerConfigurationPrefixes(true), |
|
| 37 | + new LDAP(), |
|
| 38 | + $ocConfig, |
|
| 39 | + \OC::$server->getNotificationManager(), |
|
| 40 | + \OC::$server->getUserSession() |
|
| 41 | 41 | ); |
| 42 | 42 | $deletedUsersIndex = new DeletedUsersIndex( |
| 43 | - $ocConfig, $dbConnection, $userMapping |
|
| 43 | + $ocConfig, $dbConnection, $userMapping |
|
| 44 | 44 | ); |
| 45 | 45 | |
| 46 | 46 | $application->add(new OCA\User_LDAP\Command\ShowConfig($helper)); |
@@ -50,8 +50,8 @@ discard block |
||
| 50 | 50 | $application->add(new OCA\User_LDAP\Command\DeleteConfig($helper)); |
| 51 | 51 | $application->add(new OCA\User_LDAP\Command\Search($ocConfig)); |
| 52 | 52 | $application->add(new OCA\User_LDAP\Command\ShowRemnants( |
| 53 | - $deletedUsersIndex, \OC::$server->getDateTimeFormatter()) |
|
| 53 | + $deletedUsersIndex, \OC::$server->getDateTimeFormatter()) |
|
| 54 | 54 | ); |
| 55 | 55 | $application->add(new OCA\User_LDAP\Command\CheckUser( |
| 56 | - $uBackend, $helper, $deletedUsersIndex, $userMapping) |
|
| 56 | + $uBackend, $helper, $deletedUsersIndex, $userMapping) |
|
| 57 | 57 | ); |