summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorBjoern Schiessle <bjoern@schiessle.org>2017-04-19 16:56:34 +0200
committerBjoern Schiessle <bjoern@schiessle.org>2017-04-20 16:33:26 +0200
commit972b4c04e2ea3bf96533c111853a57177231c638 (patch)
treee4b17437ede942eaff7fb0fc195d92e1e58cccb8 /apps
parent428d7cdb5e7be1d5ede6d5084459660b22c84b2c (diff)
downloadnextcloud-server-972b4c04e2ea3bf96533c111853a57177231c638.tar.gz
nextcloud-server-972b4c04e2ea3bf96533c111853a57177231c638.zip
respect password policy for auto generated passwords
Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
Diffstat (limited to 'apps')
-rw-r--r--apps/sharebymail/lib/ShareByMailProvider.php35
-rw-r--r--apps/sharebymail/tests/ShareByMailProviderTest.php11
2 files changed, 41 insertions, 5 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
);
}