@@ -33,285 +33,285 @@ |
||
| 33 | 33 | use OCP\IConfig; |
| 34 | 34 | |
| 35 | 35 | class User_Proxy extends Proxy implements \OCP\IUserBackend, \OCP\UserInterface, IUserLDAP { |
| 36 | - private $backends = array(); |
|
| 37 | - private $refBackend = null; |
|
| 36 | + private $backends = array(); |
|
| 37 | + private $refBackend = null; |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * Constructor |
|
| 41 | - * @param array $serverConfigPrefixes array containing the config Prefixes |
|
| 42 | - */ |
|
| 43 | - public function __construct(array $serverConfigPrefixes, ILDAPWrapper $ldap, IConfig $ocConfig) { |
|
| 44 | - parent::__construct($ldap); |
|
| 45 | - foreach($serverConfigPrefixes as $configPrefix) { |
|
| 46 | - $this->backends[$configPrefix] = |
|
| 47 | - new User_LDAP($this->getAccess($configPrefix), $ocConfig); |
|
| 48 | - if(is_null($this->refBackend)) { |
|
| 49 | - $this->refBackend = &$this->backends[$configPrefix]; |
|
| 50 | - } |
|
| 51 | - } |
|
| 52 | - } |
|
| 39 | + /** |
|
| 40 | + * Constructor |
|
| 41 | + * @param array $serverConfigPrefixes array containing the config Prefixes |
|
| 42 | + */ |
|
| 43 | + public function __construct(array $serverConfigPrefixes, ILDAPWrapper $ldap, IConfig $ocConfig) { |
|
| 44 | + parent::__construct($ldap); |
|
| 45 | + foreach($serverConfigPrefixes as $configPrefix) { |
|
| 46 | + $this->backends[$configPrefix] = |
|
| 47 | + new User_LDAP($this->getAccess($configPrefix), $ocConfig); |
|
| 48 | + if(is_null($this->refBackend)) { |
|
| 49 | + $this->refBackend = &$this->backends[$configPrefix]; |
|
| 50 | + } |
|
| 51 | + } |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Tries the backends one after the other until a positive result is returned from the specified method |
|
| 56 | - * @param string $uid the uid connected to the request |
|
| 57 | - * @param string $method the method of the user backend that shall be called |
|
| 58 | - * @param array $parameters an array of parameters to be passed |
|
| 59 | - * @return mixed the result of the method or false |
|
| 60 | - */ |
|
| 61 | - protected function walkBackends($uid, $method, $parameters) { |
|
| 62 | - $cacheKey = $this->getUserCacheKey($uid); |
|
| 63 | - foreach($this->backends as $configPrefix => $backend) { |
|
| 64 | - $instance = $backend; |
|
| 65 | - if(!method_exists($instance, $method) |
|
| 66 | - && method_exists($this->getAccess($configPrefix), $method)) { |
|
| 67 | - $instance = $this->getAccess($configPrefix); |
|
| 68 | - } |
|
| 69 | - if($result = call_user_func_array(array($instance, $method), $parameters)) { |
|
| 70 | - $this->writeToCache($cacheKey, $configPrefix); |
|
| 71 | - return $result; |
|
| 72 | - } |
|
| 73 | - } |
|
| 74 | - return false; |
|
| 75 | - } |
|
| 54 | + /** |
|
| 55 | + * Tries the backends one after the other until a positive result is returned from the specified method |
|
| 56 | + * @param string $uid the uid connected to the request |
|
| 57 | + * @param string $method the method of the user backend that shall be called |
|
| 58 | + * @param array $parameters an array of parameters to be passed |
|
| 59 | + * @return mixed the result of the method or false |
|
| 60 | + */ |
|
| 61 | + protected function walkBackends($uid, $method, $parameters) { |
|
| 62 | + $cacheKey = $this->getUserCacheKey($uid); |
|
| 63 | + foreach($this->backends as $configPrefix => $backend) { |
|
| 64 | + $instance = $backend; |
|
| 65 | + if(!method_exists($instance, $method) |
|
| 66 | + && method_exists($this->getAccess($configPrefix), $method)) { |
|
| 67 | + $instance = $this->getAccess($configPrefix); |
|
| 68 | + } |
|
| 69 | + if($result = call_user_func_array(array($instance, $method), $parameters)) { |
|
| 70 | + $this->writeToCache($cacheKey, $configPrefix); |
|
| 71 | + return $result; |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | + return false; |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * Asks the backend connected to the server that supposely takes care of the uid from the request. |
|
| 79 | - * @param string $uid the uid connected to the request |
|
| 80 | - * @param string $method the method of the user backend that shall be called |
|
| 81 | - * @param array $parameters an array of parameters to be passed |
|
| 82 | - * @param mixed $passOnWhen the result matches this variable |
|
| 83 | - * @return mixed the result of the method or false |
|
| 84 | - */ |
|
| 85 | - protected function callOnLastSeenOn($uid, $method, $parameters, $passOnWhen) { |
|
| 86 | - $cacheKey = $this->getUserCacheKey($uid); |
|
| 87 | - $prefix = $this->getFromCache($cacheKey); |
|
| 88 | - //in case the uid has been found in the past, try this stored connection first |
|
| 89 | - if(!is_null($prefix)) { |
|
| 90 | - if(isset($this->backends[$prefix])) { |
|
| 91 | - $instance = $this->backends[$prefix]; |
|
| 92 | - if(!method_exists($instance, $method) |
|
| 93 | - && method_exists($this->getAccess($prefix), $method)) { |
|
| 94 | - $instance = $this->getAccess($prefix); |
|
| 95 | - } |
|
| 96 | - $result = call_user_func_array(array($instance, $method), $parameters); |
|
| 97 | - if($result === $passOnWhen) { |
|
| 98 | - //not found here, reset cache to null if user vanished |
|
| 99 | - //because sometimes methods return false with a reason |
|
| 100 | - $userExists = call_user_func_array( |
|
| 101 | - array($this->backends[$prefix], 'userExists'), |
|
| 102 | - array($uid) |
|
| 103 | - ); |
|
| 104 | - if(!$userExists) { |
|
| 105 | - $this->writeToCache($cacheKey, null); |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - return $result; |
|
| 109 | - } |
|
| 110 | - } |
|
| 111 | - return false; |
|
| 112 | - } |
|
| 77 | + /** |
|
| 78 | + * Asks the backend connected to the server that supposely takes care of the uid from the request. |
|
| 79 | + * @param string $uid the uid connected to the request |
|
| 80 | + * @param string $method the method of the user backend that shall be called |
|
| 81 | + * @param array $parameters an array of parameters to be passed |
|
| 82 | + * @param mixed $passOnWhen the result matches this variable |
|
| 83 | + * @return mixed the result of the method or false |
|
| 84 | + */ |
|
| 85 | + protected function callOnLastSeenOn($uid, $method, $parameters, $passOnWhen) { |
|
| 86 | + $cacheKey = $this->getUserCacheKey($uid); |
|
| 87 | + $prefix = $this->getFromCache($cacheKey); |
|
| 88 | + //in case the uid has been found in the past, try this stored connection first |
|
| 89 | + if(!is_null($prefix)) { |
|
| 90 | + if(isset($this->backends[$prefix])) { |
|
| 91 | + $instance = $this->backends[$prefix]; |
|
| 92 | + if(!method_exists($instance, $method) |
|
| 93 | + && method_exists($this->getAccess($prefix), $method)) { |
|
| 94 | + $instance = $this->getAccess($prefix); |
|
| 95 | + } |
|
| 96 | + $result = call_user_func_array(array($instance, $method), $parameters); |
|
| 97 | + if($result === $passOnWhen) { |
|
| 98 | + //not found here, reset cache to null if user vanished |
|
| 99 | + //because sometimes methods return false with a reason |
|
| 100 | + $userExists = call_user_func_array( |
|
| 101 | + array($this->backends[$prefix], 'userExists'), |
|
| 102 | + array($uid) |
|
| 103 | + ); |
|
| 104 | + if(!$userExists) { |
|
| 105 | + $this->writeToCache($cacheKey, null); |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + return $result; |
|
| 109 | + } |
|
| 110 | + } |
|
| 111 | + return false; |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - /** |
|
| 115 | - * Check if backend implements actions |
|
| 116 | - * @param int $actions bitwise-or'ed actions |
|
| 117 | - * @return boolean |
|
| 118 | - * |
|
| 119 | - * Returns the supported actions as int to be |
|
| 120 | - * compared with OC_USER_BACKEND_CREATE_USER etc. |
|
| 121 | - */ |
|
| 122 | - public function implementsActions($actions) { |
|
| 123 | - //it's the same across all our user backends obviously |
|
| 124 | - return $this->refBackend->implementsActions($actions); |
|
| 125 | - } |
|
| 114 | + /** |
|
| 115 | + * Check if backend implements actions |
|
| 116 | + * @param int $actions bitwise-or'ed actions |
|
| 117 | + * @return boolean |
|
| 118 | + * |
|
| 119 | + * Returns the supported actions as int to be |
|
| 120 | + * compared with OC_USER_BACKEND_CREATE_USER etc. |
|
| 121 | + */ |
|
| 122 | + public function implementsActions($actions) { |
|
| 123 | + //it's the same across all our user backends obviously |
|
| 124 | + return $this->refBackend->implementsActions($actions); |
|
| 125 | + } |
|
| 126 | 126 | |
| 127 | - /** |
|
| 128 | - * Backend name to be shown in user management |
|
| 129 | - * @return string the name of the backend to be shown |
|
| 130 | - */ |
|
| 131 | - public function getBackendName() { |
|
| 132 | - return $this->refBackend->getBackendName(); |
|
| 133 | - } |
|
| 127 | + /** |
|
| 128 | + * Backend name to be shown in user management |
|
| 129 | + * @return string the name of the backend to be shown |
|
| 130 | + */ |
|
| 131 | + public function getBackendName() { |
|
| 132 | + return $this->refBackend->getBackendName(); |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | - /** |
|
| 136 | - * Get a list of all users |
|
| 137 | - * |
|
| 138 | - * @param string $search |
|
| 139 | - * @param null|int $limit |
|
| 140 | - * @param null|int $offset |
|
| 141 | - * @return string[] an array of all uids |
|
| 142 | - */ |
|
| 143 | - public function getUsers($search = '', $limit = 10, $offset = 0) { |
|
| 144 | - //we do it just as the /OC_User implementation: do not play around with limit and offset but ask all backends |
|
| 145 | - $users = array(); |
|
| 146 | - foreach($this->backends as $backend) { |
|
| 147 | - $backendUsers = $backend->getUsers($search, $limit, $offset); |
|
| 148 | - if (is_array($backendUsers)) { |
|
| 149 | - $users = array_merge($users, $backendUsers); |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - return $users; |
|
| 153 | - } |
|
| 135 | + /** |
|
| 136 | + * Get a list of all users |
|
| 137 | + * |
|
| 138 | + * @param string $search |
|
| 139 | + * @param null|int $limit |
|
| 140 | + * @param null|int $offset |
|
| 141 | + * @return string[] an array of all uids |
|
| 142 | + */ |
|
| 143 | + public function getUsers($search = '', $limit = 10, $offset = 0) { |
|
| 144 | + //we do it just as the /OC_User implementation: do not play around with limit and offset but ask all backends |
|
| 145 | + $users = array(); |
|
| 146 | + foreach($this->backends as $backend) { |
|
| 147 | + $backendUsers = $backend->getUsers($search, $limit, $offset); |
|
| 148 | + if (is_array($backendUsers)) { |
|
| 149 | + $users = array_merge($users, $backendUsers); |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + return $users; |
|
| 153 | + } |
|
| 154 | 154 | |
| 155 | - /** |
|
| 156 | - * check if a user exists |
|
| 157 | - * @param string $uid the username |
|
| 158 | - * @return boolean |
|
| 159 | - */ |
|
| 160 | - public function userExists($uid) { |
|
| 161 | - return $this->handleRequest($uid, 'userExists', array($uid)); |
|
| 162 | - } |
|
| 155 | + /** |
|
| 156 | + * check if a user exists |
|
| 157 | + * @param string $uid the username |
|
| 158 | + * @return boolean |
|
| 159 | + */ |
|
| 160 | + public function userExists($uid) { |
|
| 161 | + return $this->handleRequest($uid, 'userExists', array($uid)); |
|
| 162 | + } |
|
| 163 | 163 | |
| 164 | - /** |
|
| 165 | - * check if a user exists on LDAP |
|
| 166 | - * @param string|\OCA\User_LDAP\User\User $user either the ownCloud user |
|
| 167 | - * name or an instance of that user |
|
| 168 | - * @return boolean |
|
| 169 | - */ |
|
| 170 | - public function userExistsOnLDAP($user) { |
|
| 171 | - $id = ($user instanceof User) ? $user->getUsername() : $user; |
|
| 172 | - return $this->handleRequest($id, 'userExistsOnLDAP', array($user)); |
|
| 173 | - } |
|
| 164 | + /** |
|
| 165 | + * check if a user exists on LDAP |
|
| 166 | + * @param string|\OCA\User_LDAP\User\User $user either the ownCloud user |
|
| 167 | + * name or an instance of that user |
|
| 168 | + * @return boolean |
|
| 169 | + */ |
|
| 170 | + public function userExistsOnLDAP($user) { |
|
| 171 | + $id = ($user instanceof User) ? $user->getUsername() : $user; |
|
| 172 | + return $this->handleRequest($id, 'userExistsOnLDAP', array($user)); |
|
| 173 | + } |
|
| 174 | 174 | |
| 175 | - /** |
|
| 176 | - * Check if the password is correct |
|
| 177 | - * @param string $uid The username |
|
| 178 | - * @param string $password The password |
|
| 179 | - * @return bool |
|
| 180 | - * |
|
| 181 | - * Check if the password is correct without logging in the user |
|
| 182 | - */ |
|
| 183 | - public function checkPassword($uid, $password) { |
|
| 184 | - return $this->handleRequest($uid, 'checkPassword', array($uid, $password)); |
|
| 185 | - } |
|
| 175 | + /** |
|
| 176 | + * Check if the password is correct |
|
| 177 | + * @param string $uid The username |
|
| 178 | + * @param string $password The password |
|
| 179 | + * @return bool |
|
| 180 | + * |
|
| 181 | + * Check if the password is correct without logging in the user |
|
| 182 | + */ |
|
| 183 | + public function checkPassword($uid, $password) { |
|
| 184 | + return $this->handleRequest($uid, 'checkPassword', array($uid, $password)); |
|
| 185 | + } |
|
| 186 | 186 | |
| 187 | - /** |
|
| 188 | - * returns the username for the given login name, if available |
|
| 189 | - * |
|
| 190 | - * @param string $loginName |
|
| 191 | - * @return string|false |
|
| 192 | - */ |
|
| 193 | - public function loginName2UserName($loginName) { |
|
| 194 | - $id = 'LOGINNAME,' . $loginName; |
|
| 195 | - return $this->handleRequest($id, 'loginName2UserName', array($loginName)); |
|
| 196 | - } |
|
| 187 | + /** |
|
| 188 | + * returns the username for the given login name, if available |
|
| 189 | + * |
|
| 190 | + * @param string $loginName |
|
| 191 | + * @return string|false |
|
| 192 | + */ |
|
| 193 | + public function loginName2UserName($loginName) { |
|
| 194 | + $id = 'LOGINNAME,' . $loginName; |
|
| 195 | + return $this->handleRequest($id, 'loginName2UserName', array($loginName)); |
|
| 196 | + } |
|
| 197 | 197 | |
| 198 | - /** |
|
| 199 | - * returns the username for the given LDAP DN, if available |
|
| 200 | - * |
|
| 201 | - * @param string $dn |
|
| 202 | - * @return string|false with the username |
|
| 203 | - */ |
|
| 204 | - public function dn2UserName($dn) { |
|
| 205 | - $id = 'DN,' . $dn; |
|
| 206 | - return $this->handleRequest($id, 'dn2UserName', array($dn)); |
|
| 207 | - } |
|
| 198 | + /** |
|
| 199 | + * returns the username for the given LDAP DN, if available |
|
| 200 | + * |
|
| 201 | + * @param string $dn |
|
| 202 | + * @return string|false with the username |
|
| 203 | + */ |
|
| 204 | + public function dn2UserName($dn) { |
|
| 205 | + $id = 'DN,' . $dn; |
|
| 206 | + return $this->handleRequest($id, 'dn2UserName', array($dn)); |
|
| 207 | + } |
|
| 208 | 208 | |
| 209 | - /** |
|
| 210 | - * get the user's home directory |
|
| 211 | - * @param string $uid the username |
|
| 212 | - * @return boolean |
|
| 213 | - */ |
|
| 214 | - public function getHome($uid) { |
|
| 215 | - return $this->handleRequest($uid, 'getHome', array($uid)); |
|
| 216 | - } |
|
| 209 | + /** |
|
| 210 | + * get the user's home directory |
|
| 211 | + * @param string $uid the username |
|
| 212 | + * @return boolean |
|
| 213 | + */ |
|
| 214 | + public function getHome($uid) { |
|
| 215 | + return $this->handleRequest($uid, 'getHome', array($uid)); |
|
| 216 | + } |
|
| 217 | 217 | |
| 218 | - /** |
|
| 219 | - * get display name of the user |
|
| 220 | - * @param string $uid user ID of the user |
|
| 221 | - * @return string display name |
|
| 222 | - */ |
|
| 223 | - public function getDisplayName($uid) { |
|
| 224 | - return $this->handleRequest($uid, 'getDisplayName', array($uid)); |
|
| 225 | - } |
|
| 218 | + /** |
|
| 219 | + * get display name of the user |
|
| 220 | + * @param string $uid user ID of the user |
|
| 221 | + * @return string display name |
|
| 222 | + */ |
|
| 223 | + public function getDisplayName($uid) { |
|
| 224 | + return $this->handleRequest($uid, 'getDisplayName', array($uid)); |
|
| 225 | + } |
|
| 226 | 226 | |
| 227 | - /** |
|
| 228 | - * checks whether the user is allowed to change his avatar in ownCloud |
|
| 229 | - * @param string $uid the ownCloud user name |
|
| 230 | - * @return boolean either the user can or cannot |
|
| 231 | - */ |
|
| 232 | - public function canChangeAvatar($uid) { |
|
| 233 | - return $this->handleRequest($uid, 'canChangeAvatar', array($uid), true); |
|
| 234 | - } |
|
| 227 | + /** |
|
| 228 | + * checks whether the user is allowed to change his avatar in ownCloud |
|
| 229 | + * @param string $uid the ownCloud user name |
|
| 230 | + * @return boolean either the user can or cannot |
|
| 231 | + */ |
|
| 232 | + public function canChangeAvatar($uid) { |
|
| 233 | + return $this->handleRequest($uid, 'canChangeAvatar', array($uid), true); |
|
| 234 | + } |
|
| 235 | 235 | |
| 236 | - /** |
|
| 237 | - * Get a list of all display names and user ids. |
|
| 238 | - * @param string $search |
|
| 239 | - * @param string|null $limit |
|
| 240 | - * @param string|null $offset |
|
| 241 | - * @return array an array of all displayNames (value) and the corresponding uids (key) |
|
| 242 | - */ |
|
| 243 | - public function getDisplayNames($search = '', $limit = null, $offset = null) { |
|
| 244 | - //we do it just as the /OC_User implementation: do not play around with limit and offset but ask all backends |
|
| 245 | - $users = array(); |
|
| 246 | - foreach($this->backends as $backend) { |
|
| 247 | - $backendUsers = $backend->getDisplayNames($search, $limit, $offset); |
|
| 248 | - if (is_array($backendUsers)) { |
|
| 249 | - $users = $users + $backendUsers; |
|
| 250 | - } |
|
| 251 | - } |
|
| 252 | - return $users; |
|
| 253 | - } |
|
| 236 | + /** |
|
| 237 | + * Get a list of all display names and user ids. |
|
| 238 | + * @param string $search |
|
| 239 | + * @param string|null $limit |
|
| 240 | + * @param string|null $offset |
|
| 241 | + * @return array an array of all displayNames (value) and the corresponding uids (key) |
|
| 242 | + */ |
|
| 243 | + public function getDisplayNames($search = '', $limit = null, $offset = null) { |
|
| 244 | + //we do it just as the /OC_User implementation: do not play around with limit and offset but ask all backends |
|
| 245 | + $users = array(); |
|
| 246 | + foreach($this->backends as $backend) { |
|
| 247 | + $backendUsers = $backend->getDisplayNames($search, $limit, $offset); |
|
| 248 | + if (is_array($backendUsers)) { |
|
| 249 | + $users = $users + $backendUsers; |
|
| 250 | + } |
|
| 251 | + } |
|
| 252 | + return $users; |
|
| 253 | + } |
|
| 254 | 254 | |
| 255 | - /** |
|
| 256 | - * delete a user |
|
| 257 | - * @param string $uid The username of the user to delete |
|
| 258 | - * @return bool |
|
| 259 | - * |
|
| 260 | - * Deletes a user |
|
| 261 | - */ |
|
| 262 | - public function deleteUser($uid) { |
|
| 263 | - return $this->handleRequest($uid, 'deleteUser', array($uid)); |
|
| 264 | - } |
|
| 255 | + /** |
|
| 256 | + * delete a user |
|
| 257 | + * @param string $uid The username of the user to delete |
|
| 258 | + * @return bool |
|
| 259 | + * |
|
| 260 | + * Deletes a user |
|
| 261 | + */ |
|
| 262 | + public function deleteUser($uid) { |
|
| 263 | + return $this->handleRequest($uid, 'deleteUser', array($uid)); |
|
| 264 | + } |
|
| 265 | 265 | |
| 266 | - /** |
|
| 267 | - * Set password |
|
| 268 | - * @param string $uid The username |
|
| 269 | - * @param string $password The new password |
|
| 270 | - * @return bool |
|
| 271 | - * |
|
| 272 | - */ |
|
| 273 | - public function setPassword($uid, $password) { |
|
| 274 | - return $this->handleRequest($uid, 'setPassword', array($uid, $password)); |
|
| 275 | - } |
|
| 266 | + /** |
|
| 267 | + * Set password |
|
| 268 | + * @param string $uid The username |
|
| 269 | + * @param string $password The new password |
|
| 270 | + * @return bool |
|
| 271 | + * |
|
| 272 | + */ |
|
| 273 | + public function setPassword($uid, $password) { |
|
| 274 | + return $this->handleRequest($uid, 'setPassword', array($uid, $password)); |
|
| 275 | + } |
|
| 276 | 276 | |
| 277 | - /** |
|
| 278 | - * @return bool |
|
| 279 | - */ |
|
| 280 | - public function hasUserListings() { |
|
| 281 | - return $this->refBackend->hasUserListings(); |
|
| 282 | - } |
|
| 277 | + /** |
|
| 278 | + * @return bool |
|
| 279 | + */ |
|
| 280 | + public function hasUserListings() { |
|
| 281 | + return $this->refBackend->hasUserListings(); |
|
| 282 | + } |
|
| 283 | 283 | |
| 284 | - /** |
|
| 285 | - * Count the number of users |
|
| 286 | - * @return int|bool |
|
| 287 | - */ |
|
| 288 | - public function countUsers() { |
|
| 289 | - $users = false; |
|
| 290 | - foreach($this->backends as $backend) { |
|
| 291 | - $backendUsers = $backend->countUsers(); |
|
| 292 | - if ($backendUsers !== false) { |
|
| 293 | - $users += $backendUsers; |
|
| 294 | - } |
|
| 295 | - } |
|
| 296 | - return $users; |
|
| 297 | - } |
|
| 284 | + /** |
|
| 285 | + * Count the number of users |
|
| 286 | + * @return int|bool |
|
| 287 | + */ |
|
| 288 | + public function countUsers() { |
|
| 289 | + $users = false; |
|
| 290 | + foreach($this->backends as $backend) { |
|
| 291 | + $backendUsers = $backend->countUsers(); |
|
| 292 | + if ($backendUsers !== false) { |
|
| 293 | + $users += $backendUsers; |
|
| 294 | + } |
|
| 295 | + } |
|
| 296 | + return $users; |
|
| 297 | + } |
|
| 298 | 298 | |
| 299 | - /** |
|
| 300 | - * Return access for LDAP interaction. |
|
| 301 | - * @param string $uid |
|
| 302 | - * @return Access instance of Access for LDAP interaction |
|
| 303 | - */ |
|
| 304 | - public function getLDAPAccess($uid) { |
|
| 305 | - return $this->handleRequest($uid, 'getLDAPAccess', array($uid)); |
|
| 306 | - } |
|
| 299 | + /** |
|
| 300 | + * Return access for LDAP interaction. |
|
| 301 | + * @param string $uid |
|
| 302 | + * @return Access instance of Access for LDAP interaction |
|
| 303 | + */ |
|
| 304 | + public function getLDAPAccess($uid) { |
|
| 305 | + return $this->handleRequest($uid, 'getLDAPAccess', array($uid)); |
|
| 306 | + } |
|
| 307 | 307 | |
| 308 | - /** |
|
| 309 | - * Return a new LDAP connection for the specified user. |
|
| 310 | - * The connection needs to be closed manually. |
|
| 311 | - * @param string $uid |
|
| 312 | - * @return resource of the LDAP connection |
|
| 313 | - */ |
|
| 314 | - public function getNewLDAPConnection($uid) { |
|
| 315 | - return $this->handleRequest($uid, 'getNewLDAPConnection', array($uid)); |
|
| 316 | - } |
|
| 308 | + /** |
|
| 309 | + * Return a new LDAP connection for the specified user. |
|
| 310 | + * The connection needs to be closed manually. |
|
| 311 | + * @param string $uid |
|
| 312 | + * @return resource of the LDAP connection |
|
| 313 | + */ |
|
| 314 | + public function getNewLDAPConnection($uid) { |
|
| 315 | + return $this->handleRequest($uid, 'getNewLDAPConnection', array($uid)); |
|
| 316 | + } |
|
| 317 | 317 | } |
@@ -42,10 +42,10 @@ discard block |
||
| 42 | 42 | */ |
| 43 | 43 | public function __construct(array $serverConfigPrefixes, ILDAPWrapper $ldap, IConfig $ocConfig) { |
| 44 | 44 | parent::__construct($ldap); |
| 45 | - foreach($serverConfigPrefixes as $configPrefix) { |
|
| 45 | + foreach ($serverConfigPrefixes as $configPrefix) { |
|
| 46 | 46 | $this->backends[$configPrefix] = |
| 47 | 47 | new User_LDAP($this->getAccess($configPrefix), $ocConfig); |
| 48 | - if(is_null($this->refBackend)) { |
|
| 48 | + if (is_null($this->refBackend)) { |
|
| 49 | 49 | $this->refBackend = &$this->backends[$configPrefix]; |
| 50 | 50 | } |
| 51 | 51 | } |
@@ -60,13 +60,13 @@ discard block |
||
| 60 | 60 | */ |
| 61 | 61 | protected function walkBackends($uid, $method, $parameters) { |
| 62 | 62 | $cacheKey = $this->getUserCacheKey($uid); |
| 63 | - foreach($this->backends as $configPrefix => $backend) { |
|
| 63 | + foreach ($this->backends as $configPrefix => $backend) { |
|
| 64 | 64 | $instance = $backend; |
| 65 | - if(!method_exists($instance, $method) |
|
| 65 | + if (!method_exists($instance, $method) |
|
| 66 | 66 | && method_exists($this->getAccess($configPrefix), $method)) { |
| 67 | 67 | $instance = $this->getAccess($configPrefix); |
| 68 | 68 | } |
| 69 | - if($result = call_user_func_array(array($instance, $method), $parameters)) { |
|
| 69 | + if ($result = call_user_func_array(array($instance, $method), $parameters)) { |
|
| 70 | 70 | $this->writeToCache($cacheKey, $configPrefix); |
| 71 | 71 | return $result; |
| 72 | 72 | } |
@@ -86,22 +86,22 @@ discard block |
||
| 86 | 86 | $cacheKey = $this->getUserCacheKey($uid); |
| 87 | 87 | $prefix = $this->getFromCache($cacheKey); |
| 88 | 88 | //in case the uid has been found in the past, try this stored connection first |
| 89 | - if(!is_null($prefix)) { |
|
| 90 | - if(isset($this->backends[$prefix])) { |
|
| 89 | + if (!is_null($prefix)) { |
|
| 90 | + if (isset($this->backends[$prefix])) { |
|
| 91 | 91 | $instance = $this->backends[$prefix]; |
| 92 | - if(!method_exists($instance, $method) |
|
| 92 | + if (!method_exists($instance, $method) |
|
| 93 | 93 | && method_exists($this->getAccess($prefix), $method)) { |
| 94 | 94 | $instance = $this->getAccess($prefix); |
| 95 | 95 | } |
| 96 | 96 | $result = call_user_func_array(array($instance, $method), $parameters); |
| 97 | - if($result === $passOnWhen) { |
|
| 97 | + if ($result === $passOnWhen) { |
|
| 98 | 98 | //not found here, reset cache to null if user vanished |
| 99 | 99 | //because sometimes methods return false with a reason |
| 100 | 100 | $userExists = call_user_func_array( |
| 101 | 101 | array($this->backends[$prefix], 'userExists'), |
| 102 | 102 | array($uid) |
| 103 | 103 | ); |
| 104 | - if(!$userExists) { |
|
| 104 | + if (!$userExists) { |
|
| 105 | 105 | $this->writeToCache($cacheKey, null); |
| 106 | 106 | } |
| 107 | 107 | } |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | public function getUsers($search = '', $limit = 10, $offset = 0) { |
| 144 | 144 | //we do it just as the /OC_User implementation: do not play around with limit and offset but ask all backends |
| 145 | 145 | $users = array(); |
| 146 | - foreach($this->backends as $backend) { |
|
| 146 | + foreach ($this->backends as $backend) { |
|
| 147 | 147 | $backendUsers = $backend->getUsers($search, $limit, $offset); |
| 148 | 148 | if (is_array($backendUsers)) { |
| 149 | 149 | $users = array_merge($users, $backendUsers); |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | * @return string|false |
| 192 | 192 | */ |
| 193 | 193 | public function loginName2UserName($loginName) { |
| 194 | - $id = 'LOGINNAME,' . $loginName; |
|
| 194 | + $id = 'LOGINNAME,'.$loginName; |
|
| 195 | 195 | return $this->handleRequest($id, 'loginName2UserName', array($loginName)); |
| 196 | 196 | } |
| 197 | 197 | |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | * @return string|false with the username |
| 203 | 203 | */ |
| 204 | 204 | public function dn2UserName($dn) { |
| 205 | - $id = 'DN,' . $dn; |
|
| 205 | + $id = 'DN,'.$dn; |
|
| 206 | 206 | return $this->handleRequest($id, 'dn2UserName', array($dn)); |
| 207 | 207 | } |
| 208 | 208 | |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | public function getDisplayNames($search = '', $limit = null, $offset = null) { |
| 244 | 244 | //we do it just as the /OC_User implementation: do not play around with limit and offset but ask all backends |
| 245 | 245 | $users = array(); |
| 246 | - foreach($this->backends as $backend) { |
|
| 246 | + foreach ($this->backends as $backend) { |
|
| 247 | 247 | $backendUsers = $backend->getDisplayNames($search, $limit, $offset); |
| 248 | 248 | if (is_array($backendUsers)) { |
| 249 | 249 | $users = $users + $backendUsers; |
@@ -287,7 +287,7 @@ discard block |
||
| 287 | 287 | */ |
| 288 | 288 | public function countUsers() { |
| 289 | 289 | $users = false; |
| 290 | - foreach($this->backends as $backend) { |
|
| 290 | + foreach ($this->backends as $backend) { |
|
| 291 | 291 | $backendUsers = $backend->countUsers(); |
| 292 | 292 | if ($backendUsers !== false) { |
| 293 | 293 | $users += $backendUsers; |
@@ -51,569 +51,569 @@ |
||
| 51 | 51 | * @property string ldapUuidGroupAttribute |
| 52 | 52 | */ |
| 53 | 53 | class Connection extends LDAPUtility { |
| 54 | - private $ldapConnectionRes = null; |
|
| 55 | - private $configPrefix; |
|
| 56 | - private $configID; |
|
| 57 | - private $configured = false; |
|
| 58 | - private $hasPagedResultSupport = true; |
|
| 59 | - //whether connection should be kept on __destruct |
|
| 60 | - private $dontDestruct = false; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @var bool runtime flag that indicates whether supported primary groups are available |
|
| 64 | - */ |
|
| 65 | - public $hasPrimaryGroups = true; |
|
| 66 | - |
|
| 67 | - //cache handler |
|
| 68 | - protected $cache; |
|
| 69 | - |
|
| 70 | - /** @var Configuration settings handler **/ |
|
| 71 | - protected $configuration; |
|
| 72 | - |
|
| 73 | - protected $doNotValidate = false; |
|
| 74 | - |
|
| 75 | - protected $ignoreValidation = false; |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * Constructor |
|
| 79 | - * @param ILDAPWrapper $ldap |
|
| 80 | - * @param string $configPrefix a string with the prefix for the configkey column (appconfig table) |
|
| 81 | - * @param string|null $configID a string with the value for the appid column (appconfig table) or null for on-the-fly connections |
|
| 82 | - */ |
|
| 83 | - public function __construct(ILDAPWrapper $ldap, $configPrefix = '', $configID = 'user_ldap') { |
|
| 84 | - parent::__construct($ldap); |
|
| 85 | - $this->configPrefix = $configPrefix; |
|
| 86 | - $this->configID = $configID; |
|
| 87 | - $this->configuration = new Configuration($configPrefix, |
|
| 88 | - !is_null($configID)); |
|
| 89 | - $memcache = \OC::$server->getMemCacheFactory(); |
|
| 90 | - if($memcache->isAvailable()) { |
|
| 91 | - $this->cache = $memcache->create(); |
|
| 92 | - } |
|
| 93 | - $helper = new Helper(\OC::$server->getConfig()); |
|
| 94 | - $this->doNotValidate = !in_array($this->configPrefix, |
|
| 95 | - $helper->getServerConfigurationPrefixes()); |
|
| 96 | - $this->hasPagedResultSupport = |
|
| 97 | - intval($this->configuration->ldapPagingSize) !== 0 |
|
| 98 | - || $this->ldap->hasPagedResultSupport(); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - public function __destruct() { |
|
| 102 | - if(!$this->dontDestruct && $this->ldap->isResource($this->ldapConnectionRes)) { |
|
| 103 | - @$this->ldap->unbind($this->ldapConnectionRes); |
|
| 104 | - }; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * defines behaviour when the instance is cloned |
|
| 109 | - */ |
|
| 110 | - public function __clone() { |
|
| 111 | - $this->configuration = new Configuration($this->configPrefix, |
|
| 112 | - !is_null($this->configID)); |
|
| 113 | - $this->ldapConnectionRes = null; |
|
| 114 | - $this->dontDestruct = true; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * @param string $name |
|
| 119 | - * @return bool|mixed|void |
|
| 120 | - */ |
|
| 121 | - public function __get($name) { |
|
| 122 | - if(!$this->configured) { |
|
| 123 | - $this->readConfiguration(); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - if($name === 'hasPagedResultSupport') { |
|
| 127 | - return $this->hasPagedResultSupport; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - return $this->configuration->$name; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * @param string $name |
|
| 135 | - * @param mixed $value |
|
| 136 | - */ |
|
| 137 | - public function __set($name, $value) { |
|
| 138 | - $this->doNotValidate = false; |
|
| 139 | - $before = $this->configuration->$name; |
|
| 140 | - $this->configuration->$name = $value; |
|
| 141 | - $after = $this->configuration->$name; |
|
| 142 | - if($before !== $after) { |
|
| 143 | - if ($this->configID !== '') { |
|
| 144 | - $this->configuration->saveConfiguration(); |
|
| 145 | - } |
|
| 146 | - $this->validateConfiguration(); |
|
| 147 | - } |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * sets whether the result of the configuration validation shall |
|
| 152 | - * be ignored when establishing the connection. Used by the Wizard |
|
| 153 | - * in early configuration state. |
|
| 154 | - * @param bool $state |
|
| 155 | - */ |
|
| 156 | - public function setIgnoreValidation($state) { |
|
| 157 | - $this->ignoreValidation = (bool)$state; |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * initializes the LDAP backend |
|
| 162 | - * @param bool $force read the config settings no matter what |
|
| 163 | - */ |
|
| 164 | - public function init($force = false) { |
|
| 165 | - $this->readConfiguration($force); |
|
| 166 | - $this->establishConnection(); |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * Returns the LDAP handler |
|
| 171 | - */ |
|
| 172 | - public function getConnectionResource() { |
|
| 173 | - if(!$this->ldapConnectionRes) { |
|
| 174 | - $this->init(); |
|
| 175 | - } else if(!$this->ldap->isResource($this->ldapConnectionRes)) { |
|
| 176 | - $this->ldapConnectionRes = null; |
|
| 177 | - $this->establishConnection(); |
|
| 178 | - } |
|
| 179 | - if(is_null($this->ldapConnectionRes)) { |
|
| 180 | - \OCP\Util::writeLog('user_ldap', 'No LDAP Connection to server ' . $this->configuration->ldapHost, \OCP\Util::ERROR); |
|
| 181 | - throw new ServerNotAvailableException('Connection to LDAP server could not be established'); |
|
| 182 | - } |
|
| 183 | - return $this->ldapConnectionRes; |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * resets the connection resource |
|
| 188 | - */ |
|
| 189 | - public function resetConnectionResource() { |
|
| 190 | - if(!is_null($this->ldapConnectionRes)) { |
|
| 191 | - @$this->ldap->unbind($this->ldapConnectionRes); |
|
| 192 | - $this->ldapConnectionRes = null; |
|
| 193 | - } |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - /** |
|
| 197 | - * @param string|null $key |
|
| 198 | - * @return string |
|
| 199 | - */ |
|
| 200 | - private function getCacheKey($key) { |
|
| 201 | - $prefix = 'LDAP-'.$this->configID.'-'.$this->configPrefix.'-'; |
|
| 202 | - if(is_null($key)) { |
|
| 203 | - return $prefix; |
|
| 204 | - } |
|
| 205 | - return $prefix.md5($key); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * @param string $key |
|
| 210 | - * @return mixed|null |
|
| 211 | - */ |
|
| 212 | - public function getFromCache($key) { |
|
| 213 | - if(!$this->configured) { |
|
| 214 | - $this->readConfiguration(); |
|
| 215 | - } |
|
| 216 | - if(is_null($this->cache) || !$this->configuration->ldapCacheTTL) { |
|
| 217 | - return null; |
|
| 218 | - } |
|
| 219 | - $key = $this->getCacheKey($key); |
|
| 220 | - |
|
| 221 | - return json_decode(base64_decode($this->cache->get($key)), true); |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - /** |
|
| 225 | - * @param string $key |
|
| 226 | - * @param mixed $value |
|
| 227 | - * |
|
| 228 | - * @return string |
|
| 229 | - */ |
|
| 230 | - public function writeToCache($key, $value) { |
|
| 231 | - if(!$this->configured) { |
|
| 232 | - $this->readConfiguration(); |
|
| 233 | - } |
|
| 234 | - if(is_null($this->cache) |
|
| 235 | - || !$this->configuration->ldapCacheTTL |
|
| 236 | - || !$this->configuration->ldapConfigurationActive) { |
|
| 237 | - return null; |
|
| 238 | - } |
|
| 239 | - $key = $this->getCacheKey($key); |
|
| 240 | - $value = base64_encode(json_encode($value)); |
|
| 241 | - $this->cache->set($key, $value, $this->configuration->ldapCacheTTL); |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - public function clearCache() { |
|
| 245 | - if(!is_null($this->cache)) { |
|
| 246 | - $this->cache->clear($this->getCacheKey(null)); |
|
| 247 | - } |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - /** |
|
| 251 | - * Caches the general LDAP configuration. |
|
| 252 | - * @param bool $force optional. true, if the re-read should be forced. defaults |
|
| 253 | - * to false. |
|
| 254 | - * @return null |
|
| 255 | - */ |
|
| 256 | - private function readConfiguration($force = false) { |
|
| 257 | - if((!$this->configured || $force) && !is_null($this->configID)) { |
|
| 258 | - $this->configuration->readConfiguration(); |
|
| 259 | - $this->configured = $this->validateConfiguration(); |
|
| 260 | - } |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - /** |
|
| 264 | - * set LDAP configuration with values delivered by an array, not read from configuration |
|
| 265 | - * @param array $config array that holds the config parameters in an associated array |
|
| 266 | - * @param array &$setParameters optional; array where the set fields will be given to |
|
| 267 | - * @return boolean true if config validates, false otherwise. Check with $setParameters for detailed success on single parameters |
|
| 268 | - */ |
|
| 269 | - public function setConfiguration($config, &$setParameters = null) { |
|
| 270 | - if(is_null($setParameters)) { |
|
| 271 | - $setParameters = array(); |
|
| 272 | - } |
|
| 273 | - $this->doNotValidate = false; |
|
| 274 | - $this->configuration->setConfiguration($config, $setParameters); |
|
| 275 | - if(count($setParameters) > 0) { |
|
| 276 | - $this->configured = $this->validateConfiguration(); |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - |
|
| 280 | - return $this->configured; |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - /** |
|
| 284 | - * saves the current Configuration in the database and empties the |
|
| 285 | - * cache |
|
| 286 | - * @return null |
|
| 287 | - */ |
|
| 288 | - public function saveConfiguration() { |
|
| 289 | - $this->configuration->saveConfiguration(); |
|
| 290 | - $this->clearCache(); |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - /** |
|
| 294 | - * get the current LDAP configuration |
|
| 295 | - * @return array |
|
| 296 | - */ |
|
| 297 | - public function getConfiguration() { |
|
| 298 | - $this->readConfiguration(); |
|
| 299 | - $config = $this->configuration->getConfiguration(); |
|
| 300 | - $cta = $this->configuration->getConfigTranslationArray(); |
|
| 301 | - $result = array(); |
|
| 302 | - foreach($cta as $dbkey => $configkey) { |
|
| 303 | - switch($configkey) { |
|
| 304 | - case 'homeFolderNamingRule': |
|
| 305 | - if(strpos($config[$configkey], 'attr:') === 0) { |
|
| 306 | - $result[$dbkey] = substr($config[$configkey], 5); |
|
| 307 | - } else { |
|
| 308 | - $result[$dbkey] = ''; |
|
| 309 | - } |
|
| 310 | - break; |
|
| 311 | - case 'ldapBase': |
|
| 312 | - case 'ldapBaseUsers': |
|
| 313 | - case 'ldapBaseGroups': |
|
| 314 | - case 'ldapAttributesForUserSearch': |
|
| 315 | - case 'ldapAttributesForGroupSearch': |
|
| 316 | - if(is_array($config[$configkey])) { |
|
| 317 | - $result[$dbkey] = implode("\n", $config[$configkey]); |
|
| 318 | - break; |
|
| 319 | - } //else follows default |
|
| 320 | - default: |
|
| 321 | - $result[$dbkey] = $config[$configkey]; |
|
| 322 | - } |
|
| 323 | - } |
|
| 324 | - return $result; |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - private function doSoftValidation() { |
|
| 328 | - //if User or Group Base are not set, take over Base DN setting |
|
| 329 | - foreach(array('ldapBaseUsers', 'ldapBaseGroups') as $keyBase) { |
|
| 330 | - $val = $this->configuration->$keyBase; |
|
| 331 | - if(empty($val)) { |
|
| 332 | - $this->configuration->$keyBase = $this->configuration->ldapBase; |
|
| 333 | - } |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - foreach(array('ldapExpertUUIDUserAttr' => 'ldapUuidUserAttribute', |
|
| 337 | - 'ldapExpertUUIDGroupAttr' => 'ldapUuidGroupAttribute') |
|
| 338 | - as $expertSetting => $effectiveSetting) { |
|
| 339 | - $uuidOverride = $this->configuration->$expertSetting; |
|
| 340 | - if(!empty($uuidOverride)) { |
|
| 341 | - $this->configuration->$effectiveSetting = $uuidOverride; |
|
| 342 | - } else { |
|
| 343 | - $uuidAttributes = array('auto', 'entryuuid', 'nsuniqueid', |
|
| 344 | - 'objectguid', 'guid', 'ipauniqueid'); |
|
| 345 | - if(!in_array($this->configuration->$effectiveSetting, |
|
| 346 | - $uuidAttributes) |
|
| 347 | - && (!is_null($this->configID))) { |
|
| 348 | - $this->configuration->$effectiveSetting = 'auto'; |
|
| 349 | - $this->configuration->saveConfiguration(); |
|
| 350 | - \OCP\Util::writeLog('user_ldap', |
|
| 351 | - 'Illegal value for the '. |
|
| 352 | - $effectiveSetting.', '.'reset to '. |
|
| 353 | - 'autodetect.', \OCP\Util::INFO); |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - } |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - $backupPort = intval($this->configuration->ldapBackupPort); |
|
| 360 | - if ($backupPort <= 0) { |
|
| 361 | - $this->configuration->backupPort = $this->configuration->ldapPort; |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - //make sure empty search attributes are saved as simple, empty array |
|
| 365 | - $saKeys = array('ldapAttributesForUserSearch', |
|
| 366 | - 'ldapAttributesForGroupSearch'); |
|
| 367 | - foreach($saKeys as $key) { |
|
| 368 | - $val = $this->configuration->$key; |
|
| 369 | - if(is_array($val) && count($val) === 1 && empty($val[0])) { |
|
| 370 | - $this->configuration->$key = array(); |
|
| 371 | - } |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - if((stripos($this->configuration->ldapHost, 'ldaps://') === 0) |
|
| 375 | - && $this->configuration->ldapTLS) { |
|
| 376 | - $this->configuration->ldapTLS = false; |
|
| 377 | - \OCP\Util::writeLog('user_ldap', |
|
| 378 | - 'LDAPS (already using secure connection) and '. |
|
| 379 | - 'TLS do not work together. Switched off TLS.', |
|
| 380 | - \OCP\Util::INFO); |
|
| 381 | - } |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - /** |
|
| 385 | - * @return bool |
|
| 386 | - */ |
|
| 387 | - private function doCriticalValidation() { |
|
| 388 | - $configurationOK = true; |
|
| 389 | - $errorStr = 'Configuration Error (prefix '. |
|
| 390 | - strval($this->configPrefix).'): '; |
|
| 391 | - |
|
| 392 | - //options that shall not be empty |
|
| 393 | - $options = array('ldapHost', 'ldapPort', 'ldapUserDisplayName', |
|
| 394 | - 'ldapGroupDisplayName', 'ldapLoginFilter'); |
|
| 395 | - foreach($options as $key) { |
|
| 396 | - $val = $this->configuration->$key; |
|
| 397 | - if(empty($val)) { |
|
| 398 | - switch($key) { |
|
| 399 | - case 'ldapHost': |
|
| 400 | - $subj = 'LDAP Host'; |
|
| 401 | - break; |
|
| 402 | - case 'ldapPort': |
|
| 403 | - $subj = 'LDAP Port'; |
|
| 404 | - break; |
|
| 405 | - case 'ldapUserDisplayName': |
|
| 406 | - $subj = 'LDAP User Display Name'; |
|
| 407 | - break; |
|
| 408 | - case 'ldapGroupDisplayName': |
|
| 409 | - $subj = 'LDAP Group Display Name'; |
|
| 410 | - break; |
|
| 411 | - case 'ldapLoginFilter': |
|
| 412 | - $subj = 'LDAP Login Filter'; |
|
| 413 | - break; |
|
| 414 | - default: |
|
| 415 | - $subj = $key; |
|
| 416 | - break; |
|
| 417 | - } |
|
| 418 | - $configurationOK = false; |
|
| 419 | - \OCP\Util::writeLog('user_ldap', |
|
| 420 | - $errorStr.'No '.$subj.' given!', |
|
| 421 | - \OCP\Util::WARN); |
|
| 422 | - } |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - //combinations |
|
| 426 | - $agent = $this->configuration->ldapAgentName; |
|
| 427 | - $pwd = $this->configuration->ldapAgentPassword; |
|
| 428 | - if ( |
|
| 429 | - ($agent === '' && $pwd !== '') |
|
| 430 | - || ($agent !== '' && $pwd === '') |
|
| 431 | - ) { |
|
| 432 | - \OCP\Util::writeLog('user_ldap', |
|
| 433 | - $errorStr.'either no password is given for the'. |
|
| 434 | - 'user agent or a password is given, but not an'. |
|
| 435 | - 'LDAP agent.', |
|
| 436 | - \OCP\Util::WARN); |
|
| 437 | - $configurationOK = false; |
|
| 438 | - } |
|
| 439 | - |
|
| 440 | - $base = $this->configuration->ldapBase; |
|
| 441 | - $baseUsers = $this->configuration->ldapBaseUsers; |
|
| 442 | - $baseGroups = $this->configuration->ldapBaseGroups; |
|
| 443 | - |
|
| 444 | - if(empty($base) && empty($baseUsers) && empty($baseGroups)) { |
|
| 445 | - \OCP\Util::writeLog('user_ldap', |
|
| 446 | - $errorStr.'Not a single Base DN given.', |
|
| 447 | - \OCP\Util::WARN); |
|
| 448 | - $configurationOK = false; |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - if(mb_strpos($this->configuration->ldapLoginFilter, '%uid', 0, 'UTF-8') |
|
| 452 | - === false) { |
|
| 453 | - \OCP\Util::writeLog('user_ldap', |
|
| 454 | - $errorStr.'login filter does not contain %uid '. |
|
| 455 | - 'place holder.', |
|
| 456 | - \OCP\Util::WARN); |
|
| 457 | - $configurationOK = false; |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - return $configurationOK; |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - /** |
|
| 464 | - * Validates the user specified configuration |
|
| 465 | - * @return bool true if configuration seems OK, false otherwise |
|
| 466 | - */ |
|
| 467 | - private function validateConfiguration() { |
|
| 468 | - |
|
| 469 | - if($this->doNotValidate) { |
|
| 470 | - //don't do a validation if it is a new configuration with pure |
|
| 471 | - //default values. Will be allowed on changes via __set or |
|
| 472 | - //setConfiguration |
|
| 473 | - return false; |
|
| 474 | - } |
|
| 475 | - |
|
| 476 | - // first step: "soft" checks: settings that are not really |
|
| 477 | - // necessary, but advisable. If left empty, give an info message |
|
| 478 | - $this->doSoftValidation(); |
|
| 479 | - |
|
| 480 | - //second step: critical checks. If left empty or filled wrong, mark as |
|
| 481 | - //not configured and give a warning. |
|
| 482 | - return $this->doCriticalValidation(); |
|
| 483 | - } |
|
| 484 | - |
|
| 485 | - |
|
| 486 | - /** |
|
| 487 | - * Connects and Binds to LDAP |
|
| 488 | - */ |
|
| 489 | - private function establishConnection() { |
|
| 490 | - if(!$this->configuration->ldapConfigurationActive) { |
|
| 491 | - return null; |
|
| 492 | - } |
|
| 493 | - static $phpLDAPinstalled = true; |
|
| 494 | - if(!$phpLDAPinstalled) { |
|
| 495 | - return false; |
|
| 496 | - } |
|
| 497 | - if(!$this->ignoreValidation && !$this->configured) { |
|
| 498 | - \OCP\Util::writeLog('user_ldap', |
|
| 499 | - 'Configuration is invalid, cannot connect', |
|
| 500 | - \OCP\Util::WARN); |
|
| 501 | - return false; |
|
| 502 | - } |
|
| 503 | - if(!$this->ldapConnectionRes) { |
|
| 504 | - if(!$this->ldap->areLDAPFunctionsAvailable()) { |
|
| 505 | - $phpLDAPinstalled = false; |
|
| 506 | - \OCP\Util::writeLog('user_ldap', |
|
| 507 | - 'function ldap_connect is not available. Make '. |
|
| 508 | - 'sure that the PHP ldap module is installed.', |
|
| 509 | - \OCP\Util::ERROR); |
|
| 510 | - |
|
| 511 | - return false; |
|
| 512 | - } |
|
| 513 | - if($this->configuration->turnOffCertCheck) { |
|
| 514 | - if(putenv('LDAPTLS_REQCERT=never')) { |
|
| 515 | - \OCP\Util::writeLog('user_ldap', |
|
| 516 | - 'Turned off SSL certificate validation successfully.', |
|
| 517 | - \OCP\Util::DEBUG); |
|
| 518 | - } else { |
|
| 519 | - \OCP\Util::writeLog('user_ldap', |
|
| 520 | - 'Could not turn off SSL certificate validation.', |
|
| 521 | - \OCP\Util::WARN); |
|
| 522 | - } |
|
| 523 | - } |
|
| 524 | - |
|
| 525 | - $bindStatus = false; |
|
| 526 | - $error = -1; |
|
| 527 | - try { |
|
| 528 | - if (!$this->configuration->ldapOverrideMainServer |
|
| 529 | - && !$this->getFromCache('overrideMainServer') |
|
| 530 | - ) { |
|
| 531 | - $this->doConnect($this->configuration->ldapHost, |
|
| 532 | - $this->configuration->ldapPort); |
|
| 533 | - $bindStatus = $this->bind(); |
|
| 534 | - $error = $this->ldap->isResource($this->ldapConnectionRes) ? |
|
| 535 | - $this->ldap->errno($this->ldapConnectionRes) : -1; |
|
| 536 | - } |
|
| 537 | - if($bindStatus === true) { |
|
| 538 | - return $bindStatus; |
|
| 539 | - } |
|
| 540 | - } catch (\OC\ServerNotAvailableException $e) { |
|
| 541 | - if(trim($this->configuration->ldapBackupHost) === "") { |
|
| 542 | - throw $e; |
|
| 543 | - } |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - //if LDAP server is not reachable, try the Backup (Replica!) Server |
|
| 547 | - if( $error !== 0 |
|
| 548 | - || $this->configuration->ldapOverrideMainServer |
|
| 549 | - || $this->getFromCache('overrideMainServer')) |
|
| 550 | - { |
|
| 551 | - $this->doConnect($this->configuration->ldapBackupHost, |
|
| 552 | - $this->configuration->ldapBackupPort); |
|
| 553 | - $bindStatus = $this->bind(); |
|
| 554 | - if($bindStatus && $error === -1 && !$this->getFromCache('overrideMainServer')) { |
|
| 555 | - //when bind to backup server succeeded and failed to main server, |
|
| 556 | - //skip contacting him until next cache refresh |
|
| 557 | - $this->writeToCache('overrideMainServer', true); |
|
| 558 | - } |
|
| 559 | - } |
|
| 560 | - return $bindStatus; |
|
| 561 | - } |
|
| 562 | - return null; |
|
| 563 | - } |
|
| 564 | - |
|
| 565 | - /** |
|
| 566 | - * @param string $host |
|
| 567 | - * @param string $port |
|
| 568 | - * @return bool |
|
| 569 | - * @throws \OC\ServerNotAvailableException |
|
| 570 | - */ |
|
| 571 | - private function doConnect($host, $port) { |
|
| 572 | - if ($host === '') { |
|
| 573 | - return false; |
|
| 574 | - } |
|
| 575 | - $this->ldapConnectionRes = $this->ldap->connect($host, $port); |
|
| 576 | - if($this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_PROTOCOL_VERSION, 3)) { |
|
| 577 | - if($this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_REFERRALS, 0)) { |
|
| 578 | - if($this->configuration->ldapTLS) { |
|
| 579 | - $this->ldap->startTls($this->ldapConnectionRes); |
|
| 580 | - } |
|
| 581 | - } |
|
| 582 | - } else { |
|
| 583 | - throw new \OC\ServerNotAvailableException('Could not set required LDAP Protocol version.'); |
|
| 584 | - } |
|
| 585 | - return true; |
|
| 586 | - } |
|
| 587 | - |
|
| 588 | - /** |
|
| 589 | - * Binds to LDAP |
|
| 590 | - */ |
|
| 591 | - public function bind() { |
|
| 592 | - static $getConnectionResourceAttempt = false; |
|
| 593 | - if(!$this->configuration->ldapConfigurationActive) { |
|
| 594 | - return false; |
|
| 595 | - } |
|
| 596 | - if($getConnectionResourceAttempt) { |
|
| 597 | - $getConnectionResourceAttempt = false; |
|
| 598 | - return false; |
|
| 599 | - } |
|
| 600 | - $getConnectionResourceAttempt = true; |
|
| 601 | - $cr = $this->getConnectionResource(); |
|
| 602 | - $getConnectionResourceAttempt = false; |
|
| 603 | - if(!$this->ldap->isResource($cr)) { |
|
| 604 | - return false; |
|
| 605 | - } |
|
| 606 | - $ldapLogin = @$this->ldap->bind($cr, |
|
| 607 | - $this->configuration->ldapAgentName, |
|
| 608 | - $this->configuration->ldapAgentPassword); |
|
| 609 | - if(!$ldapLogin) { |
|
| 610 | - \OCP\Util::writeLog('user_ldap', |
|
| 611 | - 'Bind failed: ' . $this->ldap->errno($cr) . ': ' . $this->ldap->error($cr), |
|
| 612 | - \OCP\Util::WARN); |
|
| 613 | - $this->ldapConnectionRes = null; |
|
| 614 | - return false; |
|
| 615 | - } |
|
| 616 | - return true; |
|
| 617 | - } |
|
| 54 | + private $ldapConnectionRes = null; |
|
| 55 | + private $configPrefix; |
|
| 56 | + private $configID; |
|
| 57 | + private $configured = false; |
|
| 58 | + private $hasPagedResultSupport = true; |
|
| 59 | + //whether connection should be kept on __destruct |
|
| 60 | + private $dontDestruct = false; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @var bool runtime flag that indicates whether supported primary groups are available |
|
| 64 | + */ |
|
| 65 | + public $hasPrimaryGroups = true; |
|
| 66 | + |
|
| 67 | + //cache handler |
|
| 68 | + protected $cache; |
|
| 69 | + |
|
| 70 | + /** @var Configuration settings handler **/ |
|
| 71 | + protected $configuration; |
|
| 72 | + |
|
| 73 | + protected $doNotValidate = false; |
|
| 74 | + |
|
| 75 | + protected $ignoreValidation = false; |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * Constructor |
|
| 79 | + * @param ILDAPWrapper $ldap |
|
| 80 | + * @param string $configPrefix a string with the prefix for the configkey column (appconfig table) |
|
| 81 | + * @param string|null $configID a string with the value for the appid column (appconfig table) or null for on-the-fly connections |
|
| 82 | + */ |
|
| 83 | + public function __construct(ILDAPWrapper $ldap, $configPrefix = '', $configID = 'user_ldap') { |
|
| 84 | + parent::__construct($ldap); |
|
| 85 | + $this->configPrefix = $configPrefix; |
|
| 86 | + $this->configID = $configID; |
|
| 87 | + $this->configuration = new Configuration($configPrefix, |
|
| 88 | + !is_null($configID)); |
|
| 89 | + $memcache = \OC::$server->getMemCacheFactory(); |
|
| 90 | + if($memcache->isAvailable()) { |
|
| 91 | + $this->cache = $memcache->create(); |
|
| 92 | + } |
|
| 93 | + $helper = new Helper(\OC::$server->getConfig()); |
|
| 94 | + $this->doNotValidate = !in_array($this->configPrefix, |
|
| 95 | + $helper->getServerConfigurationPrefixes()); |
|
| 96 | + $this->hasPagedResultSupport = |
|
| 97 | + intval($this->configuration->ldapPagingSize) !== 0 |
|
| 98 | + || $this->ldap->hasPagedResultSupport(); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + public function __destruct() { |
|
| 102 | + if(!$this->dontDestruct && $this->ldap->isResource($this->ldapConnectionRes)) { |
|
| 103 | + @$this->ldap->unbind($this->ldapConnectionRes); |
|
| 104 | + }; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * defines behaviour when the instance is cloned |
|
| 109 | + */ |
|
| 110 | + public function __clone() { |
|
| 111 | + $this->configuration = new Configuration($this->configPrefix, |
|
| 112 | + !is_null($this->configID)); |
|
| 113 | + $this->ldapConnectionRes = null; |
|
| 114 | + $this->dontDestruct = true; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * @param string $name |
|
| 119 | + * @return bool|mixed|void |
|
| 120 | + */ |
|
| 121 | + public function __get($name) { |
|
| 122 | + if(!$this->configured) { |
|
| 123 | + $this->readConfiguration(); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + if($name === 'hasPagedResultSupport') { |
|
| 127 | + return $this->hasPagedResultSupport; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + return $this->configuration->$name; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * @param string $name |
|
| 135 | + * @param mixed $value |
|
| 136 | + */ |
|
| 137 | + public function __set($name, $value) { |
|
| 138 | + $this->doNotValidate = false; |
|
| 139 | + $before = $this->configuration->$name; |
|
| 140 | + $this->configuration->$name = $value; |
|
| 141 | + $after = $this->configuration->$name; |
|
| 142 | + if($before !== $after) { |
|
| 143 | + if ($this->configID !== '') { |
|
| 144 | + $this->configuration->saveConfiguration(); |
|
| 145 | + } |
|
| 146 | + $this->validateConfiguration(); |
|
| 147 | + } |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * sets whether the result of the configuration validation shall |
|
| 152 | + * be ignored when establishing the connection. Used by the Wizard |
|
| 153 | + * in early configuration state. |
|
| 154 | + * @param bool $state |
|
| 155 | + */ |
|
| 156 | + public function setIgnoreValidation($state) { |
|
| 157 | + $this->ignoreValidation = (bool)$state; |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * initializes the LDAP backend |
|
| 162 | + * @param bool $force read the config settings no matter what |
|
| 163 | + */ |
|
| 164 | + public function init($force = false) { |
|
| 165 | + $this->readConfiguration($force); |
|
| 166 | + $this->establishConnection(); |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * Returns the LDAP handler |
|
| 171 | + */ |
|
| 172 | + public function getConnectionResource() { |
|
| 173 | + if(!$this->ldapConnectionRes) { |
|
| 174 | + $this->init(); |
|
| 175 | + } else if(!$this->ldap->isResource($this->ldapConnectionRes)) { |
|
| 176 | + $this->ldapConnectionRes = null; |
|
| 177 | + $this->establishConnection(); |
|
| 178 | + } |
|
| 179 | + if(is_null($this->ldapConnectionRes)) { |
|
| 180 | + \OCP\Util::writeLog('user_ldap', 'No LDAP Connection to server ' . $this->configuration->ldapHost, \OCP\Util::ERROR); |
|
| 181 | + throw new ServerNotAvailableException('Connection to LDAP server could not be established'); |
|
| 182 | + } |
|
| 183 | + return $this->ldapConnectionRes; |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * resets the connection resource |
|
| 188 | + */ |
|
| 189 | + public function resetConnectionResource() { |
|
| 190 | + if(!is_null($this->ldapConnectionRes)) { |
|
| 191 | + @$this->ldap->unbind($this->ldapConnectionRes); |
|
| 192 | + $this->ldapConnectionRes = null; |
|
| 193 | + } |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + /** |
|
| 197 | + * @param string|null $key |
|
| 198 | + * @return string |
|
| 199 | + */ |
|
| 200 | + private function getCacheKey($key) { |
|
| 201 | + $prefix = 'LDAP-'.$this->configID.'-'.$this->configPrefix.'-'; |
|
| 202 | + if(is_null($key)) { |
|
| 203 | + return $prefix; |
|
| 204 | + } |
|
| 205 | + return $prefix.md5($key); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * @param string $key |
|
| 210 | + * @return mixed|null |
|
| 211 | + */ |
|
| 212 | + public function getFromCache($key) { |
|
| 213 | + if(!$this->configured) { |
|
| 214 | + $this->readConfiguration(); |
|
| 215 | + } |
|
| 216 | + if(is_null($this->cache) || !$this->configuration->ldapCacheTTL) { |
|
| 217 | + return null; |
|
| 218 | + } |
|
| 219 | + $key = $this->getCacheKey($key); |
|
| 220 | + |
|
| 221 | + return json_decode(base64_decode($this->cache->get($key)), true); |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + /** |
|
| 225 | + * @param string $key |
|
| 226 | + * @param mixed $value |
|
| 227 | + * |
|
| 228 | + * @return string |
|
| 229 | + */ |
|
| 230 | + public function writeToCache($key, $value) { |
|
| 231 | + if(!$this->configured) { |
|
| 232 | + $this->readConfiguration(); |
|
| 233 | + } |
|
| 234 | + if(is_null($this->cache) |
|
| 235 | + || !$this->configuration->ldapCacheTTL |
|
| 236 | + || !$this->configuration->ldapConfigurationActive) { |
|
| 237 | + return null; |
|
| 238 | + } |
|
| 239 | + $key = $this->getCacheKey($key); |
|
| 240 | + $value = base64_encode(json_encode($value)); |
|
| 241 | + $this->cache->set($key, $value, $this->configuration->ldapCacheTTL); |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + public function clearCache() { |
|
| 245 | + if(!is_null($this->cache)) { |
|
| 246 | + $this->cache->clear($this->getCacheKey(null)); |
|
| 247 | + } |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + /** |
|
| 251 | + * Caches the general LDAP configuration. |
|
| 252 | + * @param bool $force optional. true, if the re-read should be forced. defaults |
|
| 253 | + * to false. |
|
| 254 | + * @return null |
|
| 255 | + */ |
|
| 256 | + private function readConfiguration($force = false) { |
|
| 257 | + if((!$this->configured || $force) && !is_null($this->configID)) { |
|
| 258 | + $this->configuration->readConfiguration(); |
|
| 259 | + $this->configured = $this->validateConfiguration(); |
|
| 260 | + } |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + /** |
|
| 264 | + * set LDAP configuration with values delivered by an array, not read from configuration |
|
| 265 | + * @param array $config array that holds the config parameters in an associated array |
|
| 266 | + * @param array &$setParameters optional; array where the set fields will be given to |
|
| 267 | + * @return boolean true if config validates, false otherwise. Check with $setParameters for detailed success on single parameters |
|
| 268 | + */ |
|
| 269 | + public function setConfiguration($config, &$setParameters = null) { |
|
| 270 | + if(is_null($setParameters)) { |
|
| 271 | + $setParameters = array(); |
|
| 272 | + } |
|
| 273 | + $this->doNotValidate = false; |
|
| 274 | + $this->configuration->setConfiguration($config, $setParameters); |
|
| 275 | + if(count($setParameters) > 0) { |
|
| 276 | + $this->configured = $this->validateConfiguration(); |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + |
|
| 280 | + return $this->configured; |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + /** |
|
| 284 | + * saves the current Configuration in the database and empties the |
|
| 285 | + * cache |
|
| 286 | + * @return null |
|
| 287 | + */ |
|
| 288 | + public function saveConfiguration() { |
|
| 289 | + $this->configuration->saveConfiguration(); |
|
| 290 | + $this->clearCache(); |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + /** |
|
| 294 | + * get the current LDAP configuration |
|
| 295 | + * @return array |
|
| 296 | + */ |
|
| 297 | + public function getConfiguration() { |
|
| 298 | + $this->readConfiguration(); |
|
| 299 | + $config = $this->configuration->getConfiguration(); |
|
| 300 | + $cta = $this->configuration->getConfigTranslationArray(); |
|
| 301 | + $result = array(); |
|
| 302 | + foreach($cta as $dbkey => $configkey) { |
|
| 303 | + switch($configkey) { |
|
| 304 | + case 'homeFolderNamingRule': |
|
| 305 | + if(strpos($config[$configkey], 'attr:') === 0) { |
|
| 306 | + $result[$dbkey] = substr($config[$configkey], 5); |
|
| 307 | + } else { |
|
| 308 | + $result[$dbkey] = ''; |
|
| 309 | + } |
|
| 310 | + break; |
|
| 311 | + case 'ldapBase': |
|
| 312 | + case 'ldapBaseUsers': |
|
| 313 | + case 'ldapBaseGroups': |
|
| 314 | + case 'ldapAttributesForUserSearch': |
|
| 315 | + case 'ldapAttributesForGroupSearch': |
|
| 316 | + if(is_array($config[$configkey])) { |
|
| 317 | + $result[$dbkey] = implode("\n", $config[$configkey]); |
|
| 318 | + break; |
|
| 319 | + } //else follows default |
|
| 320 | + default: |
|
| 321 | + $result[$dbkey] = $config[$configkey]; |
|
| 322 | + } |
|
| 323 | + } |
|
| 324 | + return $result; |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + private function doSoftValidation() { |
|
| 328 | + //if User or Group Base are not set, take over Base DN setting |
|
| 329 | + foreach(array('ldapBaseUsers', 'ldapBaseGroups') as $keyBase) { |
|
| 330 | + $val = $this->configuration->$keyBase; |
|
| 331 | + if(empty($val)) { |
|
| 332 | + $this->configuration->$keyBase = $this->configuration->ldapBase; |
|
| 333 | + } |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + foreach(array('ldapExpertUUIDUserAttr' => 'ldapUuidUserAttribute', |
|
| 337 | + 'ldapExpertUUIDGroupAttr' => 'ldapUuidGroupAttribute') |
|
| 338 | + as $expertSetting => $effectiveSetting) { |
|
| 339 | + $uuidOverride = $this->configuration->$expertSetting; |
|
| 340 | + if(!empty($uuidOverride)) { |
|
| 341 | + $this->configuration->$effectiveSetting = $uuidOverride; |
|
| 342 | + } else { |
|
| 343 | + $uuidAttributes = array('auto', 'entryuuid', 'nsuniqueid', |
|
| 344 | + 'objectguid', 'guid', 'ipauniqueid'); |
|
| 345 | + if(!in_array($this->configuration->$effectiveSetting, |
|
| 346 | + $uuidAttributes) |
|
| 347 | + && (!is_null($this->configID))) { |
|
| 348 | + $this->configuration->$effectiveSetting = 'auto'; |
|
| 349 | + $this->configuration->saveConfiguration(); |
|
| 350 | + \OCP\Util::writeLog('user_ldap', |
|
| 351 | + 'Illegal value for the '. |
|
| 352 | + $effectiveSetting.', '.'reset to '. |
|
| 353 | + 'autodetect.', \OCP\Util::INFO); |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + } |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + $backupPort = intval($this->configuration->ldapBackupPort); |
|
| 360 | + if ($backupPort <= 0) { |
|
| 361 | + $this->configuration->backupPort = $this->configuration->ldapPort; |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + //make sure empty search attributes are saved as simple, empty array |
|
| 365 | + $saKeys = array('ldapAttributesForUserSearch', |
|
| 366 | + 'ldapAttributesForGroupSearch'); |
|
| 367 | + foreach($saKeys as $key) { |
|
| 368 | + $val = $this->configuration->$key; |
|
| 369 | + if(is_array($val) && count($val) === 1 && empty($val[0])) { |
|
| 370 | + $this->configuration->$key = array(); |
|
| 371 | + } |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + if((stripos($this->configuration->ldapHost, 'ldaps://') === 0) |
|
| 375 | + && $this->configuration->ldapTLS) { |
|
| 376 | + $this->configuration->ldapTLS = false; |
|
| 377 | + \OCP\Util::writeLog('user_ldap', |
|
| 378 | + 'LDAPS (already using secure connection) and '. |
|
| 379 | + 'TLS do not work together. Switched off TLS.', |
|
| 380 | + \OCP\Util::INFO); |
|
| 381 | + } |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + /** |
|
| 385 | + * @return bool |
|
| 386 | + */ |
|
| 387 | + private function doCriticalValidation() { |
|
| 388 | + $configurationOK = true; |
|
| 389 | + $errorStr = 'Configuration Error (prefix '. |
|
| 390 | + strval($this->configPrefix).'): '; |
|
| 391 | + |
|
| 392 | + //options that shall not be empty |
|
| 393 | + $options = array('ldapHost', 'ldapPort', 'ldapUserDisplayName', |
|
| 394 | + 'ldapGroupDisplayName', 'ldapLoginFilter'); |
|
| 395 | + foreach($options as $key) { |
|
| 396 | + $val = $this->configuration->$key; |
|
| 397 | + if(empty($val)) { |
|
| 398 | + switch($key) { |
|
| 399 | + case 'ldapHost': |
|
| 400 | + $subj = 'LDAP Host'; |
|
| 401 | + break; |
|
| 402 | + case 'ldapPort': |
|
| 403 | + $subj = 'LDAP Port'; |
|
| 404 | + break; |
|
| 405 | + case 'ldapUserDisplayName': |
|
| 406 | + $subj = 'LDAP User Display Name'; |
|
| 407 | + break; |
|
| 408 | + case 'ldapGroupDisplayName': |
|
| 409 | + $subj = 'LDAP Group Display Name'; |
|
| 410 | + break; |
|
| 411 | + case 'ldapLoginFilter': |
|
| 412 | + $subj = 'LDAP Login Filter'; |
|
| 413 | + break; |
|
| 414 | + default: |
|
| 415 | + $subj = $key; |
|
| 416 | + break; |
|
| 417 | + } |
|
| 418 | + $configurationOK = false; |
|
| 419 | + \OCP\Util::writeLog('user_ldap', |
|
| 420 | + $errorStr.'No '.$subj.' given!', |
|
| 421 | + \OCP\Util::WARN); |
|
| 422 | + } |
|
| 423 | + } |
|
| 424 | + |
|
| 425 | + //combinations |
|
| 426 | + $agent = $this->configuration->ldapAgentName; |
|
| 427 | + $pwd = $this->configuration->ldapAgentPassword; |
|
| 428 | + if ( |
|
| 429 | + ($agent === '' && $pwd !== '') |
|
| 430 | + || ($agent !== '' && $pwd === '') |
|
| 431 | + ) { |
|
| 432 | + \OCP\Util::writeLog('user_ldap', |
|
| 433 | + $errorStr.'either no password is given for the'. |
|
| 434 | + 'user agent or a password is given, but not an'. |
|
| 435 | + 'LDAP agent.', |
|
| 436 | + \OCP\Util::WARN); |
|
| 437 | + $configurationOK = false; |
|
| 438 | + } |
|
| 439 | + |
|
| 440 | + $base = $this->configuration->ldapBase; |
|
| 441 | + $baseUsers = $this->configuration->ldapBaseUsers; |
|
| 442 | + $baseGroups = $this->configuration->ldapBaseGroups; |
|
| 443 | + |
|
| 444 | + if(empty($base) && empty($baseUsers) && empty($baseGroups)) { |
|
| 445 | + \OCP\Util::writeLog('user_ldap', |
|
| 446 | + $errorStr.'Not a single Base DN given.', |
|
| 447 | + \OCP\Util::WARN); |
|
| 448 | + $configurationOK = false; |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + if(mb_strpos($this->configuration->ldapLoginFilter, '%uid', 0, 'UTF-8') |
|
| 452 | + === false) { |
|
| 453 | + \OCP\Util::writeLog('user_ldap', |
|
| 454 | + $errorStr.'login filter does not contain %uid '. |
|
| 455 | + 'place holder.', |
|
| 456 | + \OCP\Util::WARN); |
|
| 457 | + $configurationOK = false; |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + return $configurationOK; |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + /** |
|
| 464 | + * Validates the user specified configuration |
|
| 465 | + * @return bool true if configuration seems OK, false otherwise |
|
| 466 | + */ |
|
| 467 | + private function validateConfiguration() { |
|
| 468 | + |
|
| 469 | + if($this->doNotValidate) { |
|
| 470 | + //don't do a validation if it is a new configuration with pure |
|
| 471 | + //default values. Will be allowed on changes via __set or |
|
| 472 | + //setConfiguration |
|
| 473 | + return false; |
|
| 474 | + } |
|
| 475 | + |
|
| 476 | + // first step: "soft" checks: settings that are not really |
|
| 477 | + // necessary, but advisable. If left empty, give an info message |
|
| 478 | + $this->doSoftValidation(); |
|
| 479 | + |
|
| 480 | + //second step: critical checks. If left empty or filled wrong, mark as |
|
| 481 | + //not configured and give a warning. |
|
| 482 | + return $this->doCriticalValidation(); |
|
| 483 | + } |
|
| 484 | + |
|
| 485 | + |
|
| 486 | + /** |
|
| 487 | + * Connects and Binds to LDAP |
|
| 488 | + */ |
|
| 489 | + private function establishConnection() { |
|
| 490 | + if(!$this->configuration->ldapConfigurationActive) { |
|
| 491 | + return null; |
|
| 492 | + } |
|
| 493 | + static $phpLDAPinstalled = true; |
|
| 494 | + if(!$phpLDAPinstalled) { |
|
| 495 | + return false; |
|
| 496 | + } |
|
| 497 | + if(!$this->ignoreValidation && !$this->configured) { |
|
| 498 | + \OCP\Util::writeLog('user_ldap', |
|
| 499 | + 'Configuration is invalid, cannot connect', |
|
| 500 | + \OCP\Util::WARN); |
|
| 501 | + return false; |
|
| 502 | + } |
|
| 503 | + if(!$this->ldapConnectionRes) { |
|
| 504 | + if(!$this->ldap->areLDAPFunctionsAvailable()) { |
|
| 505 | + $phpLDAPinstalled = false; |
|
| 506 | + \OCP\Util::writeLog('user_ldap', |
|
| 507 | + 'function ldap_connect is not available. Make '. |
|
| 508 | + 'sure that the PHP ldap module is installed.', |
|
| 509 | + \OCP\Util::ERROR); |
|
| 510 | + |
|
| 511 | + return false; |
|
| 512 | + } |
|
| 513 | + if($this->configuration->turnOffCertCheck) { |
|
| 514 | + if(putenv('LDAPTLS_REQCERT=never')) { |
|
| 515 | + \OCP\Util::writeLog('user_ldap', |
|
| 516 | + 'Turned off SSL certificate validation successfully.', |
|
| 517 | + \OCP\Util::DEBUG); |
|
| 518 | + } else { |
|
| 519 | + \OCP\Util::writeLog('user_ldap', |
|
| 520 | + 'Could not turn off SSL certificate validation.', |
|
| 521 | + \OCP\Util::WARN); |
|
| 522 | + } |
|
| 523 | + } |
|
| 524 | + |
|
| 525 | + $bindStatus = false; |
|
| 526 | + $error = -1; |
|
| 527 | + try { |
|
| 528 | + if (!$this->configuration->ldapOverrideMainServer |
|
| 529 | + && !$this->getFromCache('overrideMainServer') |
|
| 530 | + ) { |
|
| 531 | + $this->doConnect($this->configuration->ldapHost, |
|
| 532 | + $this->configuration->ldapPort); |
|
| 533 | + $bindStatus = $this->bind(); |
|
| 534 | + $error = $this->ldap->isResource($this->ldapConnectionRes) ? |
|
| 535 | + $this->ldap->errno($this->ldapConnectionRes) : -1; |
|
| 536 | + } |
|
| 537 | + if($bindStatus === true) { |
|
| 538 | + return $bindStatus; |
|
| 539 | + } |
|
| 540 | + } catch (\OC\ServerNotAvailableException $e) { |
|
| 541 | + if(trim($this->configuration->ldapBackupHost) === "") { |
|
| 542 | + throw $e; |
|
| 543 | + } |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + //if LDAP server is not reachable, try the Backup (Replica!) Server |
|
| 547 | + if( $error !== 0 |
|
| 548 | + || $this->configuration->ldapOverrideMainServer |
|
| 549 | + || $this->getFromCache('overrideMainServer')) |
|
| 550 | + { |
|
| 551 | + $this->doConnect($this->configuration->ldapBackupHost, |
|
| 552 | + $this->configuration->ldapBackupPort); |
|
| 553 | + $bindStatus = $this->bind(); |
|
| 554 | + if($bindStatus && $error === -1 && !$this->getFromCache('overrideMainServer')) { |
|
| 555 | + //when bind to backup server succeeded and failed to main server, |
|
| 556 | + //skip contacting him until next cache refresh |
|
| 557 | + $this->writeToCache('overrideMainServer', true); |
|
| 558 | + } |
|
| 559 | + } |
|
| 560 | + return $bindStatus; |
|
| 561 | + } |
|
| 562 | + return null; |
|
| 563 | + } |
|
| 564 | + |
|
| 565 | + /** |
|
| 566 | + * @param string $host |
|
| 567 | + * @param string $port |
|
| 568 | + * @return bool |
|
| 569 | + * @throws \OC\ServerNotAvailableException |
|
| 570 | + */ |
|
| 571 | + private function doConnect($host, $port) { |
|
| 572 | + if ($host === '') { |
|
| 573 | + return false; |
|
| 574 | + } |
|
| 575 | + $this->ldapConnectionRes = $this->ldap->connect($host, $port); |
|
| 576 | + if($this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_PROTOCOL_VERSION, 3)) { |
|
| 577 | + if($this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_REFERRALS, 0)) { |
|
| 578 | + if($this->configuration->ldapTLS) { |
|
| 579 | + $this->ldap->startTls($this->ldapConnectionRes); |
|
| 580 | + } |
|
| 581 | + } |
|
| 582 | + } else { |
|
| 583 | + throw new \OC\ServerNotAvailableException('Could not set required LDAP Protocol version.'); |
|
| 584 | + } |
|
| 585 | + return true; |
|
| 586 | + } |
|
| 587 | + |
|
| 588 | + /** |
|
| 589 | + * Binds to LDAP |
|
| 590 | + */ |
|
| 591 | + public function bind() { |
|
| 592 | + static $getConnectionResourceAttempt = false; |
|
| 593 | + if(!$this->configuration->ldapConfigurationActive) { |
|
| 594 | + return false; |
|
| 595 | + } |
|
| 596 | + if($getConnectionResourceAttempt) { |
|
| 597 | + $getConnectionResourceAttempt = false; |
|
| 598 | + return false; |
|
| 599 | + } |
|
| 600 | + $getConnectionResourceAttempt = true; |
|
| 601 | + $cr = $this->getConnectionResource(); |
|
| 602 | + $getConnectionResourceAttempt = false; |
|
| 603 | + if(!$this->ldap->isResource($cr)) { |
|
| 604 | + return false; |
|
| 605 | + } |
|
| 606 | + $ldapLogin = @$this->ldap->bind($cr, |
|
| 607 | + $this->configuration->ldapAgentName, |
|
| 608 | + $this->configuration->ldapAgentPassword); |
|
| 609 | + if(!$ldapLogin) { |
|
| 610 | + \OCP\Util::writeLog('user_ldap', |
|
| 611 | + 'Bind failed: ' . $this->ldap->errno($cr) . ': ' . $this->ldap->error($cr), |
|
| 612 | + \OCP\Util::WARN); |
|
| 613 | + $this->ldapConnectionRes = null; |
|
| 614 | + return false; |
|
| 615 | + } |
|
| 616 | + return true; |
|
| 617 | + } |
|
| 618 | 618 | |
| 619 | 619 | } |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | $this->configuration = new Configuration($configPrefix, |
| 88 | 88 | !is_null($configID)); |
| 89 | 89 | $memcache = \OC::$server->getMemCacheFactory(); |
| 90 | - if($memcache->isAvailable()) { |
|
| 90 | + if ($memcache->isAvailable()) { |
|
| 91 | 91 | $this->cache = $memcache->create(); |
| 92 | 92 | } |
| 93 | 93 | $helper = new Helper(\OC::$server->getConfig()); |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | public function __destruct() { |
| 102 | - if(!$this->dontDestruct && $this->ldap->isResource($this->ldapConnectionRes)) { |
|
| 102 | + if (!$this->dontDestruct && $this->ldap->isResource($this->ldapConnectionRes)) { |
|
| 103 | 103 | @$this->ldap->unbind($this->ldapConnectionRes); |
| 104 | 104 | }; |
| 105 | 105 | } |
@@ -119,11 +119,11 @@ discard block |
||
| 119 | 119 | * @return bool|mixed|void |
| 120 | 120 | */ |
| 121 | 121 | public function __get($name) { |
| 122 | - if(!$this->configured) { |
|
| 122 | + if (!$this->configured) { |
|
| 123 | 123 | $this->readConfiguration(); |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - if($name === 'hasPagedResultSupport') { |
|
| 126 | + if ($name === 'hasPagedResultSupport') { |
|
| 127 | 127 | return $this->hasPagedResultSupport; |
| 128 | 128 | } |
| 129 | 129 | |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | $before = $this->configuration->$name; |
| 140 | 140 | $this->configuration->$name = $value; |
| 141 | 141 | $after = $this->configuration->$name; |
| 142 | - if($before !== $after) { |
|
| 142 | + if ($before !== $after) { |
|
| 143 | 143 | if ($this->configID !== '') { |
| 144 | 144 | $this->configuration->saveConfiguration(); |
| 145 | 145 | } |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | * @param bool $state |
| 155 | 155 | */ |
| 156 | 156 | public function setIgnoreValidation($state) { |
| 157 | - $this->ignoreValidation = (bool)$state; |
|
| 157 | + $this->ignoreValidation = (bool) $state; |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | /** |
@@ -170,14 +170,14 @@ discard block |
||
| 170 | 170 | * Returns the LDAP handler |
| 171 | 171 | */ |
| 172 | 172 | public function getConnectionResource() { |
| 173 | - if(!$this->ldapConnectionRes) { |
|
| 173 | + if (!$this->ldapConnectionRes) { |
|
| 174 | 174 | $this->init(); |
| 175 | - } else if(!$this->ldap->isResource($this->ldapConnectionRes)) { |
|
| 175 | + } else if (!$this->ldap->isResource($this->ldapConnectionRes)) { |
|
| 176 | 176 | $this->ldapConnectionRes = null; |
| 177 | 177 | $this->establishConnection(); |
| 178 | 178 | } |
| 179 | - if(is_null($this->ldapConnectionRes)) { |
|
| 180 | - \OCP\Util::writeLog('user_ldap', 'No LDAP Connection to server ' . $this->configuration->ldapHost, \OCP\Util::ERROR); |
|
| 179 | + if (is_null($this->ldapConnectionRes)) { |
|
| 180 | + \OCP\Util::writeLog('user_ldap', 'No LDAP Connection to server '.$this->configuration->ldapHost, \OCP\Util::ERROR); |
|
| 181 | 181 | throw new ServerNotAvailableException('Connection to LDAP server could not be established'); |
| 182 | 182 | } |
| 183 | 183 | return $this->ldapConnectionRes; |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | * resets the connection resource |
| 188 | 188 | */ |
| 189 | 189 | public function resetConnectionResource() { |
| 190 | - if(!is_null($this->ldapConnectionRes)) { |
|
| 190 | + if (!is_null($this->ldapConnectionRes)) { |
|
| 191 | 191 | @$this->ldap->unbind($this->ldapConnectionRes); |
| 192 | 192 | $this->ldapConnectionRes = null; |
| 193 | 193 | } |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | */ |
| 200 | 200 | private function getCacheKey($key) { |
| 201 | 201 | $prefix = 'LDAP-'.$this->configID.'-'.$this->configPrefix.'-'; |
| 202 | - if(is_null($key)) { |
|
| 202 | + if (is_null($key)) { |
|
| 203 | 203 | return $prefix; |
| 204 | 204 | } |
| 205 | 205 | return $prefix.md5($key); |
@@ -210,10 +210,10 @@ discard block |
||
| 210 | 210 | * @return mixed|null |
| 211 | 211 | */ |
| 212 | 212 | public function getFromCache($key) { |
| 213 | - if(!$this->configured) { |
|
| 213 | + if (!$this->configured) { |
|
| 214 | 214 | $this->readConfiguration(); |
| 215 | 215 | } |
| 216 | - if(is_null($this->cache) || !$this->configuration->ldapCacheTTL) { |
|
| 216 | + if (is_null($this->cache) || !$this->configuration->ldapCacheTTL) { |
|
| 217 | 217 | return null; |
| 218 | 218 | } |
| 219 | 219 | $key = $this->getCacheKey($key); |
@@ -228,10 +228,10 @@ discard block |
||
| 228 | 228 | * @return string |
| 229 | 229 | */ |
| 230 | 230 | public function writeToCache($key, $value) { |
| 231 | - if(!$this->configured) { |
|
| 231 | + if (!$this->configured) { |
|
| 232 | 232 | $this->readConfiguration(); |
| 233 | 233 | } |
| 234 | - if(is_null($this->cache) |
|
| 234 | + if (is_null($this->cache) |
|
| 235 | 235 | || !$this->configuration->ldapCacheTTL |
| 236 | 236 | || !$this->configuration->ldapConfigurationActive) { |
| 237 | 237 | return null; |
@@ -242,7 +242,7 @@ discard block |
||
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | public function clearCache() { |
| 245 | - if(!is_null($this->cache)) { |
|
| 245 | + if (!is_null($this->cache)) { |
|
| 246 | 246 | $this->cache->clear($this->getCacheKey(null)); |
| 247 | 247 | } |
| 248 | 248 | } |
@@ -254,7 +254,7 @@ discard block |
||
| 254 | 254 | * @return null |
| 255 | 255 | */ |
| 256 | 256 | private function readConfiguration($force = false) { |
| 257 | - if((!$this->configured || $force) && !is_null($this->configID)) { |
|
| 257 | + if ((!$this->configured || $force) && !is_null($this->configID)) { |
|
| 258 | 258 | $this->configuration->readConfiguration(); |
| 259 | 259 | $this->configured = $this->validateConfiguration(); |
| 260 | 260 | } |
@@ -267,12 +267,12 @@ discard block |
||
| 267 | 267 | * @return boolean true if config validates, false otherwise. Check with $setParameters for detailed success on single parameters |
| 268 | 268 | */ |
| 269 | 269 | public function setConfiguration($config, &$setParameters = null) { |
| 270 | - if(is_null($setParameters)) { |
|
| 270 | + if (is_null($setParameters)) { |
|
| 271 | 271 | $setParameters = array(); |
| 272 | 272 | } |
| 273 | 273 | $this->doNotValidate = false; |
| 274 | 274 | $this->configuration->setConfiguration($config, $setParameters); |
| 275 | - if(count($setParameters) > 0) { |
|
| 275 | + if (count($setParameters) > 0) { |
|
| 276 | 276 | $this->configured = $this->validateConfiguration(); |
| 277 | 277 | } |
| 278 | 278 | |
@@ -299,10 +299,10 @@ discard block |
||
| 299 | 299 | $config = $this->configuration->getConfiguration(); |
| 300 | 300 | $cta = $this->configuration->getConfigTranslationArray(); |
| 301 | 301 | $result = array(); |
| 302 | - foreach($cta as $dbkey => $configkey) { |
|
| 303 | - switch($configkey) { |
|
| 302 | + foreach ($cta as $dbkey => $configkey) { |
|
| 303 | + switch ($configkey) { |
|
| 304 | 304 | case 'homeFolderNamingRule': |
| 305 | - if(strpos($config[$configkey], 'attr:') === 0) { |
|
| 305 | + if (strpos($config[$configkey], 'attr:') === 0) { |
|
| 306 | 306 | $result[$dbkey] = substr($config[$configkey], 5); |
| 307 | 307 | } else { |
| 308 | 308 | $result[$dbkey] = ''; |
@@ -313,7 +313,7 @@ discard block |
||
| 313 | 313 | case 'ldapBaseGroups': |
| 314 | 314 | case 'ldapAttributesForUserSearch': |
| 315 | 315 | case 'ldapAttributesForGroupSearch': |
| 316 | - if(is_array($config[$configkey])) { |
|
| 316 | + if (is_array($config[$configkey])) { |
|
| 317 | 317 | $result[$dbkey] = implode("\n", $config[$configkey]); |
| 318 | 318 | break; |
| 319 | 319 | } //else follows default |
@@ -326,23 +326,23 @@ discard block |
||
| 326 | 326 | |
| 327 | 327 | private function doSoftValidation() { |
| 328 | 328 | //if User or Group Base are not set, take over Base DN setting |
| 329 | - foreach(array('ldapBaseUsers', 'ldapBaseGroups') as $keyBase) { |
|
| 329 | + foreach (array('ldapBaseUsers', 'ldapBaseGroups') as $keyBase) { |
|
| 330 | 330 | $val = $this->configuration->$keyBase; |
| 331 | - if(empty($val)) { |
|
| 331 | + if (empty($val)) { |
|
| 332 | 332 | $this->configuration->$keyBase = $this->configuration->ldapBase; |
| 333 | 333 | } |
| 334 | 334 | } |
| 335 | 335 | |
| 336 | - foreach(array('ldapExpertUUIDUserAttr' => 'ldapUuidUserAttribute', |
|
| 336 | + foreach (array('ldapExpertUUIDUserAttr' => 'ldapUuidUserAttribute', |
|
| 337 | 337 | 'ldapExpertUUIDGroupAttr' => 'ldapUuidGroupAttribute') |
| 338 | 338 | as $expertSetting => $effectiveSetting) { |
| 339 | 339 | $uuidOverride = $this->configuration->$expertSetting; |
| 340 | - if(!empty($uuidOverride)) { |
|
| 340 | + if (!empty($uuidOverride)) { |
|
| 341 | 341 | $this->configuration->$effectiveSetting = $uuidOverride; |
| 342 | 342 | } else { |
| 343 | 343 | $uuidAttributes = array('auto', 'entryuuid', 'nsuniqueid', |
| 344 | 344 | 'objectguid', 'guid', 'ipauniqueid'); |
| 345 | - if(!in_array($this->configuration->$effectiveSetting, |
|
| 345 | + if (!in_array($this->configuration->$effectiveSetting, |
|
| 346 | 346 | $uuidAttributes) |
| 347 | 347 | && (!is_null($this->configID))) { |
| 348 | 348 | $this->configuration->$effectiveSetting = 'auto'; |
@@ -364,14 +364,14 @@ discard block |
||
| 364 | 364 | //make sure empty search attributes are saved as simple, empty array |
| 365 | 365 | $saKeys = array('ldapAttributesForUserSearch', |
| 366 | 366 | 'ldapAttributesForGroupSearch'); |
| 367 | - foreach($saKeys as $key) { |
|
| 367 | + foreach ($saKeys as $key) { |
|
| 368 | 368 | $val = $this->configuration->$key; |
| 369 | - if(is_array($val) && count($val) === 1 && empty($val[0])) { |
|
| 369 | + if (is_array($val) && count($val) === 1 && empty($val[0])) { |
|
| 370 | 370 | $this->configuration->$key = array(); |
| 371 | 371 | } |
| 372 | 372 | } |
| 373 | 373 | |
| 374 | - if((stripos($this->configuration->ldapHost, 'ldaps://') === 0) |
|
| 374 | + if ((stripos($this->configuration->ldapHost, 'ldaps://') === 0) |
|
| 375 | 375 | && $this->configuration->ldapTLS) { |
| 376 | 376 | $this->configuration->ldapTLS = false; |
| 377 | 377 | \OCP\Util::writeLog('user_ldap', |
@@ -392,10 +392,10 @@ discard block |
||
| 392 | 392 | //options that shall not be empty |
| 393 | 393 | $options = array('ldapHost', 'ldapPort', 'ldapUserDisplayName', |
| 394 | 394 | 'ldapGroupDisplayName', 'ldapLoginFilter'); |
| 395 | - foreach($options as $key) { |
|
| 395 | + foreach ($options as $key) { |
|
| 396 | 396 | $val = $this->configuration->$key; |
| 397 | - if(empty($val)) { |
|
| 398 | - switch($key) { |
|
| 397 | + if (empty($val)) { |
|
| 398 | + switch ($key) { |
|
| 399 | 399 | case 'ldapHost': |
| 400 | 400 | $subj = 'LDAP Host'; |
| 401 | 401 | break; |
@@ -426,7 +426,7 @@ discard block |
||
| 426 | 426 | $agent = $this->configuration->ldapAgentName; |
| 427 | 427 | $pwd = $this->configuration->ldapAgentPassword; |
| 428 | 428 | if ( |
| 429 | - ($agent === '' && $pwd !== '') |
|
| 429 | + ($agent === '' && $pwd !== '') |
|
| 430 | 430 | || ($agent !== '' && $pwd === '') |
| 431 | 431 | ) { |
| 432 | 432 | \OCP\Util::writeLog('user_ldap', |
@@ -441,14 +441,14 @@ discard block |
||
| 441 | 441 | $baseUsers = $this->configuration->ldapBaseUsers; |
| 442 | 442 | $baseGroups = $this->configuration->ldapBaseGroups; |
| 443 | 443 | |
| 444 | - if(empty($base) && empty($baseUsers) && empty($baseGroups)) { |
|
| 444 | + if (empty($base) && empty($baseUsers) && empty($baseGroups)) { |
|
| 445 | 445 | \OCP\Util::writeLog('user_ldap', |
| 446 | 446 | $errorStr.'Not a single Base DN given.', |
| 447 | 447 | \OCP\Util::WARN); |
| 448 | 448 | $configurationOK = false; |
| 449 | 449 | } |
| 450 | 450 | |
| 451 | - if(mb_strpos($this->configuration->ldapLoginFilter, '%uid', 0, 'UTF-8') |
|
| 451 | + if (mb_strpos($this->configuration->ldapLoginFilter, '%uid', 0, 'UTF-8') |
|
| 452 | 452 | === false) { |
| 453 | 453 | \OCP\Util::writeLog('user_ldap', |
| 454 | 454 | $errorStr.'login filter does not contain %uid '. |
@@ -466,7 +466,7 @@ discard block |
||
| 466 | 466 | */ |
| 467 | 467 | private function validateConfiguration() { |
| 468 | 468 | |
| 469 | - if($this->doNotValidate) { |
|
| 469 | + if ($this->doNotValidate) { |
|
| 470 | 470 | //don't do a validation if it is a new configuration with pure |
| 471 | 471 | //default values. Will be allowed on changes via __set or |
| 472 | 472 | //setConfiguration |
@@ -487,21 +487,21 @@ discard block |
||
| 487 | 487 | * Connects and Binds to LDAP |
| 488 | 488 | */ |
| 489 | 489 | private function establishConnection() { |
| 490 | - if(!$this->configuration->ldapConfigurationActive) { |
|
| 490 | + if (!$this->configuration->ldapConfigurationActive) { |
|
| 491 | 491 | return null; |
| 492 | 492 | } |
| 493 | 493 | static $phpLDAPinstalled = true; |
| 494 | - if(!$phpLDAPinstalled) { |
|
| 494 | + if (!$phpLDAPinstalled) { |
|
| 495 | 495 | return false; |
| 496 | 496 | } |
| 497 | - if(!$this->ignoreValidation && !$this->configured) { |
|
| 497 | + if (!$this->ignoreValidation && !$this->configured) { |
|
| 498 | 498 | \OCP\Util::writeLog('user_ldap', |
| 499 | 499 | 'Configuration is invalid, cannot connect', |
| 500 | 500 | \OCP\Util::WARN); |
| 501 | 501 | return false; |
| 502 | 502 | } |
| 503 | - if(!$this->ldapConnectionRes) { |
|
| 504 | - if(!$this->ldap->areLDAPFunctionsAvailable()) { |
|
| 503 | + if (!$this->ldapConnectionRes) { |
|
| 504 | + if (!$this->ldap->areLDAPFunctionsAvailable()) { |
|
| 505 | 505 | $phpLDAPinstalled = false; |
| 506 | 506 | \OCP\Util::writeLog('user_ldap', |
| 507 | 507 | 'function ldap_connect is not available. Make '. |
@@ -510,8 +510,8 @@ discard block |
||
| 510 | 510 | |
| 511 | 511 | return false; |
| 512 | 512 | } |
| 513 | - if($this->configuration->turnOffCertCheck) { |
|
| 514 | - if(putenv('LDAPTLS_REQCERT=never')) { |
|
| 513 | + if ($this->configuration->turnOffCertCheck) { |
|
| 514 | + if (putenv('LDAPTLS_REQCERT=never')) { |
|
| 515 | 515 | \OCP\Util::writeLog('user_ldap', |
| 516 | 516 | 'Turned off SSL certificate validation successfully.', |
| 517 | 517 | \OCP\Util::DEBUG); |
@@ -534,24 +534,24 @@ discard block |
||
| 534 | 534 | $error = $this->ldap->isResource($this->ldapConnectionRes) ? |
| 535 | 535 | $this->ldap->errno($this->ldapConnectionRes) : -1; |
| 536 | 536 | } |
| 537 | - if($bindStatus === true) { |
|
| 537 | + if ($bindStatus === true) { |
|
| 538 | 538 | return $bindStatus; |
| 539 | 539 | } |
| 540 | 540 | } catch (\OC\ServerNotAvailableException $e) { |
| 541 | - if(trim($this->configuration->ldapBackupHost) === "") { |
|
| 541 | + if (trim($this->configuration->ldapBackupHost) === "") { |
|
| 542 | 542 | throw $e; |
| 543 | 543 | } |
| 544 | 544 | } |
| 545 | 545 | |
| 546 | 546 | //if LDAP server is not reachable, try the Backup (Replica!) Server |
| 547 | - if( $error !== 0 |
|
| 547 | + if ($error !== 0 |
|
| 548 | 548 | || $this->configuration->ldapOverrideMainServer |
| 549 | 549 | || $this->getFromCache('overrideMainServer')) |
| 550 | 550 | { |
| 551 | 551 | $this->doConnect($this->configuration->ldapBackupHost, |
| 552 | 552 | $this->configuration->ldapBackupPort); |
| 553 | 553 | $bindStatus = $this->bind(); |
| 554 | - if($bindStatus && $error === -1 && !$this->getFromCache('overrideMainServer')) { |
|
| 554 | + if ($bindStatus && $error === -1 && !$this->getFromCache('overrideMainServer')) { |
|
| 555 | 555 | //when bind to backup server succeeded and failed to main server, |
| 556 | 556 | //skip contacting him until next cache refresh |
| 557 | 557 | $this->writeToCache('overrideMainServer', true); |
@@ -573,9 +573,9 @@ discard block |
||
| 573 | 573 | return false; |
| 574 | 574 | } |
| 575 | 575 | $this->ldapConnectionRes = $this->ldap->connect($host, $port); |
| 576 | - if($this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_PROTOCOL_VERSION, 3)) { |
|
| 577 | - if($this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_REFERRALS, 0)) { |
|
| 578 | - if($this->configuration->ldapTLS) { |
|
| 576 | + if ($this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_PROTOCOL_VERSION, 3)) { |
|
| 577 | + if ($this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_REFERRALS, 0)) { |
|
| 578 | + if ($this->configuration->ldapTLS) { |
|
| 579 | 579 | $this->ldap->startTls($this->ldapConnectionRes); |
| 580 | 580 | } |
| 581 | 581 | } |
@@ -590,25 +590,25 @@ discard block |
||
| 590 | 590 | */ |
| 591 | 591 | public function bind() { |
| 592 | 592 | static $getConnectionResourceAttempt = false; |
| 593 | - if(!$this->configuration->ldapConfigurationActive) { |
|
| 593 | + if (!$this->configuration->ldapConfigurationActive) { |
|
| 594 | 594 | return false; |
| 595 | 595 | } |
| 596 | - if($getConnectionResourceAttempt) { |
|
| 596 | + if ($getConnectionResourceAttempt) { |
|
| 597 | 597 | $getConnectionResourceAttempt = false; |
| 598 | 598 | return false; |
| 599 | 599 | } |
| 600 | 600 | $getConnectionResourceAttempt = true; |
| 601 | 601 | $cr = $this->getConnectionResource(); |
| 602 | 602 | $getConnectionResourceAttempt = false; |
| 603 | - if(!$this->ldap->isResource($cr)) { |
|
| 603 | + if (!$this->ldap->isResource($cr)) { |
|
| 604 | 604 | return false; |
| 605 | 605 | } |
| 606 | 606 | $ldapLogin = @$this->ldap->bind($cr, |
| 607 | 607 | $this->configuration->ldapAgentName, |
| 608 | 608 | $this->configuration->ldapAgentPassword); |
| 609 | - if(!$ldapLogin) { |
|
| 609 | + if (!$ldapLogin) { |
|
| 610 | 610 | \OCP\Util::writeLog('user_ldap', |
| 611 | - 'Bind failed: ' . $this->ldap->errno($cr) . ': ' . $this->ldap->error($cr), |
|
| 611 | + 'Bind failed: '.$this->ldap->errno($cr).': '.$this->ldap->error($cr), |
|
| 612 | 612 | \OCP\Util::WARN); |
| 613 | 613 | $this->ldapConnectionRes = null; |
| 614 | 614 | return false; |
@@ -29,19 +29,19 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | class FilesystemHelper { |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @brief states whether the filesystem was loaded |
|
| 34 | - * @return bool |
|
| 35 | - */ |
|
| 36 | - public function isLoaded() { |
|
| 37 | - return \OC\Files\Filesystem::$loaded; |
|
| 38 | - } |
|
| 32 | + /** |
|
| 33 | + * @brief states whether the filesystem was loaded |
|
| 34 | + * @return bool |
|
| 35 | + */ |
|
| 36 | + public function isLoaded() { |
|
| 37 | + return \OC\Files\Filesystem::$loaded; |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * @brief initializes the filesystem for the given user |
|
| 42 | - * @param string $uid the ownCloud username of the user |
|
| 43 | - */ |
|
| 44 | - public function setup($uid) { |
|
| 45 | - \OC_Util::setupFS($uid); |
|
| 46 | - } |
|
| 40 | + /** |
|
| 41 | + * @brief initializes the filesystem for the given user |
|
| 42 | + * @param string $uid the ownCloud username of the user |
|
| 43 | + */ |
|
| 44 | + public function setup($uid) { |
|
| 45 | + \OC_Util::setupFS($uid); |
|
| 46 | + } |
|
| 47 | 47 | } |
@@ -33,155 +33,155 @@ |
||
| 33 | 33 | */ |
| 34 | 34 | class LDAPProvider implements ILDAPProvider, IDeletionFlagSupport { |
| 35 | 35 | |
| 36 | - private $backend; |
|
| 37 | - private $logger; |
|
| 38 | - private $helper; |
|
| 39 | - private $deletedUsersIndex; |
|
| 36 | + private $backend; |
|
| 37 | + private $logger; |
|
| 38 | + private $helper; |
|
| 39 | + private $deletedUsersIndex; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Create new LDAPProvider |
|
| 43 | - * @param \OCP\IServerContainer $serverContainer |
|
| 44 | - * @throws \Exception if user_ldap app was not enabled |
|
| 45 | - */ |
|
| 46 | - public function __construct(IServerContainer $serverContainer, Helper $helper, DeletedUsersIndex $deletedUsersIndex) { |
|
| 47 | - $this->logger = $serverContainer->getLogger(); |
|
| 48 | - $this->helper = $helper; |
|
| 49 | - $this->deletedUsersIndex = $deletedUsersIndex; |
|
| 50 | - foreach ($serverContainer->getUserManager()->getBackends() as $backend){ |
|
| 51 | - $this->logger->debug('instance '.get_class($backend).' backend.', ['app' => 'user_ldap']); |
|
| 52 | - if ($backend instanceof IUserLDAP) { |
|
| 53 | - $this->backend = $backend; |
|
| 54 | - return; |
|
| 55 | - } |
|
| 41 | + /** |
|
| 42 | + * Create new LDAPProvider |
|
| 43 | + * @param \OCP\IServerContainer $serverContainer |
|
| 44 | + * @throws \Exception if user_ldap app was not enabled |
|
| 45 | + */ |
|
| 46 | + public function __construct(IServerContainer $serverContainer, Helper $helper, DeletedUsersIndex $deletedUsersIndex) { |
|
| 47 | + $this->logger = $serverContainer->getLogger(); |
|
| 48 | + $this->helper = $helper; |
|
| 49 | + $this->deletedUsersIndex = $deletedUsersIndex; |
|
| 50 | + foreach ($serverContainer->getUserManager()->getBackends() as $backend){ |
|
| 51 | + $this->logger->debug('instance '.get_class($backend).' backend.', ['app' => 'user_ldap']); |
|
| 52 | + if ($backend instanceof IUserLDAP) { |
|
| 53 | + $this->backend = $backend; |
|
| 54 | + return; |
|
| 55 | + } |
|
| 56 | 56 | } |
| 57 | - throw new \Exception('To use the LDAPProvider, user_ldap app must be enabled'); |
|
| 58 | - } |
|
| 57 | + throw new \Exception('To use the LDAPProvider, user_ldap app must be enabled'); |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * Translate an user id to LDAP DN |
|
| 62 | - * @param string $uid user id |
|
| 63 | - * @return string with the LDAP DN |
|
| 64 | - * @throws \Exception if translation was unsuccessful |
|
| 65 | - */ |
|
| 66 | - public function getUserDN($uid) { |
|
| 67 | - if(!$this->backend->userExists($uid)){ |
|
| 68 | - throw new \Exception('User id not found in LDAP'); |
|
| 69 | - } |
|
| 70 | - $result = $this->backend->getLDAPAccess($uid)->username2dn($uid); |
|
| 71 | - if(!$result){ |
|
| 72 | - throw new \Exception('Translation to LDAP DN unsuccessful'); |
|
| 73 | - } |
|
| 74 | - return $result; |
|
| 75 | - } |
|
| 60 | + /** |
|
| 61 | + * Translate an user id to LDAP DN |
|
| 62 | + * @param string $uid user id |
|
| 63 | + * @return string with the LDAP DN |
|
| 64 | + * @throws \Exception if translation was unsuccessful |
|
| 65 | + */ |
|
| 66 | + public function getUserDN($uid) { |
|
| 67 | + if(!$this->backend->userExists($uid)){ |
|
| 68 | + throw new \Exception('User id not found in LDAP'); |
|
| 69 | + } |
|
| 70 | + $result = $this->backend->getLDAPAccess($uid)->username2dn($uid); |
|
| 71 | + if(!$result){ |
|
| 72 | + throw new \Exception('Translation to LDAP DN unsuccessful'); |
|
| 73 | + } |
|
| 74 | + return $result; |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * Translate a LDAP DN to an internal user name. If there is no mapping between |
|
| 79 | - * the DN and the user name, a new one will be created. |
|
| 80 | - * @param string $dn LDAP DN |
|
| 81 | - * @return string with the internal user name |
|
| 82 | - * @throws \Exception if translation was unsuccessful |
|
| 83 | - */ |
|
| 84 | - public function getUserName($dn) { |
|
| 85 | - $result = $this->backend->dn2UserName($dn); |
|
| 86 | - if(!$result){ |
|
| 87 | - throw new \Exception('Translation to internal user name unsuccessful'); |
|
| 88 | - } |
|
| 89 | - return $result; |
|
| 90 | - } |
|
| 77 | + /** |
|
| 78 | + * Translate a LDAP DN to an internal user name. If there is no mapping between |
|
| 79 | + * the DN and the user name, a new one will be created. |
|
| 80 | + * @param string $dn LDAP DN |
|
| 81 | + * @return string with the internal user name |
|
| 82 | + * @throws \Exception if translation was unsuccessful |
|
| 83 | + */ |
|
| 84 | + public function getUserName($dn) { |
|
| 85 | + $result = $this->backend->dn2UserName($dn); |
|
| 86 | + if(!$result){ |
|
| 87 | + throw new \Exception('Translation to internal user name unsuccessful'); |
|
| 88 | + } |
|
| 89 | + return $result; |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * Convert a stored DN so it can be used as base parameter for LDAP queries. |
|
| 94 | - * @param string $dn the DN in question |
|
| 95 | - * @return string |
|
| 96 | - */ |
|
| 97 | - public function DNasBaseParameter($dn) { |
|
| 98 | - return $this->helper->DNasBaseParameter($dn); |
|
| 99 | - } |
|
| 92 | + /** |
|
| 93 | + * Convert a stored DN so it can be used as base parameter for LDAP queries. |
|
| 94 | + * @param string $dn the DN in question |
|
| 95 | + * @return string |
|
| 96 | + */ |
|
| 97 | + public function DNasBaseParameter($dn) { |
|
| 98 | + return $this->helper->DNasBaseParameter($dn); |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * Sanitize a DN received from the LDAP server. |
|
| 103 | - * @param array $dn the DN in question |
|
| 104 | - * @return array the sanitized DN |
|
| 105 | - */ |
|
| 106 | - public function sanitizeDN($dn) { |
|
| 107 | - return $this->helper->sanitizeDN($dn); |
|
| 108 | - } |
|
| 101 | + /** |
|
| 102 | + * Sanitize a DN received from the LDAP server. |
|
| 103 | + * @param array $dn the DN in question |
|
| 104 | + * @return array the sanitized DN |
|
| 105 | + */ |
|
| 106 | + public function sanitizeDN($dn) { |
|
| 107 | + return $this->helper->sanitizeDN($dn); |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | - /** |
|
| 111 | - * Return a new LDAP connection resource for the specified user. |
|
| 112 | - * The connection must be closed manually. |
|
| 113 | - * @param string $uid user id |
|
| 114 | - * @return resource of the LDAP connection |
|
| 115 | - * @throws \Exception if user id was not found in LDAP |
|
| 116 | - */ |
|
| 117 | - public function getLDAPConnection($uid) { |
|
| 118 | - if(!$this->backend->userExists($uid)){ |
|
| 119 | - throw new \Exception('User id not found in LDAP'); |
|
| 120 | - } |
|
| 121 | - return $this->backend->getNewLDAPConnection($uid); |
|
| 122 | - } |
|
| 110 | + /** |
|
| 111 | + * Return a new LDAP connection resource for the specified user. |
|
| 112 | + * The connection must be closed manually. |
|
| 113 | + * @param string $uid user id |
|
| 114 | + * @return resource of the LDAP connection |
|
| 115 | + * @throws \Exception if user id was not found in LDAP |
|
| 116 | + */ |
|
| 117 | + public function getLDAPConnection($uid) { |
|
| 118 | + if(!$this->backend->userExists($uid)){ |
|
| 119 | + throw new \Exception('User id not found in LDAP'); |
|
| 120 | + } |
|
| 121 | + return $this->backend->getNewLDAPConnection($uid); |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | - /** |
|
| 125 | - * Get the LDAP base for users. |
|
| 126 | - * @param string $uid user id |
|
| 127 | - * @return string the base for users |
|
| 128 | - * @throws \Exception if user id was not found in LDAP |
|
| 129 | - */ |
|
| 130 | - public function getLDAPBaseUsers($uid) { |
|
| 131 | - if(!$this->backend->userExists($uid)){ |
|
| 132 | - throw new \Exception('User id not found in LDAP'); |
|
| 133 | - } |
|
| 134 | - return $this->backend->getLDAPAccess($uid)->getConnection()->getConfiguration()['ldap_base_users']; |
|
| 135 | - } |
|
| 124 | + /** |
|
| 125 | + * Get the LDAP base for users. |
|
| 126 | + * @param string $uid user id |
|
| 127 | + * @return string the base for users |
|
| 128 | + * @throws \Exception if user id was not found in LDAP |
|
| 129 | + */ |
|
| 130 | + public function getLDAPBaseUsers($uid) { |
|
| 131 | + if(!$this->backend->userExists($uid)){ |
|
| 132 | + throw new \Exception('User id not found in LDAP'); |
|
| 133 | + } |
|
| 134 | + return $this->backend->getLDAPAccess($uid)->getConnection()->getConfiguration()['ldap_base_users']; |
|
| 135 | + } |
|
| 136 | 136 | |
| 137 | - /** |
|
| 138 | - * Get the LDAP base for groups. |
|
| 139 | - * @param string $uid user id |
|
| 140 | - * @return string the base for groups |
|
| 141 | - * @throws \Exception if user id was not found in LDAP |
|
| 142 | - */ |
|
| 143 | - public function getLDAPBaseGroups($uid) { |
|
| 144 | - if(!$this->backend->userExists($uid)){ |
|
| 145 | - throw new \Exception('User id not found in LDAP'); |
|
| 146 | - } |
|
| 147 | - return $this->backend->getLDAPAccess($uid)->getConnection()->getConfiguration()['ldap_base_groups']; |
|
| 148 | - } |
|
| 137 | + /** |
|
| 138 | + * Get the LDAP base for groups. |
|
| 139 | + * @param string $uid user id |
|
| 140 | + * @return string the base for groups |
|
| 141 | + * @throws \Exception if user id was not found in LDAP |
|
| 142 | + */ |
|
| 143 | + public function getLDAPBaseGroups($uid) { |
|
| 144 | + if(!$this->backend->userExists($uid)){ |
|
| 145 | + throw new \Exception('User id not found in LDAP'); |
|
| 146 | + } |
|
| 147 | + return $this->backend->getLDAPAccess($uid)->getConnection()->getConfiguration()['ldap_base_groups']; |
|
| 148 | + } |
|
| 149 | 149 | |
| 150 | - /** |
|
| 151 | - * Clear the cache if a cache is used, otherwise do nothing. |
|
| 152 | - * @param string $uid user id |
|
| 153 | - * @throws \Exception if user id was not found in LDAP |
|
| 154 | - */ |
|
| 155 | - public function clearCache($uid) { |
|
| 156 | - if(!$this->backend->userExists($uid)){ |
|
| 157 | - throw new \Exception('User id not found in LDAP'); |
|
| 158 | - } |
|
| 159 | - $this->backend->getLDAPAccess($uid)->getConnection()->clearCache(); |
|
| 160 | - } |
|
| 150 | + /** |
|
| 151 | + * Clear the cache if a cache is used, otherwise do nothing. |
|
| 152 | + * @param string $uid user id |
|
| 153 | + * @throws \Exception if user id was not found in LDAP |
|
| 154 | + */ |
|
| 155 | + public function clearCache($uid) { |
|
| 156 | + if(!$this->backend->userExists($uid)){ |
|
| 157 | + throw new \Exception('User id not found in LDAP'); |
|
| 158 | + } |
|
| 159 | + $this->backend->getLDAPAccess($uid)->getConnection()->clearCache(); |
|
| 160 | + } |
|
| 161 | 161 | |
| 162 | - /** |
|
| 163 | - * Check whether a LDAP DN exists |
|
| 164 | - * @param string $dn LDAP DN |
|
| 165 | - * @return bool whether the DN exists |
|
| 166 | - */ |
|
| 167 | - public function dnExists($dn) { |
|
| 168 | - $result = $this->backend->dn2UserName($dn); |
|
| 169 | - return !$result ? false : true; |
|
| 170 | - } |
|
| 162 | + /** |
|
| 163 | + * Check whether a LDAP DN exists |
|
| 164 | + * @param string $dn LDAP DN |
|
| 165 | + * @return bool whether the DN exists |
|
| 166 | + */ |
|
| 167 | + public function dnExists($dn) { |
|
| 168 | + $result = $this->backend->dn2UserName($dn); |
|
| 169 | + return !$result ? false : true; |
|
| 170 | + } |
|
| 171 | 171 | |
| 172 | - /** |
|
| 173 | - * Flag record for deletion. |
|
| 174 | - * @param string $uid user id |
|
| 175 | - */ |
|
| 176 | - public function flagRecord($uid) { |
|
| 177 | - $this->deletedUsersIndex->markUser($uid); |
|
| 178 | - } |
|
| 172 | + /** |
|
| 173 | + * Flag record for deletion. |
|
| 174 | + * @param string $uid user id |
|
| 175 | + */ |
|
| 176 | + public function flagRecord($uid) { |
|
| 177 | + $this->deletedUsersIndex->markUser($uid); |
|
| 178 | + } |
|
| 179 | 179 | |
| 180 | - /** |
|
| 181 | - * Unflag record for deletion. |
|
| 182 | - * @param string $uid user id |
|
| 183 | - */ |
|
| 184 | - public function unflagRecord($uid) { |
|
| 185 | - //do nothing |
|
| 186 | - } |
|
| 180 | + /** |
|
| 181 | + * Unflag record for deletion. |
|
| 182 | + * @param string $uid user id |
|
| 183 | + */ |
|
| 184 | + public function unflagRecord($uid) { |
|
| 185 | + //do nothing |
|
| 186 | + } |
|
| 187 | 187 | } |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | $this->logger = $serverContainer->getLogger(); |
| 48 | 48 | $this->helper = $helper; |
| 49 | 49 | $this->deletedUsersIndex = $deletedUsersIndex; |
| 50 | - foreach ($serverContainer->getUserManager()->getBackends() as $backend){ |
|
| 50 | + foreach ($serverContainer->getUserManager()->getBackends() as $backend) { |
|
| 51 | 51 | $this->logger->debug('instance '.get_class($backend).' backend.', ['app' => 'user_ldap']); |
| 52 | 52 | if ($backend instanceof IUserLDAP) { |
| 53 | 53 | $this->backend = $backend; |
@@ -64,11 +64,11 @@ discard block |
||
| 64 | 64 | * @throws \Exception if translation was unsuccessful |
| 65 | 65 | */ |
| 66 | 66 | public function getUserDN($uid) { |
| 67 | - if(!$this->backend->userExists($uid)){ |
|
| 67 | + if (!$this->backend->userExists($uid)) { |
|
| 68 | 68 | throw new \Exception('User id not found in LDAP'); |
| 69 | 69 | } |
| 70 | 70 | $result = $this->backend->getLDAPAccess($uid)->username2dn($uid); |
| 71 | - if(!$result){ |
|
| 71 | + if (!$result) { |
|
| 72 | 72 | throw new \Exception('Translation to LDAP DN unsuccessful'); |
| 73 | 73 | } |
| 74 | 74 | return $result; |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | */ |
| 84 | 84 | public function getUserName($dn) { |
| 85 | 85 | $result = $this->backend->dn2UserName($dn); |
| 86 | - if(!$result){ |
|
| 86 | + if (!$result) { |
|
| 87 | 87 | throw new \Exception('Translation to internal user name unsuccessful'); |
| 88 | 88 | } |
| 89 | 89 | return $result; |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | * @throws \Exception if user id was not found in LDAP |
| 116 | 116 | */ |
| 117 | 117 | public function getLDAPConnection($uid) { |
| 118 | - if(!$this->backend->userExists($uid)){ |
|
| 118 | + if (!$this->backend->userExists($uid)) { |
|
| 119 | 119 | throw new \Exception('User id not found in LDAP'); |
| 120 | 120 | } |
| 121 | 121 | return $this->backend->getNewLDAPConnection($uid); |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | * @throws \Exception if user id was not found in LDAP |
| 129 | 129 | */ |
| 130 | 130 | public function getLDAPBaseUsers($uid) { |
| 131 | - if(!$this->backend->userExists($uid)){ |
|
| 131 | + if (!$this->backend->userExists($uid)) { |
|
| 132 | 132 | throw new \Exception('User id not found in LDAP'); |
| 133 | 133 | } |
| 134 | 134 | return $this->backend->getLDAPAccess($uid)->getConnection()->getConfiguration()['ldap_base_users']; |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | * @throws \Exception if user id was not found in LDAP |
| 142 | 142 | */ |
| 143 | 143 | public function getLDAPBaseGroups($uid) { |
| 144 | - if(!$this->backend->userExists($uid)){ |
|
| 144 | + if (!$this->backend->userExists($uid)) { |
|
| 145 | 145 | throw new \Exception('User id not found in LDAP'); |
| 146 | 146 | } |
| 147 | 147 | return $this->backend->getLDAPAccess($uid)->getConnection()->getConfiguration()['ldap_base_groups']; |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | * @throws \Exception if user id was not found in LDAP |
| 154 | 154 | */ |
| 155 | 155 | public function clearCache($uid) { |
| 156 | - if(!$this->backend->userExists($uid)){ |
|
| 156 | + if (!$this->backend->userExists($uid)) { |
|
| 157 | 157 | throw new \Exception('User id not found in LDAP'); |
| 158 | 158 | } |
| 159 | 159 | $this->backend->getLDAPAccess($uid)->getConnection()->clearCache(); |
@@ -44,492 +44,492 @@ |
||
| 44 | 44 | use OCP\Util; |
| 45 | 45 | |
| 46 | 46 | class User_LDAP extends BackendUtility implements \OCP\IUserBackend, \OCP\UserInterface, IUserLDAP { |
| 47 | - /** @var string[] $homesToKill */ |
|
| 48 | - protected $homesToKill = array(); |
|
| 49 | - |
|
| 50 | - /** @var \OCP\IConfig */ |
|
| 51 | - protected $ocConfig; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * @param Access $access |
|
| 55 | - * @param \OCP\IConfig $ocConfig |
|
| 56 | - */ |
|
| 57 | - public function __construct(Access $access, IConfig $ocConfig) { |
|
| 58 | - parent::__construct($access); |
|
| 59 | - $this->ocConfig = $ocConfig; |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * checks whether the user is allowed to change his avatar in ownCloud |
|
| 64 | - * @param string $uid the ownCloud user name |
|
| 65 | - * @return boolean either the user can or cannot |
|
| 66 | - */ |
|
| 67 | - public function canChangeAvatar($uid) { |
|
| 68 | - $user = $this->access->userManager->get($uid); |
|
| 69 | - if(!$user instanceof User) { |
|
| 70 | - return false; |
|
| 71 | - } |
|
| 72 | - if($user->getAvatarImage() === false) { |
|
| 73 | - return true; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - return false; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * returns the username for the given login name, if available |
|
| 81 | - * |
|
| 82 | - * @param string $loginName |
|
| 83 | - * @return string|false |
|
| 84 | - */ |
|
| 85 | - public function loginName2UserName($loginName) { |
|
| 86 | - $cacheKey = 'loginName2UserName-'.$loginName; |
|
| 87 | - $username = $this->access->connection->getFromCache($cacheKey); |
|
| 88 | - if(!is_null($username)) { |
|
| 89 | - return $username; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - try { |
|
| 93 | - $ldapRecord = $this->getLDAPUserByLoginName($loginName); |
|
| 94 | - $user = $this->access->userManager->get($ldapRecord['dn'][0]); |
|
| 95 | - if($user instanceof OfflineUser) { |
|
| 96 | - // this path is not really possible, however get() is documented |
|
| 97 | - // to return User or OfflineUser so we are very defensive here. |
|
| 98 | - $this->access->connection->writeToCache($cacheKey, false); |
|
| 99 | - return false; |
|
| 100 | - } |
|
| 101 | - $username = $user->getUsername(); |
|
| 102 | - $this->access->connection->writeToCache($cacheKey, $username); |
|
| 103 | - return $username; |
|
| 104 | - } catch (NotOnLDAP $e) { |
|
| 105 | - $this->access->connection->writeToCache($cacheKey, false); |
|
| 106 | - return false; |
|
| 107 | - } |
|
| 108 | - } |
|
| 47 | + /** @var string[] $homesToKill */ |
|
| 48 | + protected $homesToKill = array(); |
|
| 49 | + |
|
| 50 | + /** @var \OCP\IConfig */ |
|
| 51 | + protected $ocConfig; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * @param Access $access |
|
| 55 | + * @param \OCP\IConfig $ocConfig |
|
| 56 | + */ |
|
| 57 | + public function __construct(Access $access, IConfig $ocConfig) { |
|
| 58 | + parent::__construct($access); |
|
| 59 | + $this->ocConfig = $ocConfig; |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * checks whether the user is allowed to change his avatar in ownCloud |
|
| 64 | + * @param string $uid the ownCloud user name |
|
| 65 | + * @return boolean either the user can or cannot |
|
| 66 | + */ |
|
| 67 | + public function canChangeAvatar($uid) { |
|
| 68 | + $user = $this->access->userManager->get($uid); |
|
| 69 | + if(!$user instanceof User) { |
|
| 70 | + return false; |
|
| 71 | + } |
|
| 72 | + if($user->getAvatarImage() === false) { |
|
| 73 | + return true; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + return false; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * returns the username for the given login name, if available |
|
| 81 | + * |
|
| 82 | + * @param string $loginName |
|
| 83 | + * @return string|false |
|
| 84 | + */ |
|
| 85 | + public function loginName2UserName($loginName) { |
|
| 86 | + $cacheKey = 'loginName2UserName-'.$loginName; |
|
| 87 | + $username = $this->access->connection->getFromCache($cacheKey); |
|
| 88 | + if(!is_null($username)) { |
|
| 89 | + return $username; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + try { |
|
| 93 | + $ldapRecord = $this->getLDAPUserByLoginName($loginName); |
|
| 94 | + $user = $this->access->userManager->get($ldapRecord['dn'][0]); |
|
| 95 | + if($user instanceof OfflineUser) { |
|
| 96 | + // this path is not really possible, however get() is documented |
|
| 97 | + // to return User or OfflineUser so we are very defensive here. |
|
| 98 | + $this->access->connection->writeToCache($cacheKey, false); |
|
| 99 | + return false; |
|
| 100 | + } |
|
| 101 | + $username = $user->getUsername(); |
|
| 102 | + $this->access->connection->writeToCache($cacheKey, $username); |
|
| 103 | + return $username; |
|
| 104 | + } catch (NotOnLDAP $e) { |
|
| 105 | + $this->access->connection->writeToCache($cacheKey, false); |
|
| 106 | + return false; |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | - /** |
|
| 111 | - * returns the username for the given LDAP DN, if available |
|
| 112 | - * |
|
| 113 | - * @param string $dn |
|
| 114 | - * @return string|false with the username |
|
| 115 | - */ |
|
| 116 | - public function dn2UserName($dn) { |
|
| 117 | - return $this->access->dn2username($dn); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * returns an LDAP record based on a given login name |
|
| 122 | - * |
|
| 123 | - * @param string $loginName |
|
| 124 | - * @return array |
|
| 125 | - * @throws NotOnLDAP |
|
| 126 | - */ |
|
| 127 | - public function getLDAPUserByLoginName($loginName) { |
|
| 128 | - //find out dn of the user name |
|
| 129 | - $attrs = $this->access->userManager->getAttributes(); |
|
| 130 | - $users = $this->access->fetchUsersByLoginName($loginName, $attrs); |
|
| 131 | - if(count($users) < 1) { |
|
| 132 | - throw new NotOnLDAP('No user available for the given login name on ' . |
|
| 133 | - $this->access->connection->ldapHost . ':' . $this->access->connection->ldapPort); |
|
| 134 | - } |
|
| 135 | - return $users[0]; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * Check if the password is correct without logging in the user |
|
| 140 | - * |
|
| 141 | - * @param string $uid The username |
|
| 142 | - * @param string $password The password |
|
| 143 | - * @return false|string |
|
| 144 | - */ |
|
| 145 | - public function checkPassword($uid, $password) { |
|
| 146 | - try { |
|
| 147 | - $ldapRecord = $this->getLDAPUserByLoginName($uid); |
|
| 148 | - } catch(NotOnLDAP $e) { |
|
| 149 | - if($this->ocConfig->getSystemValue('loglevel', Util::WARN) === Util::DEBUG) { |
|
| 150 | - \OC::$server->getLogger()->logException($e, ['app' => 'user_ldap']); |
|
| 151 | - } |
|
| 152 | - return false; |
|
| 153 | - } |
|
| 154 | - $dn = $ldapRecord['dn'][0]; |
|
| 155 | - $user = $this->access->userManager->get($dn); |
|
| 156 | - |
|
| 157 | - if(!$user instanceof User) { |
|
| 158 | - Util::writeLog('user_ldap', |
|
| 159 | - 'LDAP Login: Could not get user object for DN ' . $dn . |
|
| 160 | - '. Maybe the LDAP entry has no set display name attribute?', |
|
| 161 | - Util::WARN); |
|
| 162 | - return false; |
|
| 163 | - } |
|
| 164 | - if($user->getUsername() !== false) { |
|
| 165 | - //are the credentials OK? |
|
| 166 | - if(!$this->access->areCredentialsValid($dn, $password)) { |
|
| 167 | - return false; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - $this->access->cacheUserExists($user->getUsername()); |
|
| 171 | - $user->processAttributes($ldapRecord); |
|
| 172 | - $user->markLogin(); |
|
| 173 | - |
|
| 174 | - return $user->getUsername(); |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - return false; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * Set password |
|
| 182 | - * @param string $uid The username |
|
| 183 | - * @param string $password The new password |
|
| 184 | - * @return bool |
|
| 185 | - */ |
|
| 186 | - public function setPassword($uid, $password) { |
|
| 187 | - $user = $this->access->userManager->get($uid); |
|
| 188 | - |
|
| 189 | - if(!$user instanceof User) { |
|
| 190 | - throw new \Exception('LDAP setPassword: Could not get user object for uid ' . $uid . |
|
| 191 | - '. Maybe the LDAP entry has no set display name attribute?'); |
|
| 192 | - } |
|
| 193 | - if($user->getUsername() !== false) { |
|
| 194 | - return $this->access->setPassword($user->getDN(), $password); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - return false; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - /** |
|
| 201 | - * Get a list of all users |
|
| 202 | - * |
|
| 203 | - * @param string $search |
|
| 204 | - * @param integer $limit |
|
| 205 | - * @param integer $offset |
|
| 206 | - * @return string[] an array of all uids |
|
| 207 | - */ |
|
| 208 | - public function getUsers($search = '', $limit = 10, $offset = 0) { |
|
| 209 | - $search = $this->access->escapeFilterPart($search, true); |
|
| 210 | - $cachekey = 'getUsers-'.$search.'-'.$limit.'-'.$offset; |
|
| 211 | - |
|
| 212 | - //check if users are cached, if so return |
|
| 213 | - $ldap_users = $this->access->connection->getFromCache($cachekey); |
|
| 214 | - if(!is_null($ldap_users)) { |
|
| 215 | - return $ldap_users; |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - // if we'd pass -1 to LDAP search, we'd end up in a Protocol |
|
| 219 | - // error. With a limit of 0, we get 0 results. So we pass null. |
|
| 220 | - if($limit <= 0) { |
|
| 221 | - $limit = null; |
|
| 222 | - } |
|
| 223 | - $filter = $this->access->combineFilterWithAnd(array( |
|
| 224 | - $this->access->connection->ldapUserFilter, |
|
| 225 | - $this->access->connection->ldapUserDisplayName . '=*', |
|
| 226 | - $this->access->getFilterPartForUserSearch($search) |
|
| 227 | - )); |
|
| 228 | - |
|
| 229 | - Util::writeLog('user_ldap', |
|
| 230 | - 'getUsers: Options: search '.$search.' limit '.$limit.' offset '.$offset.' Filter: '.$filter, |
|
| 231 | - Util::DEBUG); |
|
| 232 | - //do the search and translate results to owncloud names |
|
| 233 | - $ldap_users = $this->access->fetchListOfUsers( |
|
| 234 | - $filter, |
|
| 235 | - $this->access->userManager->getAttributes(true), |
|
| 236 | - $limit, $offset); |
|
| 237 | - $ldap_users = $this->access->ownCloudUserNames($ldap_users); |
|
| 238 | - Util::writeLog('user_ldap', 'getUsers: '.count($ldap_users). ' Users found', Util::DEBUG); |
|
| 239 | - |
|
| 240 | - $this->access->connection->writeToCache($cachekey, $ldap_users); |
|
| 241 | - return $ldap_users; |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - /** |
|
| 245 | - * checks whether a user is still available on LDAP |
|
| 246 | - * |
|
| 247 | - * @param string|\OCA\User_LDAP\User\User $user either the ownCloud user |
|
| 248 | - * name or an instance of that user |
|
| 249 | - * @return bool |
|
| 250 | - * @throws \Exception |
|
| 251 | - * @throws \OC\ServerNotAvailableException |
|
| 252 | - */ |
|
| 253 | - public function userExistsOnLDAP($user) { |
|
| 254 | - if(is_string($user)) { |
|
| 255 | - $user = $this->access->userManager->get($user); |
|
| 256 | - } |
|
| 257 | - if(is_null($user)) { |
|
| 258 | - return false; |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - $dn = $user->getDN(); |
|
| 262 | - //check if user really still exists by reading its entry |
|
| 263 | - if(!is_array($this->access->readAttribute($dn, '', $this->access->connection->ldapUserFilter))) { |
|
| 264 | - $lcr = $this->access->connection->getConnectionResource(); |
|
| 265 | - if(is_null($lcr)) { |
|
| 266 | - throw new \Exception('No LDAP Connection to server ' . $this->access->connection->ldapHost); |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - try { |
|
| 270 | - $uuid = $this->access->getUserMapper()->getUUIDByDN($dn); |
|
| 271 | - if(!$uuid) { |
|
| 272 | - return false; |
|
| 273 | - } |
|
| 274 | - $newDn = $this->access->getUserDnByUuid($uuid); |
|
| 275 | - //check if renamed user is still valid by reapplying the ldap filter |
|
| 276 | - if(!is_array($this->access->readAttribute($newDn, '', $this->access->connection->ldapUserFilter))) { |
|
| 277 | - return false; |
|
| 278 | - } |
|
| 279 | - $this->access->getUserMapper()->setDNbyUUID($newDn, $uuid); |
|
| 280 | - return true; |
|
| 281 | - } catch (\Exception $e) { |
|
| 282 | - return false; |
|
| 283 | - } |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - if($user instanceof OfflineUser) { |
|
| 287 | - $user->unmark(); |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - return true; |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - /** |
|
| 294 | - * check if a user exists |
|
| 295 | - * @param string $uid the username |
|
| 296 | - * @return boolean |
|
| 297 | - * @throws \Exception when connection could not be established |
|
| 298 | - */ |
|
| 299 | - public function userExists($uid) { |
|
| 300 | - $userExists = $this->access->connection->getFromCache('userExists'.$uid); |
|
| 301 | - if(!is_null($userExists)) { |
|
| 302 | - return (bool)$userExists; |
|
| 303 | - } |
|
| 304 | - //getting dn, if false the user does not exist. If dn, he may be mapped only, requires more checking. |
|
| 305 | - $user = $this->access->userManager->get($uid); |
|
| 306 | - |
|
| 307 | - if(is_null($user)) { |
|
| 308 | - Util::writeLog('user_ldap', 'No DN found for '.$uid.' on '. |
|
| 309 | - $this->access->connection->ldapHost, Util::DEBUG); |
|
| 310 | - $this->access->connection->writeToCache('userExists'.$uid, false); |
|
| 311 | - return false; |
|
| 312 | - } else if($user instanceof OfflineUser) { |
|
| 313 | - //express check for users marked as deleted. Returning true is |
|
| 314 | - //necessary for cleanup |
|
| 315 | - return true; |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - $result = $this->userExistsOnLDAP($user); |
|
| 319 | - $this->access->connection->writeToCache('userExists'.$uid, $result); |
|
| 320 | - if($result === true) { |
|
| 321 | - $user->update(); |
|
| 322 | - } |
|
| 323 | - return $result; |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - /** |
|
| 327 | - * returns whether a user was deleted in LDAP |
|
| 328 | - * |
|
| 329 | - * @param string $uid The username of the user to delete |
|
| 330 | - * @return bool |
|
| 331 | - */ |
|
| 332 | - public function deleteUser($uid) { |
|
| 333 | - $marked = $this->ocConfig->getUserValue($uid, 'user_ldap', 'isDeleted', 0); |
|
| 334 | - if(intval($marked) === 0) { |
|
| 335 | - \OC::$server->getLogger()->notice( |
|
| 336 | - 'User '.$uid . ' is not marked as deleted, not cleaning up.', |
|
| 337 | - array('app' => 'user_ldap')); |
|
| 338 | - return false; |
|
| 339 | - } |
|
| 340 | - \OC::$server->getLogger()->info('Cleaning up after user ' . $uid, |
|
| 341 | - array('app' => 'user_ldap')); |
|
| 342 | - |
|
| 343 | - //Get Home Directory out of user preferences so we can return it later, |
|
| 344 | - //necessary for removing directories as done by OC_User. |
|
| 345 | - $home = $this->ocConfig->getUserValue($uid, 'user_ldap', 'homePath', ''); |
|
| 346 | - $this->homesToKill[$uid] = $home; |
|
| 347 | - $this->access->getUserMapper()->unmap($uid); |
|
| 348 | - |
|
| 349 | - return true; |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * get the user's home directory |
|
| 354 | - * |
|
| 355 | - * @param string $uid the username |
|
| 356 | - * @return bool|string |
|
| 357 | - * @throws NoUserException |
|
| 358 | - * @throws \Exception |
|
| 359 | - */ |
|
| 360 | - public function getHome($uid) { |
|
| 361 | - if(isset($this->homesToKill[$uid]) && !empty($this->homesToKill[$uid])) { |
|
| 362 | - //a deleted user who needs some clean up |
|
| 363 | - return $this->homesToKill[$uid]; |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - // user Exists check required as it is not done in user proxy! |
|
| 367 | - if(!$this->userExists($uid)) { |
|
| 368 | - return false; |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - $cacheKey = 'getHome'.$uid; |
|
| 372 | - $path = $this->access->connection->getFromCache($cacheKey); |
|
| 373 | - if(!is_null($path)) { |
|
| 374 | - return $path; |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - $user = $this->access->userManager->get($uid); |
|
| 378 | - if(is_null($user) || ($user instanceof OfflineUser && !$this->userExistsOnLDAP($user->getOCName()))) { |
|
| 379 | - throw new NoUserException($uid . ' is not a valid user anymore'); |
|
| 380 | - } |
|
| 381 | - if($user instanceof OfflineUser) { |
|
| 382 | - // apparently this user survived the userExistsOnLDAP check, |
|
| 383 | - // we request the user instance again in order to retrieve a User |
|
| 384 | - // instance instead |
|
| 385 | - $user = $this->access->userManager->get($uid); |
|
| 386 | - } |
|
| 387 | - $path = $user->getHomePath(); |
|
| 388 | - $this->access->cacheUserHome($uid, $path); |
|
| 389 | - |
|
| 390 | - return $path; |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - /** |
|
| 394 | - * get display name of the user |
|
| 395 | - * @param string $uid user ID of the user |
|
| 396 | - * @return string|false display name |
|
| 397 | - */ |
|
| 398 | - public function getDisplayName($uid) { |
|
| 399 | - if(!$this->userExists($uid)) { |
|
| 400 | - return false; |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - $cacheKey = 'getDisplayName'.$uid; |
|
| 404 | - if(!is_null($displayName = $this->access->connection->getFromCache($cacheKey))) { |
|
| 405 | - return $displayName; |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - //Check whether the display name is configured to have a 2nd feature |
|
| 409 | - $additionalAttribute = $this->access->connection->ldapUserDisplayName2; |
|
| 410 | - $displayName2 = ''; |
|
| 411 | - if ($additionalAttribute !== '') { |
|
| 412 | - $displayName2 = $this->access->readAttribute( |
|
| 413 | - $this->access->username2dn($uid), |
|
| 414 | - $additionalAttribute); |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - $displayName = $this->access->readAttribute( |
|
| 418 | - $this->access->username2dn($uid), |
|
| 419 | - $this->access->connection->ldapUserDisplayName); |
|
| 420 | - |
|
| 421 | - if($displayName && (count($displayName) > 0)) { |
|
| 422 | - $displayName = $displayName[0]; |
|
| 423 | - |
|
| 424 | - if (is_array($displayName2)){ |
|
| 425 | - $displayName2 = count($displayName2) > 0 ? $displayName2[0] : ''; |
|
| 426 | - } |
|
| 427 | - |
|
| 428 | - $user = $this->access->userManager->get($uid); |
|
| 429 | - if ($user instanceof User) { |
|
| 430 | - $displayName = $user->composeAndStoreDisplayName($displayName, $displayName2); |
|
| 431 | - $this->access->connection->writeToCache($cacheKey, $displayName); |
|
| 432 | - } |
|
| 433 | - if ($user instanceof OfflineUser) { |
|
| 434 | - /** @var OfflineUser $user*/ |
|
| 435 | - $displayName = $user->getDisplayName(); |
|
| 436 | - } |
|
| 437 | - return $displayName; |
|
| 438 | - } |
|
| 439 | - |
|
| 440 | - return null; |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - /** |
|
| 444 | - * Get a list of all display names |
|
| 445 | - * |
|
| 446 | - * @param string $search |
|
| 447 | - * @param string|null $limit |
|
| 448 | - * @param string|null $offset |
|
| 449 | - * @return array an array of all displayNames (value) and the corresponding uids (key) |
|
| 450 | - */ |
|
| 451 | - public function getDisplayNames($search = '', $limit = null, $offset = null) { |
|
| 452 | - $cacheKey = 'getDisplayNames-'.$search.'-'.$limit.'-'.$offset; |
|
| 453 | - if(!is_null($displayNames = $this->access->connection->getFromCache($cacheKey))) { |
|
| 454 | - return $displayNames; |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - $displayNames = array(); |
|
| 458 | - $users = $this->getUsers($search, $limit, $offset); |
|
| 459 | - foreach ($users as $user) { |
|
| 460 | - $displayNames[$user] = $this->getDisplayName($user); |
|
| 461 | - } |
|
| 462 | - $this->access->connection->writeToCache($cacheKey, $displayNames); |
|
| 463 | - return $displayNames; |
|
| 464 | - } |
|
| 465 | - |
|
| 466 | - /** |
|
| 467 | - * Check if backend implements actions |
|
| 468 | - * @param int $actions bitwise-or'ed actions |
|
| 469 | - * @return boolean |
|
| 470 | - * |
|
| 471 | - * Returns the supported actions as int to be |
|
| 472 | - * compared with OC_USER_BACKEND_CREATE_USER etc. |
|
| 473 | - */ |
|
| 474 | - public function implementsActions($actions) { |
|
| 475 | - return (bool)((Backend::CHECK_PASSWORD |
|
| 476 | - | Backend::GET_HOME |
|
| 477 | - | Backend::GET_DISPLAYNAME |
|
| 478 | - | Backend::PROVIDE_AVATAR |
|
| 479 | - | Backend::COUNT_USERS |
|
| 480 | - | ((intval($this->access->connection->turnOnPasswordChange) === 1)?(Backend::SET_PASSWORD):0)) |
|
| 481 | - & $actions); |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - /** |
|
| 485 | - * @return bool |
|
| 486 | - */ |
|
| 487 | - public function hasUserListings() { |
|
| 488 | - return true; |
|
| 489 | - } |
|
| 490 | - |
|
| 491 | - /** |
|
| 492 | - * counts the users in LDAP |
|
| 493 | - * |
|
| 494 | - * @return int|bool |
|
| 495 | - */ |
|
| 496 | - public function countUsers() { |
|
| 497 | - $filter = $this->access->getFilterForUserCount(); |
|
| 498 | - $cacheKey = 'countUsers-'.$filter; |
|
| 499 | - if(!is_null($entries = $this->access->connection->getFromCache($cacheKey))) { |
|
| 500 | - return $entries; |
|
| 501 | - } |
|
| 502 | - $entries = $this->access->countUsers($filter); |
|
| 503 | - $this->access->connection->writeToCache($cacheKey, $entries); |
|
| 504 | - return $entries; |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - /** |
|
| 508 | - * Backend name to be shown in user management |
|
| 509 | - * @return string the name of the backend to be shown |
|
| 510 | - */ |
|
| 511 | - public function getBackendName(){ |
|
| 512 | - return 'LDAP'; |
|
| 513 | - } |
|
| 110 | + /** |
|
| 111 | + * returns the username for the given LDAP DN, if available |
|
| 112 | + * |
|
| 113 | + * @param string $dn |
|
| 114 | + * @return string|false with the username |
|
| 115 | + */ |
|
| 116 | + public function dn2UserName($dn) { |
|
| 117 | + return $this->access->dn2username($dn); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * returns an LDAP record based on a given login name |
|
| 122 | + * |
|
| 123 | + * @param string $loginName |
|
| 124 | + * @return array |
|
| 125 | + * @throws NotOnLDAP |
|
| 126 | + */ |
|
| 127 | + public function getLDAPUserByLoginName($loginName) { |
|
| 128 | + //find out dn of the user name |
|
| 129 | + $attrs = $this->access->userManager->getAttributes(); |
|
| 130 | + $users = $this->access->fetchUsersByLoginName($loginName, $attrs); |
|
| 131 | + if(count($users) < 1) { |
|
| 132 | + throw new NotOnLDAP('No user available for the given login name on ' . |
|
| 133 | + $this->access->connection->ldapHost . ':' . $this->access->connection->ldapPort); |
|
| 134 | + } |
|
| 135 | + return $users[0]; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * Check if the password is correct without logging in the user |
|
| 140 | + * |
|
| 141 | + * @param string $uid The username |
|
| 142 | + * @param string $password The password |
|
| 143 | + * @return false|string |
|
| 144 | + */ |
|
| 145 | + public function checkPassword($uid, $password) { |
|
| 146 | + try { |
|
| 147 | + $ldapRecord = $this->getLDAPUserByLoginName($uid); |
|
| 148 | + } catch(NotOnLDAP $e) { |
|
| 149 | + if($this->ocConfig->getSystemValue('loglevel', Util::WARN) === Util::DEBUG) { |
|
| 150 | + \OC::$server->getLogger()->logException($e, ['app' => 'user_ldap']); |
|
| 151 | + } |
|
| 152 | + return false; |
|
| 153 | + } |
|
| 154 | + $dn = $ldapRecord['dn'][0]; |
|
| 155 | + $user = $this->access->userManager->get($dn); |
|
| 156 | + |
|
| 157 | + if(!$user instanceof User) { |
|
| 158 | + Util::writeLog('user_ldap', |
|
| 159 | + 'LDAP Login: Could not get user object for DN ' . $dn . |
|
| 160 | + '. Maybe the LDAP entry has no set display name attribute?', |
|
| 161 | + Util::WARN); |
|
| 162 | + return false; |
|
| 163 | + } |
|
| 164 | + if($user->getUsername() !== false) { |
|
| 165 | + //are the credentials OK? |
|
| 166 | + if(!$this->access->areCredentialsValid($dn, $password)) { |
|
| 167 | + return false; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + $this->access->cacheUserExists($user->getUsername()); |
|
| 171 | + $user->processAttributes($ldapRecord); |
|
| 172 | + $user->markLogin(); |
|
| 173 | + |
|
| 174 | + return $user->getUsername(); |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + return false; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * Set password |
|
| 182 | + * @param string $uid The username |
|
| 183 | + * @param string $password The new password |
|
| 184 | + * @return bool |
|
| 185 | + */ |
|
| 186 | + public function setPassword($uid, $password) { |
|
| 187 | + $user = $this->access->userManager->get($uid); |
|
| 188 | + |
|
| 189 | + if(!$user instanceof User) { |
|
| 190 | + throw new \Exception('LDAP setPassword: Could not get user object for uid ' . $uid . |
|
| 191 | + '. Maybe the LDAP entry has no set display name attribute?'); |
|
| 192 | + } |
|
| 193 | + if($user->getUsername() !== false) { |
|
| 194 | + return $this->access->setPassword($user->getDN(), $password); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + return false; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + /** |
|
| 201 | + * Get a list of all users |
|
| 202 | + * |
|
| 203 | + * @param string $search |
|
| 204 | + * @param integer $limit |
|
| 205 | + * @param integer $offset |
|
| 206 | + * @return string[] an array of all uids |
|
| 207 | + */ |
|
| 208 | + public function getUsers($search = '', $limit = 10, $offset = 0) { |
|
| 209 | + $search = $this->access->escapeFilterPart($search, true); |
|
| 210 | + $cachekey = 'getUsers-'.$search.'-'.$limit.'-'.$offset; |
|
| 211 | + |
|
| 212 | + //check if users are cached, if so return |
|
| 213 | + $ldap_users = $this->access->connection->getFromCache($cachekey); |
|
| 214 | + if(!is_null($ldap_users)) { |
|
| 215 | + return $ldap_users; |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + // if we'd pass -1 to LDAP search, we'd end up in a Protocol |
|
| 219 | + // error. With a limit of 0, we get 0 results. So we pass null. |
|
| 220 | + if($limit <= 0) { |
|
| 221 | + $limit = null; |
|
| 222 | + } |
|
| 223 | + $filter = $this->access->combineFilterWithAnd(array( |
|
| 224 | + $this->access->connection->ldapUserFilter, |
|
| 225 | + $this->access->connection->ldapUserDisplayName . '=*', |
|
| 226 | + $this->access->getFilterPartForUserSearch($search) |
|
| 227 | + )); |
|
| 228 | + |
|
| 229 | + Util::writeLog('user_ldap', |
|
| 230 | + 'getUsers: Options: search '.$search.' limit '.$limit.' offset '.$offset.' Filter: '.$filter, |
|
| 231 | + Util::DEBUG); |
|
| 232 | + //do the search and translate results to owncloud names |
|
| 233 | + $ldap_users = $this->access->fetchListOfUsers( |
|
| 234 | + $filter, |
|
| 235 | + $this->access->userManager->getAttributes(true), |
|
| 236 | + $limit, $offset); |
|
| 237 | + $ldap_users = $this->access->ownCloudUserNames($ldap_users); |
|
| 238 | + Util::writeLog('user_ldap', 'getUsers: '.count($ldap_users). ' Users found', Util::DEBUG); |
|
| 239 | + |
|
| 240 | + $this->access->connection->writeToCache($cachekey, $ldap_users); |
|
| 241 | + return $ldap_users; |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + /** |
|
| 245 | + * checks whether a user is still available on LDAP |
|
| 246 | + * |
|
| 247 | + * @param string|\OCA\User_LDAP\User\User $user either the ownCloud user |
|
| 248 | + * name or an instance of that user |
|
| 249 | + * @return bool |
|
| 250 | + * @throws \Exception |
|
| 251 | + * @throws \OC\ServerNotAvailableException |
|
| 252 | + */ |
|
| 253 | + public function userExistsOnLDAP($user) { |
|
| 254 | + if(is_string($user)) { |
|
| 255 | + $user = $this->access->userManager->get($user); |
|
| 256 | + } |
|
| 257 | + if(is_null($user)) { |
|
| 258 | + return false; |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + $dn = $user->getDN(); |
|
| 262 | + //check if user really still exists by reading its entry |
|
| 263 | + if(!is_array($this->access->readAttribute($dn, '', $this->access->connection->ldapUserFilter))) { |
|
| 264 | + $lcr = $this->access->connection->getConnectionResource(); |
|
| 265 | + if(is_null($lcr)) { |
|
| 266 | + throw new \Exception('No LDAP Connection to server ' . $this->access->connection->ldapHost); |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + try { |
|
| 270 | + $uuid = $this->access->getUserMapper()->getUUIDByDN($dn); |
|
| 271 | + if(!$uuid) { |
|
| 272 | + return false; |
|
| 273 | + } |
|
| 274 | + $newDn = $this->access->getUserDnByUuid($uuid); |
|
| 275 | + //check if renamed user is still valid by reapplying the ldap filter |
|
| 276 | + if(!is_array($this->access->readAttribute($newDn, '', $this->access->connection->ldapUserFilter))) { |
|
| 277 | + return false; |
|
| 278 | + } |
|
| 279 | + $this->access->getUserMapper()->setDNbyUUID($newDn, $uuid); |
|
| 280 | + return true; |
|
| 281 | + } catch (\Exception $e) { |
|
| 282 | + return false; |
|
| 283 | + } |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + if($user instanceof OfflineUser) { |
|
| 287 | + $user->unmark(); |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + return true; |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + /** |
|
| 294 | + * check if a user exists |
|
| 295 | + * @param string $uid the username |
|
| 296 | + * @return boolean |
|
| 297 | + * @throws \Exception when connection could not be established |
|
| 298 | + */ |
|
| 299 | + public function userExists($uid) { |
|
| 300 | + $userExists = $this->access->connection->getFromCache('userExists'.$uid); |
|
| 301 | + if(!is_null($userExists)) { |
|
| 302 | + return (bool)$userExists; |
|
| 303 | + } |
|
| 304 | + //getting dn, if false the user does not exist. If dn, he may be mapped only, requires more checking. |
|
| 305 | + $user = $this->access->userManager->get($uid); |
|
| 306 | + |
|
| 307 | + if(is_null($user)) { |
|
| 308 | + Util::writeLog('user_ldap', 'No DN found for '.$uid.' on '. |
|
| 309 | + $this->access->connection->ldapHost, Util::DEBUG); |
|
| 310 | + $this->access->connection->writeToCache('userExists'.$uid, false); |
|
| 311 | + return false; |
|
| 312 | + } else if($user instanceof OfflineUser) { |
|
| 313 | + //express check for users marked as deleted. Returning true is |
|
| 314 | + //necessary for cleanup |
|
| 315 | + return true; |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + $result = $this->userExistsOnLDAP($user); |
|
| 319 | + $this->access->connection->writeToCache('userExists'.$uid, $result); |
|
| 320 | + if($result === true) { |
|
| 321 | + $user->update(); |
|
| 322 | + } |
|
| 323 | + return $result; |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + /** |
|
| 327 | + * returns whether a user was deleted in LDAP |
|
| 328 | + * |
|
| 329 | + * @param string $uid The username of the user to delete |
|
| 330 | + * @return bool |
|
| 331 | + */ |
|
| 332 | + public function deleteUser($uid) { |
|
| 333 | + $marked = $this->ocConfig->getUserValue($uid, 'user_ldap', 'isDeleted', 0); |
|
| 334 | + if(intval($marked) === 0) { |
|
| 335 | + \OC::$server->getLogger()->notice( |
|
| 336 | + 'User '.$uid . ' is not marked as deleted, not cleaning up.', |
|
| 337 | + array('app' => 'user_ldap')); |
|
| 338 | + return false; |
|
| 339 | + } |
|
| 340 | + \OC::$server->getLogger()->info('Cleaning up after user ' . $uid, |
|
| 341 | + array('app' => 'user_ldap')); |
|
| 342 | + |
|
| 343 | + //Get Home Directory out of user preferences so we can return it later, |
|
| 344 | + //necessary for removing directories as done by OC_User. |
|
| 345 | + $home = $this->ocConfig->getUserValue($uid, 'user_ldap', 'homePath', ''); |
|
| 346 | + $this->homesToKill[$uid] = $home; |
|
| 347 | + $this->access->getUserMapper()->unmap($uid); |
|
| 348 | + |
|
| 349 | + return true; |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * get the user's home directory |
|
| 354 | + * |
|
| 355 | + * @param string $uid the username |
|
| 356 | + * @return bool|string |
|
| 357 | + * @throws NoUserException |
|
| 358 | + * @throws \Exception |
|
| 359 | + */ |
|
| 360 | + public function getHome($uid) { |
|
| 361 | + if(isset($this->homesToKill[$uid]) && !empty($this->homesToKill[$uid])) { |
|
| 362 | + //a deleted user who needs some clean up |
|
| 363 | + return $this->homesToKill[$uid]; |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + // user Exists check required as it is not done in user proxy! |
|
| 367 | + if(!$this->userExists($uid)) { |
|
| 368 | + return false; |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + $cacheKey = 'getHome'.$uid; |
|
| 372 | + $path = $this->access->connection->getFromCache($cacheKey); |
|
| 373 | + if(!is_null($path)) { |
|
| 374 | + return $path; |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + $user = $this->access->userManager->get($uid); |
|
| 378 | + if(is_null($user) || ($user instanceof OfflineUser && !$this->userExistsOnLDAP($user->getOCName()))) { |
|
| 379 | + throw new NoUserException($uid . ' is not a valid user anymore'); |
|
| 380 | + } |
|
| 381 | + if($user instanceof OfflineUser) { |
|
| 382 | + // apparently this user survived the userExistsOnLDAP check, |
|
| 383 | + // we request the user instance again in order to retrieve a User |
|
| 384 | + // instance instead |
|
| 385 | + $user = $this->access->userManager->get($uid); |
|
| 386 | + } |
|
| 387 | + $path = $user->getHomePath(); |
|
| 388 | + $this->access->cacheUserHome($uid, $path); |
|
| 389 | + |
|
| 390 | + return $path; |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + /** |
|
| 394 | + * get display name of the user |
|
| 395 | + * @param string $uid user ID of the user |
|
| 396 | + * @return string|false display name |
|
| 397 | + */ |
|
| 398 | + public function getDisplayName($uid) { |
|
| 399 | + if(!$this->userExists($uid)) { |
|
| 400 | + return false; |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + $cacheKey = 'getDisplayName'.$uid; |
|
| 404 | + if(!is_null($displayName = $this->access->connection->getFromCache($cacheKey))) { |
|
| 405 | + return $displayName; |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + //Check whether the display name is configured to have a 2nd feature |
|
| 409 | + $additionalAttribute = $this->access->connection->ldapUserDisplayName2; |
|
| 410 | + $displayName2 = ''; |
|
| 411 | + if ($additionalAttribute !== '') { |
|
| 412 | + $displayName2 = $this->access->readAttribute( |
|
| 413 | + $this->access->username2dn($uid), |
|
| 414 | + $additionalAttribute); |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + $displayName = $this->access->readAttribute( |
|
| 418 | + $this->access->username2dn($uid), |
|
| 419 | + $this->access->connection->ldapUserDisplayName); |
|
| 420 | + |
|
| 421 | + if($displayName && (count($displayName) > 0)) { |
|
| 422 | + $displayName = $displayName[0]; |
|
| 423 | + |
|
| 424 | + if (is_array($displayName2)){ |
|
| 425 | + $displayName2 = count($displayName2) > 0 ? $displayName2[0] : ''; |
|
| 426 | + } |
|
| 427 | + |
|
| 428 | + $user = $this->access->userManager->get($uid); |
|
| 429 | + if ($user instanceof User) { |
|
| 430 | + $displayName = $user->composeAndStoreDisplayName($displayName, $displayName2); |
|
| 431 | + $this->access->connection->writeToCache($cacheKey, $displayName); |
|
| 432 | + } |
|
| 433 | + if ($user instanceof OfflineUser) { |
|
| 434 | + /** @var OfflineUser $user*/ |
|
| 435 | + $displayName = $user->getDisplayName(); |
|
| 436 | + } |
|
| 437 | + return $displayName; |
|
| 438 | + } |
|
| 439 | + |
|
| 440 | + return null; |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + /** |
|
| 444 | + * Get a list of all display names |
|
| 445 | + * |
|
| 446 | + * @param string $search |
|
| 447 | + * @param string|null $limit |
|
| 448 | + * @param string|null $offset |
|
| 449 | + * @return array an array of all displayNames (value) and the corresponding uids (key) |
|
| 450 | + */ |
|
| 451 | + public function getDisplayNames($search = '', $limit = null, $offset = null) { |
|
| 452 | + $cacheKey = 'getDisplayNames-'.$search.'-'.$limit.'-'.$offset; |
|
| 453 | + if(!is_null($displayNames = $this->access->connection->getFromCache($cacheKey))) { |
|
| 454 | + return $displayNames; |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + $displayNames = array(); |
|
| 458 | + $users = $this->getUsers($search, $limit, $offset); |
|
| 459 | + foreach ($users as $user) { |
|
| 460 | + $displayNames[$user] = $this->getDisplayName($user); |
|
| 461 | + } |
|
| 462 | + $this->access->connection->writeToCache($cacheKey, $displayNames); |
|
| 463 | + return $displayNames; |
|
| 464 | + } |
|
| 465 | + |
|
| 466 | + /** |
|
| 467 | + * Check if backend implements actions |
|
| 468 | + * @param int $actions bitwise-or'ed actions |
|
| 469 | + * @return boolean |
|
| 470 | + * |
|
| 471 | + * Returns the supported actions as int to be |
|
| 472 | + * compared with OC_USER_BACKEND_CREATE_USER etc. |
|
| 473 | + */ |
|
| 474 | + public function implementsActions($actions) { |
|
| 475 | + return (bool)((Backend::CHECK_PASSWORD |
|
| 476 | + | Backend::GET_HOME |
|
| 477 | + | Backend::GET_DISPLAYNAME |
|
| 478 | + | Backend::PROVIDE_AVATAR |
|
| 479 | + | Backend::COUNT_USERS |
|
| 480 | + | ((intval($this->access->connection->turnOnPasswordChange) === 1)?(Backend::SET_PASSWORD):0)) |
|
| 481 | + & $actions); |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + /** |
|
| 485 | + * @return bool |
|
| 486 | + */ |
|
| 487 | + public function hasUserListings() { |
|
| 488 | + return true; |
|
| 489 | + } |
|
| 490 | + |
|
| 491 | + /** |
|
| 492 | + * counts the users in LDAP |
|
| 493 | + * |
|
| 494 | + * @return int|bool |
|
| 495 | + */ |
|
| 496 | + public function countUsers() { |
|
| 497 | + $filter = $this->access->getFilterForUserCount(); |
|
| 498 | + $cacheKey = 'countUsers-'.$filter; |
|
| 499 | + if(!is_null($entries = $this->access->connection->getFromCache($cacheKey))) { |
|
| 500 | + return $entries; |
|
| 501 | + } |
|
| 502 | + $entries = $this->access->countUsers($filter); |
|
| 503 | + $this->access->connection->writeToCache($cacheKey, $entries); |
|
| 504 | + return $entries; |
|
| 505 | + } |
|
| 506 | + |
|
| 507 | + /** |
|
| 508 | + * Backend name to be shown in user management |
|
| 509 | + * @return string the name of the backend to be shown |
|
| 510 | + */ |
|
| 511 | + public function getBackendName(){ |
|
| 512 | + return 'LDAP'; |
|
| 513 | + } |
|
| 514 | 514 | |
| 515 | - /** |
|
| 516 | - * Return access for LDAP interaction. |
|
| 517 | - * @param string $uid |
|
| 518 | - * @return Access instance of Access for LDAP interaction |
|
| 519 | - */ |
|
| 520 | - public function getLDAPAccess($uid) { |
|
| 521 | - return $this->access; |
|
| 522 | - } |
|
| 515 | + /** |
|
| 516 | + * Return access for LDAP interaction. |
|
| 517 | + * @param string $uid |
|
| 518 | + * @return Access instance of Access for LDAP interaction |
|
| 519 | + */ |
|
| 520 | + public function getLDAPAccess($uid) { |
|
| 521 | + return $this->access; |
|
| 522 | + } |
|
| 523 | 523 | |
| 524 | - /** |
|
| 525 | - * Return LDAP connection resource from a cloned connection. |
|
| 526 | - * The cloned connection needs to be closed manually. |
|
| 527 | - * of the current access. |
|
| 528 | - * @param string $uid |
|
| 529 | - * @return resource of the LDAP connection |
|
| 530 | - */ |
|
| 531 | - public function getNewLDAPConnection($uid) { |
|
| 532 | - $connection = clone $this->access->getConnection(); |
|
| 533 | - return $connection->getConnectionResource(); |
|
| 534 | - } |
|
| 524 | + /** |
|
| 525 | + * Return LDAP connection resource from a cloned connection. |
|
| 526 | + * The cloned connection needs to be closed manually. |
|
| 527 | + * of the current access. |
|
| 528 | + * @param string $uid |
|
| 529 | + * @return resource of the LDAP connection |
|
| 530 | + */ |
|
| 531 | + public function getNewLDAPConnection($uid) { |
|
| 532 | + $connection = clone $this->access->getConnection(); |
|
| 533 | + return $connection->getConnectionResource(); |
|
| 534 | + } |
|
| 535 | 535 | } |
@@ -66,10 +66,10 @@ discard block |
||
| 66 | 66 | */ |
| 67 | 67 | public function canChangeAvatar($uid) { |
| 68 | 68 | $user = $this->access->userManager->get($uid); |
| 69 | - if(!$user instanceof User) { |
|
| 69 | + if (!$user instanceof User) { |
|
| 70 | 70 | return false; |
| 71 | 71 | } |
| 72 | - if($user->getAvatarImage() === false) { |
|
| 72 | + if ($user->getAvatarImage() === false) { |
|
| 73 | 73 | return true; |
| 74 | 74 | } |
| 75 | 75 | |
@@ -85,14 +85,14 @@ discard block |
||
| 85 | 85 | public function loginName2UserName($loginName) { |
| 86 | 86 | $cacheKey = 'loginName2UserName-'.$loginName; |
| 87 | 87 | $username = $this->access->connection->getFromCache($cacheKey); |
| 88 | - if(!is_null($username)) { |
|
| 88 | + if (!is_null($username)) { |
|
| 89 | 89 | return $username; |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | try { |
| 93 | 93 | $ldapRecord = $this->getLDAPUserByLoginName($loginName); |
| 94 | 94 | $user = $this->access->userManager->get($ldapRecord['dn'][0]); |
| 95 | - if($user instanceof OfflineUser) { |
|
| 95 | + if ($user instanceof OfflineUser) { |
|
| 96 | 96 | // this path is not really possible, however get() is documented |
| 97 | 97 | // to return User or OfflineUser so we are very defensive here. |
| 98 | 98 | $this->access->connection->writeToCache($cacheKey, false); |
@@ -128,9 +128,9 @@ discard block |
||
| 128 | 128 | //find out dn of the user name |
| 129 | 129 | $attrs = $this->access->userManager->getAttributes(); |
| 130 | 130 | $users = $this->access->fetchUsersByLoginName($loginName, $attrs); |
| 131 | - if(count($users) < 1) { |
|
| 132 | - throw new NotOnLDAP('No user available for the given login name on ' . |
|
| 133 | - $this->access->connection->ldapHost . ':' . $this->access->connection->ldapPort); |
|
| 131 | + if (count($users) < 1) { |
|
| 132 | + throw new NotOnLDAP('No user available for the given login name on '. |
|
| 133 | + $this->access->connection->ldapHost.':'.$this->access->connection->ldapPort); |
|
| 134 | 134 | } |
| 135 | 135 | return $users[0]; |
| 136 | 136 | } |
@@ -145,8 +145,8 @@ discard block |
||
| 145 | 145 | public function checkPassword($uid, $password) { |
| 146 | 146 | try { |
| 147 | 147 | $ldapRecord = $this->getLDAPUserByLoginName($uid); |
| 148 | - } catch(NotOnLDAP $e) { |
|
| 149 | - if($this->ocConfig->getSystemValue('loglevel', Util::WARN) === Util::DEBUG) { |
|
| 148 | + } catch (NotOnLDAP $e) { |
|
| 149 | + if ($this->ocConfig->getSystemValue('loglevel', Util::WARN) === Util::DEBUG) { |
|
| 150 | 150 | \OC::$server->getLogger()->logException($e, ['app' => 'user_ldap']); |
| 151 | 151 | } |
| 152 | 152 | return false; |
@@ -154,16 +154,16 @@ discard block |
||
| 154 | 154 | $dn = $ldapRecord['dn'][0]; |
| 155 | 155 | $user = $this->access->userManager->get($dn); |
| 156 | 156 | |
| 157 | - if(!$user instanceof User) { |
|
| 157 | + if (!$user instanceof User) { |
|
| 158 | 158 | Util::writeLog('user_ldap', |
| 159 | - 'LDAP Login: Could not get user object for DN ' . $dn . |
|
| 159 | + 'LDAP Login: Could not get user object for DN '.$dn. |
|
| 160 | 160 | '. Maybe the LDAP entry has no set display name attribute?', |
| 161 | 161 | Util::WARN); |
| 162 | 162 | return false; |
| 163 | 163 | } |
| 164 | - if($user->getUsername() !== false) { |
|
| 164 | + if ($user->getUsername() !== false) { |
|
| 165 | 165 | //are the credentials OK? |
| 166 | - if(!$this->access->areCredentialsValid($dn, $password)) { |
|
| 166 | + if (!$this->access->areCredentialsValid($dn, $password)) { |
|
| 167 | 167 | return false; |
| 168 | 168 | } |
| 169 | 169 | |
@@ -186,11 +186,11 @@ discard block |
||
| 186 | 186 | public function setPassword($uid, $password) { |
| 187 | 187 | $user = $this->access->userManager->get($uid); |
| 188 | 188 | |
| 189 | - if(!$user instanceof User) { |
|
| 190 | - throw new \Exception('LDAP setPassword: Could not get user object for uid ' . $uid . |
|
| 189 | + if (!$user instanceof User) { |
|
| 190 | + throw new \Exception('LDAP setPassword: Could not get user object for uid '.$uid. |
|
| 191 | 191 | '. Maybe the LDAP entry has no set display name attribute?'); |
| 192 | 192 | } |
| 193 | - if($user->getUsername() !== false) { |
|
| 193 | + if ($user->getUsername() !== false) { |
|
| 194 | 194 | return $this->access->setPassword($user->getDN(), $password); |
| 195 | 195 | } |
| 196 | 196 | |
@@ -211,18 +211,18 @@ discard block |
||
| 211 | 211 | |
| 212 | 212 | //check if users are cached, if so return |
| 213 | 213 | $ldap_users = $this->access->connection->getFromCache($cachekey); |
| 214 | - if(!is_null($ldap_users)) { |
|
| 214 | + if (!is_null($ldap_users)) { |
|
| 215 | 215 | return $ldap_users; |
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | // if we'd pass -1 to LDAP search, we'd end up in a Protocol |
| 219 | 219 | // error. With a limit of 0, we get 0 results. So we pass null. |
| 220 | - if($limit <= 0) { |
|
| 220 | + if ($limit <= 0) { |
|
| 221 | 221 | $limit = null; |
| 222 | 222 | } |
| 223 | 223 | $filter = $this->access->combineFilterWithAnd(array( |
| 224 | 224 | $this->access->connection->ldapUserFilter, |
| 225 | - $this->access->connection->ldapUserDisplayName . '=*', |
|
| 225 | + $this->access->connection->ldapUserDisplayName.'=*', |
|
| 226 | 226 | $this->access->getFilterPartForUserSearch($search) |
| 227 | 227 | )); |
| 228 | 228 | |
@@ -235,7 +235,7 @@ discard block |
||
| 235 | 235 | $this->access->userManager->getAttributes(true), |
| 236 | 236 | $limit, $offset); |
| 237 | 237 | $ldap_users = $this->access->ownCloudUserNames($ldap_users); |
| 238 | - Util::writeLog('user_ldap', 'getUsers: '.count($ldap_users). ' Users found', Util::DEBUG); |
|
| 238 | + Util::writeLog('user_ldap', 'getUsers: '.count($ldap_users).' Users found', Util::DEBUG); |
|
| 239 | 239 | |
| 240 | 240 | $this->access->connection->writeToCache($cachekey, $ldap_users); |
| 241 | 241 | return $ldap_users; |
@@ -251,29 +251,29 @@ discard block |
||
| 251 | 251 | * @throws \OC\ServerNotAvailableException |
| 252 | 252 | */ |
| 253 | 253 | public function userExistsOnLDAP($user) { |
| 254 | - if(is_string($user)) { |
|
| 254 | + if (is_string($user)) { |
|
| 255 | 255 | $user = $this->access->userManager->get($user); |
| 256 | 256 | } |
| 257 | - if(is_null($user)) { |
|
| 257 | + if (is_null($user)) { |
|
| 258 | 258 | return false; |
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | $dn = $user->getDN(); |
| 262 | 262 | //check if user really still exists by reading its entry |
| 263 | - if(!is_array($this->access->readAttribute($dn, '', $this->access->connection->ldapUserFilter))) { |
|
| 263 | + if (!is_array($this->access->readAttribute($dn, '', $this->access->connection->ldapUserFilter))) { |
|
| 264 | 264 | $lcr = $this->access->connection->getConnectionResource(); |
| 265 | - if(is_null($lcr)) { |
|
| 266 | - throw new \Exception('No LDAP Connection to server ' . $this->access->connection->ldapHost); |
|
| 265 | + if (is_null($lcr)) { |
|
| 266 | + throw new \Exception('No LDAP Connection to server '.$this->access->connection->ldapHost); |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | try { |
| 270 | 270 | $uuid = $this->access->getUserMapper()->getUUIDByDN($dn); |
| 271 | - if(!$uuid) { |
|
| 271 | + if (!$uuid) { |
|
| 272 | 272 | return false; |
| 273 | 273 | } |
| 274 | 274 | $newDn = $this->access->getUserDnByUuid($uuid); |
| 275 | 275 | //check if renamed user is still valid by reapplying the ldap filter |
| 276 | - if(!is_array($this->access->readAttribute($newDn, '', $this->access->connection->ldapUserFilter))) { |
|
| 276 | + if (!is_array($this->access->readAttribute($newDn, '', $this->access->connection->ldapUserFilter))) { |
|
| 277 | 277 | return false; |
| 278 | 278 | } |
| 279 | 279 | $this->access->getUserMapper()->setDNbyUUID($newDn, $uuid); |
@@ -283,7 +283,7 @@ discard block |
||
| 283 | 283 | } |
| 284 | 284 | } |
| 285 | 285 | |
| 286 | - if($user instanceof OfflineUser) { |
|
| 286 | + if ($user instanceof OfflineUser) { |
|
| 287 | 287 | $user->unmark(); |
| 288 | 288 | } |
| 289 | 289 | |
@@ -298,18 +298,18 @@ discard block |
||
| 298 | 298 | */ |
| 299 | 299 | public function userExists($uid) { |
| 300 | 300 | $userExists = $this->access->connection->getFromCache('userExists'.$uid); |
| 301 | - if(!is_null($userExists)) { |
|
| 302 | - return (bool)$userExists; |
|
| 301 | + if (!is_null($userExists)) { |
|
| 302 | + return (bool) $userExists; |
|
| 303 | 303 | } |
| 304 | 304 | //getting dn, if false the user does not exist. If dn, he may be mapped only, requires more checking. |
| 305 | 305 | $user = $this->access->userManager->get($uid); |
| 306 | 306 | |
| 307 | - if(is_null($user)) { |
|
| 307 | + if (is_null($user)) { |
|
| 308 | 308 | Util::writeLog('user_ldap', 'No DN found for '.$uid.' on '. |
| 309 | 309 | $this->access->connection->ldapHost, Util::DEBUG); |
| 310 | 310 | $this->access->connection->writeToCache('userExists'.$uid, false); |
| 311 | 311 | return false; |
| 312 | - } else if($user instanceof OfflineUser) { |
|
| 312 | + } else if ($user instanceof OfflineUser) { |
|
| 313 | 313 | //express check for users marked as deleted. Returning true is |
| 314 | 314 | //necessary for cleanup |
| 315 | 315 | return true; |
@@ -317,7 +317,7 @@ discard block |
||
| 317 | 317 | |
| 318 | 318 | $result = $this->userExistsOnLDAP($user); |
| 319 | 319 | $this->access->connection->writeToCache('userExists'.$uid, $result); |
| 320 | - if($result === true) { |
|
| 320 | + if ($result === true) { |
|
| 321 | 321 | $user->update(); |
| 322 | 322 | } |
| 323 | 323 | return $result; |
@@ -331,13 +331,13 @@ discard block |
||
| 331 | 331 | */ |
| 332 | 332 | public function deleteUser($uid) { |
| 333 | 333 | $marked = $this->ocConfig->getUserValue($uid, 'user_ldap', 'isDeleted', 0); |
| 334 | - if(intval($marked) === 0) { |
|
| 334 | + if (intval($marked) === 0) { |
|
| 335 | 335 | \OC::$server->getLogger()->notice( |
| 336 | - 'User '.$uid . ' is not marked as deleted, not cleaning up.', |
|
| 336 | + 'User '.$uid.' is not marked as deleted, not cleaning up.', |
|
| 337 | 337 | array('app' => 'user_ldap')); |
| 338 | 338 | return false; |
| 339 | 339 | } |
| 340 | - \OC::$server->getLogger()->info('Cleaning up after user ' . $uid, |
|
| 340 | + \OC::$server->getLogger()->info('Cleaning up after user '.$uid, |
|
| 341 | 341 | array('app' => 'user_ldap')); |
| 342 | 342 | |
| 343 | 343 | //Get Home Directory out of user preferences so we can return it later, |
@@ -358,27 +358,27 @@ discard block |
||
| 358 | 358 | * @throws \Exception |
| 359 | 359 | */ |
| 360 | 360 | public function getHome($uid) { |
| 361 | - if(isset($this->homesToKill[$uid]) && !empty($this->homesToKill[$uid])) { |
|
| 361 | + if (isset($this->homesToKill[$uid]) && !empty($this->homesToKill[$uid])) { |
|
| 362 | 362 | //a deleted user who needs some clean up |
| 363 | 363 | return $this->homesToKill[$uid]; |
| 364 | 364 | } |
| 365 | 365 | |
| 366 | 366 | // user Exists check required as it is not done in user proxy! |
| 367 | - if(!$this->userExists($uid)) { |
|
| 367 | + if (!$this->userExists($uid)) { |
|
| 368 | 368 | return false; |
| 369 | 369 | } |
| 370 | 370 | |
| 371 | 371 | $cacheKey = 'getHome'.$uid; |
| 372 | 372 | $path = $this->access->connection->getFromCache($cacheKey); |
| 373 | - if(!is_null($path)) { |
|
| 373 | + if (!is_null($path)) { |
|
| 374 | 374 | return $path; |
| 375 | 375 | } |
| 376 | 376 | |
| 377 | 377 | $user = $this->access->userManager->get($uid); |
| 378 | - if(is_null($user) || ($user instanceof OfflineUser && !$this->userExistsOnLDAP($user->getOCName()))) { |
|
| 379 | - throw new NoUserException($uid . ' is not a valid user anymore'); |
|
| 378 | + if (is_null($user) || ($user instanceof OfflineUser && !$this->userExistsOnLDAP($user->getOCName()))) { |
|
| 379 | + throw new NoUserException($uid.' is not a valid user anymore'); |
|
| 380 | 380 | } |
| 381 | - if($user instanceof OfflineUser) { |
|
| 381 | + if ($user instanceof OfflineUser) { |
|
| 382 | 382 | // apparently this user survived the userExistsOnLDAP check, |
| 383 | 383 | // we request the user instance again in order to retrieve a User |
| 384 | 384 | // instance instead |
@@ -396,12 +396,12 @@ discard block |
||
| 396 | 396 | * @return string|false display name |
| 397 | 397 | */ |
| 398 | 398 | public function getDisplayName($uid) { |
| 399 | - if(!$this->userExists($uid)) { |
|
| 399 | + if (!$this->userExists($uid)) { |
|
| 400 | 400 | return false; |
| 401 | 401 | } |
| 402 | 402 | |
| 403 | 403 | $cacheKey = 'getDisplayName'.$uid; |
| 404 | - if(!is_null($displayName = $this->access->connection->getFromCache($cacheKey))) { |
|
| 404 | + if (!is_null($displayName = $this->access->connection->getFromCache($cacheKey))) { |
|
| 405 | 405 | return $displayName; |
| 406 | 406 | } |
| 407 | 407 | |
@@ -418,10 +418,10 @@ discard block |
||
| 418 | 418 | $this->access->username2dn($uid), |
| 419 | 419 | $this->access->connection->ldapUserDisplayName); |
| 420 | 420 | |
| 421 | - if($displayName && (count($displayName) > 0)) { |
|
| 421 | + if ($displayName && (count($displayName) > 0)) { |
|
| 422 | 422 | $displayName = $displayName[0]; |
| 423 | 423 | |
| 424 | - if (is_array($displayName2)){ |
|
| 424 | + if (is_array($displayName2)) { |
|
| 425 | 425 | $displayName2 = count($displayName2) > 0 ? $displayName2[0] : ''; |
| 426 | 426 | } |
| 427 | 427 | |
@@ -450,7 +450,7 @@ discard block |
||
| 450 | 450 | */ |
| 451 | 451 | public function getDisplayNames($search = '', $limit = null, $offset = null) { |
| 452 | 452 | $cacheKey = 'getDisplayNames-'.$search.'-'.$limit.'-'.$offset; |
| 453 | - if(!is_null($displayNames = $this->access->connection->getFromCache($cacheKey))) { |
|
| 453 | + if (!is_null($displayNames = $this->access->connection->getFromCache($cacheKey))) { |
|
| 454 | 454 | return $displayNames; |
| 455 | 455 | } |
| 456 | 456 | |
@@ -472,12 +472,12 @@ discard block |
||
| 472 | 472 | * compared with OC_USER_BACKEND_CREATE_USER etc. |
| 473 | 473 | */ |
| 474 | 474 | public function implementsActions($actions) { |
| 475 | - return (bool)((Backend::CHECK_PASSWORD |
|
| 475 | + return (bool) ((Backend::CHECK_PASSWORD |
|
| 476 | 476 | | Backend::GET_HOME |
| 477 | 477 | | Backend::GET_DISPLAYNAME |
| 478 | 478 | | Backend::PROVIDE_AVATAR |
| 479 | 479 | | Backend::COUNT_USERS |
| 480 | - | ((intval($this->access->connection->turnOnPasswordChange) === 1)?(Backend::SET_PASSWORD):0)) |
|
| 480 | + | ((intval($this->access->connection->turnOnPasswordChange) === 1) ? (Backend::SET_PASSWORD) : 0)) |
|
| 481 | 481 | & $actions); |
| 482 | 482 | } |
| 483 | 483 | |
@@ -496,7 +496,7 @@ discard block |
||
| 496 | 496 | public function countUsers() { |
| 497 | 497 | $filter = $this->access->getFilterForUserCount(); |
| 498 | 498 | $cacheKey = 'countUsers-'.$filter; |
| 499 | - if(!is_null($entries = $this->access->connection->getFromCache($cacheKey))) { |
|
| 499 | + if (!is_null($entries = $this->access->connection->getFromCache($cacheKey))) { |
|
| 500 | 500 | return $entries; |
| 501 | 501 | } |
| 502 | 502 | $entries = $this->access->countUsers($filter); |
@@ -508,7 +508,7 @@ discard block |
||
| 508 | 508 | * Backend name to be shown in user management |
| 509 | 509 | * @return string the name of the backend to be shown |
| 510 | 510 | */ |
| 511 | - public function getBackendName(){ |
|
| 511 | + public function getBackendName() { |
|
| 512 | 512 | return 'LDAP'; |
| 513 | 513 | } |
| 514 | 514 | |
@@ -28,13 +28,13 @@ |
||
| 28 | 28 | * @brief wraps around static ownCloud core methods |
| 29 | 29 | */ |
| 30 | 30 | class LogWrapper { |
| 31 | - protected $app = 'user_ldap'; |
|
| 31 | + protected $app = 'user_ldap'; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @brief states whether the filesystem was loaded |
|
| 35 | - * @return bool |
|
| 36 | - */ |
|
| 37 | - public function log($msg, $level) { |
|
| 38 | - \OCP\Util::writeLog($this->app, $msg, $level); |
|
| 39 | - } |
|
| 33 | + /** |
|
| 34 | + * @brief states whether the filesystem was loaded |
|
| 35 | + * @return bool |
|
| 36 | + */ |
|
| 37 | + public function log($msg, $level) { |
|
| 38 | + \OCP\Util::writeLog($this->app, $msg, $level); |
|
| 39 | + } |
|
| 40 | 40 | } |
@@ -28,32 +28,32 @@ |
||
| 28 | 28 | use OCA\User_LDAP\Mapping\UserMapping; |
| 29 | 29 | |
| 30 | 30 | class LDAPProviderFactory implements ILDAPProviderFactory { |
| 31 | - /** |
|
| 32 | - * Server container |
|
| 33 | - * |
|
| 34 | - * @var IServerContainer |
|
| 35 | - */ |
|
| 36 | - private $serverContainer; |
|
| 31 | + /** |
|
| 32 | + * Server container |
|
| 33 | + * |
|
| 34 | + * @var IServerContainer |
|
| 35 | + */ |
|
| 36 | + private $serverContainer; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Constructor for the LDAP provider factory |
|
| 40 | - * |
|
| 41 | - * @param IServerContainer $serverContainer server container |
|
| 42 | - */ |
|
| 43 | - public function __construct(IServerContainer $serverContainer) { |
|
| 44 | - $this->serverContainer = $serverContainer; |
|
| 45 | - } |
|
| 38 | + /** |
|
| 39 | + * Constructor for the LDAP provider factory |
|
| 40 | + * |
|
| 41 | + * @param IServerContainer $serverContainer server container |
|
| 42 | + */ |
|
| 43 | + public function __construct(IServerContainer $serverContainer) { |
|
| 44 | + $this->serverContainer = $serverContainer; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * creates and returns an instance of the ILDAPProvider |
|
| 49 | - * |
|
| 50 | - * @return OCP\LDAP\ILDAPProvider |
|
| 51 | - */ |
|
| 52 | - public function getLDAPProvider() { |
|
| 53 | - $dbConnection = $this->serverContainer->getDatabaseConnection(); |
|
| 54 | - $userMapping = new UserMapping($dbConnection); |
|
| 55 | - return new LDAPProvider($this->serverContainer, new Helper($this->serverContainer->getConfig()), |
|
| 56 | - new DeletedUsersIndex($this->serverContainer->getConfig(), |
|
| 57 | - $dbConnection, $userMapping)); |
|
| 58 | - } |
|
| 47 | + /** |
|
| 48 | + * creates and returns an instance of the ILDAPProvider |
|
| 49 | + * |
|
| 50 | + * @return OCP\LDAP\ILDAPProvider |
|
| 51 | + */ |
|
| 52 | + public function getLDAPProvider() { |
|
| 53 | + $dbConnection = $this->serverContainer->getDatabaseConnection(); |
|
| 54 | + $userMapping = new UserMapping($dbConnection); |
|
| 55 | + return new LDAPProvider($this->serverContainer, new Helper($this->serverContainer->getConfig()), |
|
| 56 | + new DeletedUsersIndex($this->serverContainer->getConfig(), |
|
| 57 | + $dbConnection, $userMapping)); |
|
| 58 | + } |
|
| 59 | 59 | } |
@@ -29,192 +29,192 @@ |
||
| 29 | 29 | |
| 30 | 30 | interface ILDAPWrapper { |
| 31 | 31 | |
| 32 | - //LDAP functions in use |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * Bind to LDAP directory |
|
| 36 | - * @param resource $link LDAP link resource |
|
| 37 | - * @param string $dn an RDN to log in with |
|
| 38 | - * @param string $password the password |
|
| 39 | - * @return bool true on success, false otherwise |
|
| 40 | - * |
|
| 41 | - * with $dn and $password as null a anonymous bind is attempted. |
|
| 42 | - */ |
|
| 43 | - public function bind($link, $dn, $password); |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * connect to an LDAP server |
|
| 47 | - * @param string $host The host to connect to |
|
| 48 | - * @param string $port The port to connect to |
|
| 49 | - * @return mixed a link resource on success, otherwise false |
|
| 50 | - */ |
|
| 51 | - public function connect($host, $port); |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Send LDAP pagination control |
|
| 55 | - * @param resource $link LDAP link resource |
|
| 56 | - * @param int $pageSize number of results per page |
|
| 57 | - * @param bool $isCritical Indicates whether the pagination is critical of not. |
|
| 58 | - * @param string $cookie structure sent by LDAP server |
|
| 59 | - * @return bool true on success, false otherwise |
|
| 60 | - */ |
|
| 61 | - public function controlPagedResult($link, $pageSize, $isCritical, $cookie); |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Retrieve the LDAP pagination cookie |
|
| 65 | - * @param resource $link LDAP link resource |
|
| 66 | - * @param resource $result LDAP result resource |
|
| 67 | - * @param string $cookie structure sent by LDAP server |
|
| 68 | - * @return bool true on success, false otherwise |
|
| 69 | - * |
|
| 70 | - * Corresponds to ldap_control_paged_result_response |
|
| 71 | - */ |
|
| 72 | - public function controlPagedResultResponse($link, $result, &$cookie); |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * Count the number of entries in a search |
|
| 76 | - * @param resource $link LDAP link resource |
|
| 77 | - * @param resource $result LDAP result resource |
|
| 78 | - * @return int|false number of results on success, false otherwise |
|
| 79 | - */ |
|
| 80 | - public function countEntries($link, $result); |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * Return the LDAP error number of the last LDAP command |
|
| 84 | - * @param resource $link LDAP link resource |
|
| 85 | - * @return string error message as string |
|
| 86 | - */ |
|
| 87 | - public function errno($link); |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * Return the LDAP error message of the last LDAP command |
|
| 91 | - * @param resource $link LDAP link resource |
|
| 92 | - * @return int error code as integer |
|
| 93 | - */ |
|
| 94 | - public function error($link); |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * Splits DN into its component parts |
|
| 98 | - * @param string $dn |
|
| 99 | - * @param int @withAttrib |
|
| 100 | - * @return array|false |
|
| 101 | - * @link http://www.php.net/manual/en/function.ldap-explode-dn.php |
|
| 102 | - */ |
|
| 103 | - public function explodeDN($dn, $withAttrib); |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * Return first result id |
|
| 107 | - * @param resource $link LDAP link resource |
|
| 108 | - * @param resource $result LDAP result resource |
|
| 109 | - * @return Resource an LDAP search result resource |
|
| 110 | - * */ |
|
| 111 | - public function firstEntry($link, $result); |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * Get attributes from a search result entry |
|
| 115 | - * @param resource $link LDAP link resource |
|
| 116 | - * @param resource $result LDAP result resource |
|
| 117 | - * @return array containing the results, false on error |
|
| 118 | - * */ |
|
| 119 | - public function getAttributes($link, $result); |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * Get the DN of a result entry |
|
| 123 | - * @param resource $link LDAP link resource |
|
| 124 | - * @param resource $result LDAP result resource |
|
| 125 | - * @return string containing the DN, false on error |
|
| 126 | - */ |
|
| 127 | - public function getDN($link, $result); |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * Get all result entries |
|
| 131 | - * @param resource $link LDAP link resource |
|
| 132 | - * @param resource $result LDAP result resource |
|
| 133 | - * @return array containing the results, false on error |
|
| 134 | - */ |
|
| 135 | - public function getEntries($link, $result); |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * Return next result id |
|
| 139 | - * @param resource $link LDAP link resource |
|
| 140 | - * @param resource $result LDAP entry result resource |
|
| 141 | - * @return resource an LDAP search result resource |
|
| 142 | - * */ |
|
| 143 | - public function nextEntry($link, $result); |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * Read an entry |
|
| 147 | - * @param resource $link LDAP link resource |
|
| 148 | - * @param array $baseDN The DN of the entry to read from |
|
| 149 | - * @param string $filter An LDAP filter |
|
| 150 | - * @param array $attr array of the attributes to read |
|
| 151 | - * @return resource an LDAP search result resource |
|
| 152 | - */ |
|
| 153 | - public function read($link, $baseDN, $filter, $attr); |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * Search LDAP tree |
|
| 157 | - * @param resource $link LDAP link resource |
|
| 158 | - * @param string $baseDN The DN of the entry to read from |
|
| 159 | - * @param string $filter An LDAP filter |
|
| 160 | - * @param array $attr array of the attributes to read |
|
| 161 | - * @param int $attrsOnly optional, 1 if only attribute types shall be returned |
|
| 162 | - * @param int $limit optional, limits the result entries |
|
| 163 | - * @return resource|false an LDAP search result resource, false on error |
|
| 164 | - */ |
|
| 165 | - public function search($link, $baseDN, $filter, $attr, $attrsOnly = 0, $limit = 0); |
|
| 32 | + //LDAP functions in use |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * Bind to LDAP directory |
|
| 36 | + * @param resource $link LDAP link resource |
|
| 37 | + * @param string $dn an RDN to log in with |
|
| 38 | + * @param string $password the password |
|
| 39 | + * @return bool true on success, false otherwise |
|
| 40 | + * |
|
| 41 | + * with $dn and $password as null a anonymous bind is attempted. |
|
| 42 | + */ |
|
| 43 | + public function bind($link, $dn, $password); |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * connect to an LDAP server |
|
| 47 | + * @param string $host The host to connect to |
|
| 48 | + * @param string $port The port to connect to |
|
| 49 | + * @return mixed a link resource on success, otherwise false |
|
| 50 | + */ |
|
| 51 | + public function connect($host, $port); |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Send LDAP pagination control |
|
| 55 | + * @param resource $link LDAP link resource |
|
| 56 | + * @param int $pageSize number of results per page |
|
| 57 | + * @param bool $isCritical Indicates whether the pagination is critical of not. |
|
| 58 | + * @param string $cookie structure sent by LDAP server |
|
| 59 | + * @return bool true on success, false otherwise |
|
| 60 | + */ |
|
| 61 | + public function controlPagedResult($link, $pageSize, $isCritical, $cookie); |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Retrieve the LDAP pagination cookie |
|
| 65 | + * @param resource $link LDAP link resource |
|
| 66 | + * @param resource $result LDAP result resource |
|
| 67 | + * @param string $cookie structure sent by LDAP server |
|
| 68 | + * @return bool true on success, false otherwise |
|
| 69 | + * |
|
| 70 | + * Corresponds to ldap_control_paged_result_response |
|
| 71 | + */ |
|
| 72 | + public function controlPagedResultResponse($link, $result, &$cookie); |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * Count the number of entries in a search |
|
| 76 | + * @param resource $link LDAP link resource |
|
| 77 | + * @param resource $result LDAP result resource |
|
| 78 | + * @return int|false number of results on success, false otherwise |
|
| 79 | + */ |
|
| 80 | + public function countEntries($link, $result); |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * Return the LDAP error number of the last LDAP command |
|
| 84 | + * @param resource $link LDAP link resource |
|
| 85 | + * @return string error message as string |
|
| 86 | + */ |
|
| 87 | + public function errno($link); |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * Return the LDAP error message of the last LDAP command |
|
| 91 | + * @param resource $link LDAP link resource |
|
| 92 | + * @return int error code as integer |
|
| 93 | + */ |
|
| 94 | + public function error($link); |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * Splits DN into its component parts |
|
| 98 | + * @param string $dn |
|
| 99 | + * @param int @withAttrib |
|
| 100 | + * @return array|false |
|
| 101 | + * @link http://www.php.net/manual/en/function.ldap-explode-dn.php |
|
| 102 | + */ |
|
| 103 | + public function explodeDN($dn, $withAttrib); |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * Return first result id |
|
| 107 | + * @param resource $link LDAP link resource |
|
| 108 | + * @param resource $result LDAP result resource |
|
| 109 | + * @return Resource an LDAP search result resource |
|
| 110 | + * */ |
|
| 111 | + public function firstEntry($link, $result); |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * Get attributes from a search result entry |
|
| 115 | + * @param resource $link LDAP link resource |
|
| 116 | + * @param resource $result LDAP result resource |
|
| 117 | + * @return array containing the results, false on error |
|
| 118 | + * */ |
|
| 119 | + public function getAttributes($link, $result); |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * Get the DN of a result entry |
|
| 123 | + * @param resource $link LDAP link resource |
|
| 124 | + * @param resource $result LDAP result resource |
|
| 125 | + * @return string containing the DN, false on error |
|
| 126 | + */ |
|
| 127 | + public function getDN($link, $result); |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * Get all result entries |
|
| 131 | + * @param resource $link LDAP link resource |
|
| 132 | + * @param resource $result LDAP result resource |
|
| 133 | + * @return array containing the results, false on error |
|
| 134 | + */ |
|
| 135 | + public function getEntries($link, $result); |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * Return next result id |
|
| 139 | + * @param resource $link LDAP link resource |
|
| 140 | + * @param resource $result LDAP entry result resource |
|
| 141 | + * @return resource an LDAP search result resource |
|
| 142 | + * */ |
|
| 143 | + public function nextEntry($link, $result); |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * Read an entry |
|
| 147 | + * @param resource $link LDAP link resource |
|
| 148 | + * @param array $baseDN The DN of the entry to read from |
|
| 149 | + * @param string $filter An LDAP filter |
|
| 150 | + * @param array $attr array of the attributes to read |
|
| 151 | + * @return resource an LDAP search result resource |
|
| 152 | + */ |
|
| 153 | + public function read($link, $baseDN, $filter, $attr); |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * Search LDAP tree |
|
| 157 | + * @param resource $link LDAP link resource |
|
| 158 | + * @param string $baseDN The DN of the entry to read from |
|
| 159 | + * @param string $filter An LDAP filter |
|
| 160 | + * @param array $attr array of the attributes to read |
|
| 161 | + * @param int $attrsOnly optional, 1 if only attribute types shall be returned |
|
| 162 | + * @param int $limit optional, limits the result entries |
|
| 163 | + * @return resource|false an LDAP search result resource, false on error |
|
| 164 | + */ |
|
| 165 | + public function search($link, $baseDN, $filter, $attr, $attrsOnly = 0, $limit = 0); |
|
| 166 | 166 | |
| 167 | - /** |
|
| 168 | - * Replace the value of a userPassword by $password |
|
| 169 | - * @param resource $link LDAP link resource |
|
| 170 | - * @param string $userDN the DN of the user whose password is to be replaced |
|
| 171 | - * @param string $password the new value for the userPassword |
|
| 172 | - * @return bool true on success, false otherwise |
|
| 173 | - */ |
|
| 174 | - public function modReplace($link, $userDN, $password); |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * Sets the value of the specified option to be $value |
|
| 178 | - * @param resource $link LDAP link resource |
|
| 179 | - * @param string $option a defined LDAP Server option |
|
| 180 | - * @param int $value the new value for the option |
|
| 181 | - * @return bool true on success, false otherwise |
|
| 182 | - */ |
|
| 183 | - public function setOption($link, $option, $value); |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * establish Start TLS |
|
| 187 | - * @param resource $link LDAP link resource |
|
| 188 | - * @return bool true on success, false otherwise |
|
| 189 | - */ |
|
| 190 | - public function startTls($link); |
|
| 191 | - |
|
| 192 | - /** |
|
| 193 | - * Unbind from LDAP directory |
|
| 194 | - * @param resource $link LDAP link resource |
|
| 195 | - * @return bool true on success, false otherwise |
|
| 196 | - */ |
|
| 197 | - public function unbind($link); |
|
| 198 | - |
|
| 199 | - //additional required methods in ownCloud |
|
| 200 | - |
|
| 201 | - /** |
|
| 202 | - * Checks whether the server supports LDAP |
|
| 203 | - * @return bool true if it the case, false otherwise |
|
| 204 | - * */ |
|
| 205 | - public function areLDAPFunctionsAvailable(); |
|
| 206 | - |
|
| 207 | - /** |
|
| 208 | - * Checks whether PHP supports LDAP Paged Results |
|
| 209 | - * @return bool true if it the case, false otherwise |
|
| 210 | - * */ |
|
| 211 | - public function hasPagedResultSupport(); |
|
| 212 | - |
|
| 213 | - /** |
|
| 214 | - * Checks whether the submitted parameter is a resource |
|
| 215 | - * @param resource $resource the resource variable to check |
|
| 216 | - * @return bool true if it is a resource, false otherwise |
|
| 217 | - */ |
|
| 218 | - public function isResource($resource); |
|
| 167 | + /** |
|
| 168 | + * Replace the value of a userPassword by $password |
|
| 169 | + * @param resource $link LDAP link resource |
|
| 170 | + * @param string $userDN the DN of the user whose password is to be replaced |
|
| 171 | + * @param string $password the new value for the userPassword |
|
| 172 | + * @return bool true on success, false otherwise |
|
| 173 | + */ |
|
| 174 | + public function modReplace($link, $userDN, $password); |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * Sets the value of the specified option to be $value |
|
| 178 | + * @param resource $link LDAP link resource |
|
| 179 | + * @param string $option a defined LDAP Server option |
|
| 180 | + * @param int $value the new value for the option |
|
| 181 | + * @return bool true on success, false otherwise |
|
| 182 | + */ |
|
| 183 | + public function setOption($link, $option, $value); |
|
| 184 | + |
|
| 185 | + /** |
|
| 186 | + * establish Start TLS |
|
| 187 | + * @param resource $link LDAP link resource |
|
| 188 | + * @return bool true on success, false otherwise |
|
| 189 | + */ |
|
| 190 | + public function startTls($link); |
|
| 191 | + |
|
| 192 | + /** |
|
| 193 | + * Unbind from LDAP directory |
|
| 194 | + * @param resource $link LDAP link resource |
|
| 195 | + * @return bool true on success, false otherwise |
|
| 196 | + */ |
|
| 197 | + public function unbind($link); |
|
| 198 | + |
|
| 199 | + //additional required methods in ownCloud |
|
| 200 | + |
|
| 201 | + /** |
|
| 202 | + * Checks whether the server supports LDAP |
|
| 203 | + * @return bool true if it the case, false otherwise |
|
| 204 | + * */ |
|
| 205 | + public function areLDAPFunctionsAvailable(); |
|
| 206 | + |
|
| 207 | + /** |
|
| 208 | + * Checks whether PHP supports LDAP Paged Results |
|
| 209 | + * @return bool true if it the case, false otherwise |
|
| 210 | + * */ |
|
| 211 | + public function hasPagedResultSupport(); |
|
| 212 | + |
|
| 213 | + /** |
|
| 214 | + * Checks whether the submitted parameter is a resource |
|
| 215 | + * @param resource $resource the resource variable to check |
|
| 216 | + * @return bool true if it is a resource, false otherwise |
|
| 217 | + */ |
|
| 218 | + public function isResource($resource); |
|
| 219 | 219 | |
| 220 | 220 | } |
@@ -23,26 +23,26 @@ |
||
| 23 | 23 | |
| 24 | 24 | /** @var $this \OCP\Route\IRouter */ |
| 25 | 25 | $this->create('user_ldap_ajax_clearMappings', 'ajax/clearMappings.php') |
| 26 | - ->actionInclude('user_ldap/ajax/clearMappings.php'); |
|
| 26 | + ->actionInclude('user_ldap/ajax/clearMappings.php'); |
|
| 27 | 27 | $this->create('user_ldap_ajax_deleteConfiguration', 'ajax/deleteConfiguration.php') |
| 28 | - ->actionInclude('user_ldap/ajax/deleteConfiguration.php'); |
|
| 28 | + ->actionInclude('user_ldap/ajax/deleteConfiguration.php'); |
|
| 29 | 29 | $this->create('user_ldap_ajax_getConfiguration', 'ajax/getConfiguration.php') |
| 30 | - ->actionInclude('user_ldap/ajax/getConfiguration.php'); |
|
| 30 | + ->actionInclude('user_ldap/ajax/getConfiguration.php'); |
|
| 31 | 31 | $this->create('user_ldap_ajax_getNewServerConfigPrefix', 'ajax/getNewServerConfigPrefix.php') |
| 32 | - ->actionInclude('user_ldap/ajax/getNewServerConfigPrefix.php'); |
|
| 32 | + ->actionInclude('user_ldap/ajax/getNewServerConfigPrefix.php'); |
|
| 33 | 33 | $this->create('user_ldap_ajax_setConfiguration', 'ajax/setConfiguration.php') |
| 34 | - ->actionInclude('user_ldap/ajax/setConfiguration.php'); |
|
| 34 | + ->actionInclude('user_ldap/ajax/setConfiguration.php'); |
|
| 35 | 35 | $this->create('user_ldap_ajax_testConfiguration', 'ajax/testConfiguration.php') |
| 36 | - ->actionInclude('user_ldap/ajax/testConfiguration.php'); |
|
| 36 | + ->actionInclude('user_ldap/ajax/testConfiguration.php'); |
|
| 37 | 37 | $this->create('user_ldap_ajax_wizard', 'ajax/wizard.php') |
| 38 | - ->actionInclude('user_ldap/ajax/wizard.php'); |
|
| 38 | + ->actionInclude('user_ldap/ajax/wizard.php'); |
|
| 39 | 39 | |
| 40 | 40 | $application = new \OCP\AppFramework\App('user_ldap'); |
| 41 | 41 | $application->registerRoutes($this, [ |
| 42 | - 'ocs' => [ |
|
| 43 | - ['name' => 'ConfigAPI#create', 'url' => '/api/v1/config', 'verb' => 'POST'], |
|
| 44 | - ['name' => 'ConfigAPI#show', 'url' => '/api/v1/config/{configID}', 'verb' => 'GET'], |
|
| 45 | - ['name' => 'ConfigAPI#modify', 'url' => '/api/v1/config/{configID}', 'verb' => 'PUT'], |
|
| 46 | - ['name' => 'ConfigAPI#delete', 'url' => '/api/v1/config/{configID}', 'verb' => 'DELETE'], |
|
| 47 | - ] |
|
| 42 | + 'ocs' => [ |
|
| 43 | + ['name' => 'ConfigAPI#create', 'url' => '/api/v1/config', 'verb' => 'POST'], |
|
| 44 | + ['name' => 'ConfigAPI#show', 'url' => '/api/v1/config/{configID}', 'verb' => 'GET'], |
|
| 45 | + ['name' => 'ConfigAPI#modify', 'url' => '/api/v1/config/{configID}', 'verb' => 'PUT'], |
|
| 46 | + ['name' => 'ConfigAPI#delete', 'url' => '/api/v1/config/{configID}', 'verb' => 'DELETE'], |
|
| 47 | + ] |
|
| 48 | 48 | ]); |
@@ -41,7 +41,7 @@ |
||
| 41 | 41 | $application->registerRoutes($this, [ |
| 42 | 42 | 'ocs' => [ |
| 43 | 43 | ['name' => 'ConfigAPI#create', 'url' => '/api/v1/config', 'verb' => 'POST'], |
| 44 | - ['name' => 'ConfigAPI#show', 'url' => '/api/v1/config/{configID}', 'verb' => 'GET'], |
|
| 44 | + ['name' => 'ConfigAPI#show', 'url' => '/api/v1/config/{configID}', 'verb' => 'GET'], |
|
| 45 | 45 | ['name' => 'ConfigAPI#modify', 'url' => '/api/v1/config/{configID}', 'verb' => 'PUT'], |
| 46 | 46 | ['name' => 'ConfigAPI#delete', 'url' => '/api/v1/config/{configID}', 'verb' => 'DELETE'], |
| 47 | 47 | ] |