aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2019-11-27 11:11:17 +0100
committerGitHub <noreply@github.com>2019-11-27 11:11:17 +0100
commit0532f8116da1ed92b973c8842c4d18f084255820 (patch)
treef259a529e238cb66cf3d89a25d2203a2065f5e7e /lib/private
parentd2f9deba51d6c3944344fb8e0b8731a049923dba (diff)
parent1a886b1472cad1fb04e8073d2749514e2d97a506 (diff)
downloadnextcloud-server-0532f8116da1ed92b973c8842c4d18f084255820.tar.gz
nextcloud-server-0532f8116da1ed92b973c8842c4d18f084255820.zip
Merge pull request #18019 from nextcloud/enhancement/password-policy-events
Add typed events for password_policy
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/Share20/Manager.php4
-rw-r--r--lib/private/User/Database.php15
2 files changed, 9 insertions, 10 deletions
diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php
index d9809fd128a..210dc7772c0 100644
--- a/lib/private/Share20/Manager.php
+++ b/lib/private/Share20/Manager.php
@@ -55,6 +55,7 @@ use OCP\IUser;
use OCP\IUserManager;
use OCP\L10N\IFactory;
use OCP\Mail\IMailer;
+use OCP\Security\Events\ValidatePasswordPolicyEvent;
use OCP\Security\IHasher;
use OCP\Security\ISecureRandom;
use OCP\Share;
@@ -191,8 +192,7 @@ class Manager implements IManager {
// Let others verify the password
try {
- $event = new GenericEvent($password);
- $this->eventDispatcher->dispatch('OCP\PasswordPolicy::validate', $event);
+ $this->eventDispatcher->dispatch(new ValidatePasswordPolicyEvent($password));
} catch (HintException $e) {
throw new \Exception($e->getHint());
}
diff --git a/lib/private/User/Database.php b/lib/private/User/Database.php
index 23dbe8c2334..a4c35deb2b8 100644
--- a/lib/private/User/Database.php
+++ b/lib/private/User/Database.php
@@ -58,7 +58,9 @@ declare(strict_types=1);
namespace OC\User;
use OC\Cache\CappedMemoryCache;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\IDBConnection;
+use OCP\Security\Events\ValidatePasswordPolicyEvent;
use OCP\User\Backend\ABackend;
use OCP\User\Backend\ICheckPasswordBackend;
use OCP\User\Backend\ICountUsersBackend;
@@ -68,7 +70,6 @@ use OCP\User\Backend\IGetHomeBackend;
use OCP\User\Backend\IGetRealUIDBackend;
use OCP\User\Backend\ISetDisplayNameBackend;
use OCP\User\Backend\ISetPasswordBackend;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
/**
@@ -86,7 +87,7 @@ class Database extends ABackend
/** @var CappedMemoryCache */
private $cache;
- /** @var EventDispatcherInterface */
+ /** @var IEventDispatcher */
private $eventDispatcher;
/** @var IDBConnection */
@@ -98,13 +99,13 @@ class Database extends ABackend
/**
* \OC\User\Database constructor.
*
- * @param EventDispatcherInterface $eventDispatcher
+ * @param IEventDispatcher $eventDispatcher
* @param string $table
*/
public function __construct($eventDispatcher = null, $table = 'users') {
$this->cache = new CappedMemoryCache();
$this->table = $table;
- $this->eventDispatcher = $eventDispatcher ? $eventDispatcher : \OC::$server->getEventDispatcher();
+ $this->eventDispatcher = $eventDispatcher ? $eventDispatcher : \OC::$server->query(IEventDispatcher::class);
}
/**
@@ -130,8 +131,7 @@ class Database extends ABackend
$this->fixDI();
if (!$this->userExists($uid)) {
- $event = new GenericEvent($password);
- $this->eventDispatcher->dispatch('OCP\PasswordPolicy::validate', $event);
+ $this->eventDispatcher->dispatchTyped(new ValidatePasswordPolicyEvent($password));
$qb = $this->dbConn->getQueryBuilder();
$qb->insert($this->table)
@@ -199,8 +199,7 @@ class Database extends ABackend
$this->fixDI();
if ($this->userExists($uid)) {
- $event = new GenericEvent($password);
- $this->eventDispatcher->dispatch('OCP\PasswordPolicy::validate', $event);
+ $this->eventDispatcher->dispatchTyped(new ValidatePasswordPolicyEvent($password));
$hasher = \OC::$server->getHasher();
$hashedPassword = $hasher->hash($password);
e AGPL-3.0 * * This code is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License, version 3, * as published by the Free Software Foundation. * * 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, version 3, * along with this program. If not, see <http://www.gnu.org/licenses/> * */ namespace OC\Repair; use Doctrine\DBAL\Exception\DriverException; use Doctrine\DBAL\Platforms\MySqlPlatform; use OCP\IConfig; use OCP\IDBConnection; use OCP\ILogger; use OCP\Migration\IOutput; use OCP\Migration\IRepairStep; class Collation implements IRepairStep { /** @var IConfig */ protected $config; /** @var ILogger */ protected $logger; /** @var IDBConnection */ protected $connection; /** @var bool */ protected $ignoreFailures; /** * @param IConfig $config * @param ILogger $logger * @param IDBConnection $connection * @param bool $ignoreFailures */ public function __construct(IConfig $config, ILogger $logger, IDBConnection $connection, $ignoreFailures) { $this->connection = $connection; $this->config = $config; $this->logger = $logger; $this->ignoreFailures = $ignoreFailures; } public function getName() { return 'Repair MySQL collation'; } /** * Fix mime types */ public function run(IOutput $output) { if (!$this->connection->getDatabasePlatform() instanceof MySqlPlatform) { $output->info('Not a mysql database -> nothing to do'); return; } $characterSet = $this->config->getSystemValue('mysql.utf8mb4', false) ? 'utf8mb4' : 'utf8'; $tables = $this->getAllNonUTF8BinTables($this->connection); foreach ($tables as $table) { $output->info("Change row format for $table ..."); $query = $this->connection->prepare('ALTER TABLE `' . $table . '` ROW_FORMAT = DYNAMIC;'); try { $query->execute(); } catch (DriverException $e) { // Just log this $this->logger->logException($e); if (!$this->ignoreFailures) { throw $e; } } $output->info("Change collation for $table ..."); if ($characterSet === 'utf8mb4') { // need to set row compression first $query = $this->connection->prepare('ALTER TABLE `' . $table . '` ROW_FORMAT=COMPRESSED;'); $query->execute(); } $query = $this->connection->prepare('ALTER TABLE `' . $table . '` CONVERT TO CHARACTER SET ' . $characterSet . ' COLLATE ' . $characterSet . '_bin;'); try { $query->execute(); } catch (DriverException $e) { // Just log this $this->logger->logException($e); if (!$this->ignoreFailures) { throw $e; } } } if (empty($tables)) { $output->info('All tables already have the correct collation -> nothing to do'); } } /** * @param IDBConnection $connection * @return string[] */ protected function getAllNonUTF8BinTables(IDBConnection $connection) { $dbName = $this->config->getSystemValue("dbname"); $characterSet = $this->config->getSystemValue('mysql.utf8mb4', false) ? 'utf8mb4' : 'utf8'; // fetch tables by columns $statement = $connection->executeQuery( "SELECT DISTINCT(TABLE_NAME) AS `table`" . " FROM INFORMATION_SCHEMA . COLUMNS" . " WHERE TABLE_SCHEMA = ?" . " AND (COLLATION_NAME <> '" . $characterSet . "_bin' OR CHARACTER_SET_NAME <> '" . $characterSet . "')" . " AND TABLE_NAME LIKE '*PREFIX*%'", [$dbName] ); $rows = $statement->fetchAll(); $result = []; foreach ($rows as $row) { $result[$row['table']] = true; } // fetch tables by collation $statement = $connection->executeQuery( "SELECT DISTINCT(TABLE_NAME) AS `table`" . " FROM INFORMATION_SCHEMA . TABLES" . " WHERE TABLE_SCHEMA = ?" . " AND TABLE_COLLATION <> '" . $characterSet . "_bin'" . " AND TABLE_NAME LIKE '*PREFIX*%'", [$dbName] ); $rows = $statement->fetchAll(); foreach ($rows as $row) { $result[$row['table']] = true; } return array_keys($result); } }