-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable changing passwords in user_ldap #1715
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
/** | ||
* @copyright Copyright (c) 2016 Roger Szabo <roger.szabo@web.de> | ||
* | ||
* @author Roger Szabo <roger.szabo@web.de> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
namespace OCA\User_LDAP\Exceptions; | ||
|
||
class ConstraintViolationException extends \Exception {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
* @author Lukas Reschke <lukas@statuscode.ch> | ||
* @author Morris Jobke <hey@morrisjobke.de> | ||
* @author Robin McCorkell <robin@mccorkell.me.uk> | ||
* @author Roger Szabo <roger.szabo@web.de> | ||
* | ||
* @license AGPL-3.0 | ||
* | ||
|
@@ -29,6 +30,7 @@ | |
namespace OCA\User_LDAP; | ||
|
||
use OC\ServerNotAvailableException; | ||
use OCA\User_LDAP\Exceptions\ConstraintViolationException; | ||
|
||
class LDAP implements ILDAPWrapper { | ||
protected $curFunc = ''; | ||
|
@@ -192,6 +194,16 @@ public function search($link, $baseDN, $filter, $attr, $attrsOnly = 0, $limit = | |
return $this->invokeLDAPMethod('search', $link, $baseDN, $filter, $attr, $attrsOnly, $limit); | ||
} | ||
|
||
/** | ||
* @param LDAP $link | ||
* @param string $userDN | ||
* @param string $password | ||
* @return bool | ||
*/ | ||
public function modReplace($link, $userDN, $password) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you also add this method to the ILDAPWrapper interface, please? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok~ |
||
return $this->invokeLDAPMethod('mod_replace', $link, $userDN, array('userPassword' => $password)); | ||
} | ||
|
||
/** | ||
* @param LDAP $link | ||
* @param string $option | ||
|
@@ -288,6 +300,9 @@ private function postFunctionCall() { | |
throw new \Exception('LDAP authentication method rejected', $errorCode); | ||
} else if ($errorCode === 1) { | ||
throw new \Exception('LDAP Operations error', $errorCode); | ||
} else if ($errorCode === 19) { | ||
ldap_get_option($this->curArgs[0], LDAP_OPT_ERROR_STRING, $extended_error); | ||
throw new ConstraintViolationException(!empty($extended_error)?$extended_error:$errorMsg, $errorCode); | ||
} else { | ||
\OCP\Util::writeLog('user_ldap', | ||
'LDAP error '.$errorMsg.' (' . | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ | |
|
||
namespace OCA\User_LDAP; | ||
|
||
use OC\User\Backend; | ||
use OC\User\NoUserException; | ||
use OCA\User_LDAP\Exceptions\NotOnLDAP; | ||
use OCA\User_LDAP\User\OfflineUser; | ||
|
@@ -174,6 +175,26 @@ public function checkPassword($uid, $password) { | |
return false; | ||
} | ||
|
||
/** | ||
* Set password | ||
* @param string $uid The username | ||
* @param string $password The new password | ||
* @return bool | ||
*/ | ||
public function setPassword($uid, $password) { | ||
$user = $this->access->userManager->get($uid); | ||
|
||
if(!$user instanceof User) { | ||
throw new \Exception('LDAP setPassword: Could not get user object for uid ' . $uid . | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not covered by tests. Will add. |
||
'. Maybe the LDAP entry has no set display name attribute?'); | ||
} | ||
if($user->getUsername() !== false) { | ||
return $this->access->setPassword($user->getDN(), $password); | ||
} | ||
|
||
return false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not covered by tests. Will add. |
||
} | ||
|
||
/** | ||
* Get a list of all users | ||
* | ||
|
@@ -449,11 +470,12 @@ public function getDisplayNames($search = '', $limit = null, $offset = null) { | |
* compared with OC_USER_BACKEND_CREATE_USER etc. | ||
*/ | ||
public function implementsActions($actions) { | ||
return (bool)((\OC\User\Backend::CHECK_PASSWORD | ||
| \OC\User\Backend::GET_HOME | ||
| \OC\User\Backend::GET_DISPLAYNAME | ||
| \OC\User\Backend::PROVIDE_AVATAR | ||
| \OC\User\Backend::COUNT_USERS) | ||
return (bool)((Backend::CHECK_PASSWORD | ||
| Backend::GET_HOME | ||
| Backend::GET_DISPLAYNAME | ||
| Backend::PROVIDE_AVATAR | ||
| Backend::COUNT_USERS | ||
| ((intval($this->access->connection->turnOnPasswordChange) === 1)?(Backend::SET_PASSWORD):0)) | ||
& $actions); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -262,6 +262,17 @@ public function getDisplayNames($search = '', $limit = null, $offset = null) { | |
public function deleteUser($uid) { | ||
return $this->handleRequest($uid, 'deleteUser', array($uid)); | ||
} | ||
|
||
/** | ||
* Set password | ||
* @param string $uid The username | ||
* @param string $password The new password | ||
* @return bool | ||
* | ||
*/ | ||
public function setPassword($uid, $password) { | ||
return $this->handleRequest($uid, 'setPassword', array($uid, $password)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not covered by tests. Will add. |
||
} | ||
|
||
/** | ||
* @return bool | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing tests. Will add myself so we get this done.