diff options
author | Bjoern Schiessle <bjoern@schiessle.org> | 2016-06-28 11:13:15 +0200 |
---|---|---|
committer | Bjoern Schiessle <bjoern@schiessle.org> | 2016-06-28 11:43:23 +0200 |
commit | 27059107f869c6a5758569c1e24f34f8543b245e (patch) | |
tree | a4a2eb18b23f91ebc05fe618605995c06be8faf2 /lib | |
parent | 95f6dd909b6c676ac8d0a79cb42d32e5e202bfd8 (diff) | |
download | nextcloud-server-27059107f869c6a5758569c1e24f34f8543b245e.tar.gz nextcloud-server-27059107f869c6a5758569c1e24f34f8543b245e.zip |
add events to check passwords with the password policy app
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/server.php | 3 | ||||
-rw-r--r-- | lib/private/share20/manager.php | 23 | ||||
-rw-r--r-- | lib/private/user/database.php | 9 |
3 files changed, 22 insertions, 13 deletions
diff --git a/lib/private/server.php b/lib/private/server.php index 581a2b44cea..7d4b02fefee 100644 --- a/lib/private/server.php +++ b/lib/private/server.php @@ -618,7 +618,8 @@ class Server extends ServerContainer implements IServerContainer { $c->getL10N('core'), $factory, $c->getUserManager(), - $c->getRootFolder() + $c->getRootFolder(), + $c->getEventDispatcher() ); return $manager; diff --git a/lib/private/share20/manager.php b/lib/private/share20/manager.php index 35a019b2334..5d53d0ef839 100644 --- a/lib/private/share20/manager.php +++ b/lib/private/share20/manager.php @@ -24,6 +24,7 @@ namespace OC\Share20; use OC\Files\Mount\MoveableMount; +use OC\HintException; use OCP\Files\IRootFolder; use OCP\Files\NotFoundException; use OCP\IUserManager; @@ -42,6 +43,8 @@ use OCP\Files\Folder; use OCP\Share\Exceptions\ShareNotFound; use OCP\Share\Exceptions\GenericShareException; +use Symfony\Component\EventDispatcher\EventDispatcher; +use Symfony\Component\EventDispatcher\GenericEvent; /** * This class is the communication hub for all sharing related operations. @@ -82,6 +85,7 @@ class Manager implements IManager { * @param IProviderFactory $factory * @param IUserManager $userManager * @param IRootFolder $rootFolder + * @param EventDispatcher $eventDispatcher */ public function __construct( ILogger $logger, @@ -93,7 +97,8 @@ class Manager implements IManager { IL10N $l, IProviderFactory $factory, IUserManager $userManager, - IRootFolder $rootFolder + IRootFolder $rootFolder, + EventDispatcher $eventDispatcher ) { $this->logger = $logger; $this->config = $config; @@ -105,6 +110,7 @@ class Manager implements IManager { $this->factory = $factory; $this->userManager = $userManager; $this->rootFolder = $rootFolder; + $this->eventDispatcher = $eventDispatcher; } /** @@ -134,16 +140,11 @@ class Manager implements IManager { } // Let others verify the password - $accepted = true; - $message = ''; - \OCP\Util::emitHook('\OC\Share', 'verifyPassword', [ - 'password' => $password, - 'accepted' => &$accepted, - 'message' => &$message - ]); - - if (!$accepted) { - throw new \Exception($message); + try { + $event = new GenericEvent($password); + $this->eventDispatcher->dispatch('OCP\PasswordPolicy::validate', $event); + } catch (HintException $e) { + throw new \Exception($e->getHint()); } } diff --git a/lib/private/user/database.php b/lib/private/user/database.php index fd273055ae1..4622be1657d 100644 --- a/lib/private/user/database.php +++ b/lib/private/user/database.php @@ -49,6 +49,8 @@ */ use OC\Cache\CappedMemoryCache; +use Symfony\Component\EventDispatcher\EventDispatcher; +use Symfony\Component\EventDispatcher\GenericEvent; /** * Class for user management in a SQL Database (e.g. MySQL, SQLite) @@ -59,9 +61,12 @@ class OC_User_Database extends OC_User_Backend implements \OCP\IUserBackend { /** * OC_User_Database constructor. + * + * @param EventDispatcher $eventDispatcher */ - public function __construct() { + public function __construct(EventDispatcher $eventDispatcher = null) { $this->cache = new CappedMemoryCache(); + $this->eventDispatcher = $eventDispatcher ? $eventDispatcher : \OC::$server->getEventDispatcher(); } /** @@ -113,6 +118,8 @@ class OC_User_Database extends OC_User_Backend implements \OCP\IUserBackend { */ public function setPassword($uid, $password) { if ($this->userExists($uid)) { + $event = new GenericEvent($password); + $this->eventDispatcher->dispatch('OCP\PasswordPolicy::validate', $event); $query = OC_DB::prepare('UPDATE `*PREFIX*users` SET `password` = ? WHERE `uid` = ?'); $result = $query->execute(array(\OC::$server->getHasher()->hash($password), $uid)); |