summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/sharebymail/lib/ShareByMailProvider.php35
-rw-r--r--apps/sharebymail/tests/ShareByMailProviderTest.php11
-rw-r--r--lib/private/Share20/ProviderFactory.php4
3 files changed, 44 insertions, 6 deletions
diff --git a/apps/sharebymail/lib/ShareByMailProvider.php b/apps/sharebymail/lib/ShareByMailProvider.php
index 5307a8cb223..f31a774b1d1 100644
--- a/apps/sharebymail/lib/ShareByMailProvider.php
+++ b/apps/sharebymail/lib/ShareByMailProvider.php
@@ -21,6 +21,7 @@
namespace OCA\ShareByMail;
+use OC\CapabilitiesManager;
use OC\HintException;
use OC\Share20\Exception\InvalidShare;
use OCA\ShareByMail\Settings\SettingsManager;
@@ -43,7 +44,6 @@ use OC\Share20\Share;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IShare;
use OCP\Share\IShareProvider;
-use OCP\Template;
/**
* Class ShareByMail
@@ -88,6 +88,9 @@ class ShareByMailProvider implements IShareProvider {
/** @var IHasher */
private $hasher;
+ /** @var CapabilitiesManager */
+ private $capabilitiesManager;
+
/**
* Return the identifier of this provider.
*
@@ -112,6 +115,7 @@ class ShareByMailProvider implements IShareProvider {
* @param SettingsManager $settingsManager
* @param Defaults $defaults
* @param IHasher $hasher
+ * @param CapabilitiesManager $capabilitiesManager
*/
public function __construct(
IDBConnection $connection,
@@ -125,7 +129,8 @@ class ShareByMailProvider implements IShareProvider {
IManager $activityManager,
SettingsManager $settingsManager,
Defaults $defaults,
- IHasher $hasher
+ IHasher $hasher,
+ CapabilitiesManager $capabilitiesManager
) {
$this->dbConnection = $connection;
$this->secureRandom = $secureRandom;
@@ -139,6 +144,7 @@ class ShareByMailProvider implements IShareProvider {
$this->settingsManager = $settingsManager;
$this->defaults = $defaults;
$this->hasher = $hasher;
+ $this->capabilitiesManager = $capabilitiesManager;
}
/**
@@ -202,13 +208,36 @@ class ShareByMailProvider implements IShareProvider {
);
}
- $password = $this->generateToken(8);
+ $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 : '';
+ }
+
+ $password = $this->secureRandom->generate($passwordLength, $passwordCharset);
+
$share->setPassword($this->hasher->hash($password));
return $password;
}
/**
+ * get password policy
+ *
+ * @return array
+ */
+ protected function getPasswordPolicy() {
+ $capabilities = $this->capabilitiesManager->getCapabilities();
+ if (isset($capabilities['password_policy'])) {
+ return $capabilities['password_policy'];
+ }
+
+ return [];
+ }
+
+ /**
* create activity if a file/folder was shared by mail
*
* @param IShare $share
diff --git a/apps/sharebymail/tests/ShareByMailProviderTest.php b/apps/sharebymail/tests/ShareByMailProviderTest.php
index 4061ef4eb50..a3e5da82bf2 100644
--- a/apps/sharebymail/tests/ShareByMailProviderTest.php
+++ b/apps/sharebymail/tests/ShareByMailProviderTest.php
@@ -23,6 +23,7 @@
namespace OCA\ShareByMail\Tests;
+use OC\CapabilitiesManager;
use OC\Mail\Message;
use OCA\ShareByMail\Settings\SettingsManager;
use OCA\ShareByMail\ShareByMailProvider;
@@ -93,6 +94,9 @@ class ShareByMailProviderTest extends TestCase {
/** @var IHasher | \PHPUnit_Framework_MockObject_MockObject */
private $hasher;
+ /** @var CapabilitiesManager | \PHPUnit_Framework_MockObject_MockObject */
+ private $capabilitiesManager;
+
public function setUp() {
parent::setUp();
@@ -115,6 +119,7 @@ class ShareByMailProviderTest extends TestCase {
$this->settingsManager = $this->getMockBuilder(SettingsManager::class)->disableOriginalConstructor()->getMock();
$this->defaults = $this->createMock(Defaults::class);
$this->hasher = $this->getMockBuilder(IHasher::class)->getMock();
+ $this->capabilitiesManager = $this->getMockBuilder(CapabilitiesManager::class)->disableOriginalConstructor()->getMock();
$this->userManager->expects($this->any())->method('userExists')->willReturn(true);
}
@@ -141,7 +146,8 @@ class ShareByMailProviderTest extends TestCase {
$this->activityManager,
$this->settingsManager,
$this->defaults,
- $this->hasher
+ $this->hasher,
+ $this->capabilitiesManager
]
);
@@ -162,7 +168,8 @@ class ShareByMailProviderTest extends TestCase {
$this->activityManager,
$this->settingsManager,
$this->defaults,
- $this->hasher
+ $this->hasher,
+ $this->capabilitiesManager
);
}
diff --git a/lib/private/Share20/ProviderFactory.php b/lib/private/Share20/ProviderFactory.php
index c9c0265c789..c79f58f6ba6 100644
--- a/lib/private/Share20/ProviderFactory.php
+++ b/lib/private/Share20/ProviderFactory.php
@@ -23,6 +23,7 @@
*/
namespace OC\Share20;
+use OC\CapabilitiesManager;
use OCA\FederatedFileSharing\AddressHandler;
use OCA\FederatedFileSharing\DiscoveryManager;
use OCA\FederatedFileSharing\FederatedShareProvider;
@@ -161,7 +162,8 @@ class ProviderFactory implements IProviderFactory {
$this->serverContainer->getActivityManager(),
$settingsManager,
$this->serverContainer->query(Defaults::class),
- $this->serverContainer->getHasher()
+ $this->serverContainer->getHasher(),
+ $this->serverContainer->query(CapabilitiesManager::class)
);
}