diff options
author | Daniel Kesselberg <mail@danielkesselberg.de> | 2020-08-09 18:13:14 +0200 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2020-08-11 21:58:51 +0200 |
commit | 4dd507675c8583a28b948872f6e2e9e3df043fb7 (patch) | |
tree | f7ea3ec15d7530b4a1b80d19e2a34f7d1f0bd667 /apps/sharebymail/lib/ShareByMailProvider.php | |
parent | 50fdd45e9bbeaff811888ea5ddc984a5966bd6f6 (diff) | |
download | nextcloud-server-4dd507675c8583a28b948872f6e2e9e3df043fb7.tar.gz nextcloud-server-4dd507675c8583a28b948872f6e2e9e3df043fb7.zip |
Generate password by password_policy app
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
Diffstat (limited to 'apps/sharebymail/lib/ShareByMailProvider.php')
-rw-r--r-- | apps/sharebymail/lib/ShareByMailProvider.php | 56 |
1 files changed, 12 insertions, 44 deletions
diff --git a/apps/sharebymail/lib/ShareByMailProvider.php b/apps/sharebymail/lib/ShareByMailProvider.php index 0f1afd43ba4..1365899271e 100644 --- a/apps/sharebymail/lib/ShareByMailProvider.php +++ b/apps/sharebymail/lib/ShareByMailProvider.php @@ -36,7 +36,6 @@ namespace OCA\ShareByMail; -use OC\CapabilitiesManager; use OC\HintException; use OC\Share20\Exception\InvalidShare; use OC\Share20\Share; @@ -45,6 +44,7 @@ use OCA\ShareByMail\Settings\SettingsManager; use OCP\Activity\IManager; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\Defaults; +use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Folder; use OCP\Files\IRootFolder; use OCP\Files\Node; @@ -55,6 +55,7 @@ use OCP\IURLGenerator; use OCP\IUser; use OCP\IUserManager; use OCP\Mail\IMailer; +use OCP\Security\Events\GenerateSecurePasswordEvent; use OCP\Security\IHasher; use OCP\Security\ISecureRandom; use OCP\Share\Exceptions\GenericShareException; @@ -105,8 +106,8 @@ class ShareByMailProvider implements IShareProvider { /** @var IHasher */ private $hasher; - /** @var CapabilitiesManager */ - private $capabilitiesManager; + /** @var IEventDispatcher */ + private $eventDispatcher; /** * Return the identifier of this provider. @@ -117,23 +118,6 @@ class ShareByMailProvider implements IShareProvider { return 'ocMailShare'; } - /** - * DefaultShareProvider constructor. - * - * @param IDBConnection $connection - * @param ISecureRandom $secureRandom - * @param IUserManager $userManager - * @param IRootFolder $rootFolder - * @param IL10N $l - * @param ILogger $logger - * @param IMailer $mailer - * @param IURLGenerator $urlGenerator - * @param IManager $activityManager - * @param SettingsManager $settingsManager - * @param Defaults $defaults - * @param IHasher $hasher - * @param CapabilitiesManager $capabilitiesManager - */ public function __construct( IDBConnection $connection, ISecureRandom $secureRandom, @@ -147,7 +131,7 @@ class ShareByMailProvider implements IShareProvider { SettingsManager $settingsManager, Defaults $defaults, IHasher $hasher, - CapabilitiesManager $capabilitiesManager + IEventDispatcher $eventDispatcher ) { $this->dbConnection = $connection; $this->secureRandom = $secureRandom; @@ -161,7 +145,7 @@ class ShareByMailProvider implements IShareProvider { $this->settingsManager = $settingsManager; $this->defaults = $defaults; $this->hasher = $hasher; - $this->capabilitiesManager = $capabilitiesManager; + $this->eventDispatcher = $eventDispatcher; } /** @@ -227,31 +211,15 @@ class ShareByMailProvider implements IShareProvider { ); } - $passwordPolicy = $this->getPasswordPolicy(); - $passwordCharset = ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS; - $passwordLength = 8; - if (!empty($passwordPolicy)) { - $passwordLength = (int)$passwordPolicy['minLength'] > 0 ? (int)$passwordPolicy['minLength'] : $passwordLength; - $passwordCharset .= $passwordPolicy['enforceSpecialCharacters'] ? ISecureRandom::CHAR_SYMBOLS : ''; - } + $passwordEvent = new GenerateSecurePasswordEvent(); + $this->eventDispatcher->dispatchTyped($passwordEvent); - $password = $this->secureRandom->generate($passwordLength, $passwordCharset); - - return $password; - } - - /** - * get password policy - * - * @return array - */ - protected function getPasswordPolicy() { - $capabilities = $this->capabilitiesManager->getCapabilities(); - if (isset($capabilities['password_policy'])) { - return $capabilities['password_policy']; + $password = $passwordEvent->getPassword(); + if ($password === null) { + $password = $this->secureRandom->generate(8, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS); } - return []; + return $password; } /** |