|
|
|
|
@ -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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|