diff options
author | Lukas Reschke <lukas@statuscode.ch> | 2016-11-23 20:54:31 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-23 20:54:31 +0100 |
commit | 38658da12b3bd4df273e64f3a74e566ffbf9e1e9 (patch) | |
tree | 3152fe98d44acbf54d7fa40ad4e8ba9e4134414b /apps/user_ldap/lib/Access.php | |
parent | 56c926bc8b5b7e08dd0db32e70af132506735ca3 (diff) | |
parent | 4c5e7d270ae81c341195d47055aadabbb761b84c (diff) | |
download | nextcloud-server-38658da12b3bd4df273e64f3a74e566ffbf9e1e9.tar.gz nextcloud-server-38658da12b3bd4df273e64f3a74e566ffbf9e1e9.zip |
Merge pull request #2286 from nextcloud/ldap_password_pr-1
LDAP PR with tests
Diffstat (limited to 'apps/user_ldap/lib/Access.php')
-rw-r--r-- | apps/user_ldap/lib/Access.php | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/apps/user_ldap/lib/Access.php b/apps/user_ldap/lib/Access.php index e7facd80ae0..d88378c1888 100644 --- a/apps/user_ldap/lib/Access.php +++ b/apps/user_ldap/lib/Access.php @@ -40,6 +40,8 @@ namespace OCA\User_LDAP; +use OC\HintException; +use OCA\User_LDAP\Exceptions\ConstraintViolationException; use OCA\User_LDAP\User\IUserTools; use OCA\User_LDAP\User\Manager; use OCA\User_LDAP\User\OfflineUser; @@ -221,6 +223,33 @@ class Access extends LDAPUtility implements IUserTools { \OCP\Util::writeLog('user_ldap', 'Requested attribute '.$attr.' not found for '.$dn, \OCP\Util::DEBUG); return false; } + + /** + * Set password for an LDAP user identified by a DN + * + * @param string $userDN the user in question + * @param string $password the new password + * @return bool + * @throws HintException + * @throws \Exception + */ + public function setPassword($userDN, $password) { + if(intval($this->connection->turnOnPasswordChange) !== 1) { + throw new \Exception('LDAP password changes are disabled.'); + } + $cr = $this->connection->getConnectionResource(); + if(!$this->ldap->isResource($cr)) { + //LDAP not available + \OCP\Util::writeLog('user_ldap', 'LDAP resource not available.', \OCP\Util::DEBUG); + return false; + } + + try { + return $this->ldap->modReplace($cr, $userDN, $password); + } catch(ConstraintViolationException $e) { + throw new HintException('Password change rejected.', \OC::$server->getL10N('user_ldap')->t('Password change rejected. Hint: ').$e->getMessage(), $e->getCode()); + } + } /** * checks whether the given attributes value is probably a DN |