36
36
37
37
namespace OCA \ShareByMail ;
38
38
39
- use OC \CapabilitiesManager ;
40
39
use OC \HintException ;
41
40
use OC \Share20 \Exception \InvalidShare ;
42
41
use OC \Share20 \Share ;
45
44
use OCP \Activity \IManager ;
46
45
use OCP \DB \QueryBuilder \IQueryBuilder ;
47
46
use OCP \Defaults ;
47
+ use OCP \EventDispatcher \IEventDispatcher ;
48
48
use OCP \Files \Folder ;
49
49
use OCP \Files \IRootFolder ;
50
50
use OCP \Files \Node ;
55
55
use OCP \IUser ;
56
56
use OCP \IUserManager ;
57
57
use OCP \Mail \IMailer ;
58
+ use OCP \Security \Events \GenerateSecurePasswordEvent ;
58
59
use OCP \Security \IHasher ;
59
60
use OCP \Security \ISecureRandom ;
60
61
use OCP \Share \Exceptions \GenericShareException ;
@@ -105,8 +106,8 @@ class ShareByMailProvider implements IShareProvider {
105
106
/** @var IHasher */
106
107
private $ hasher ;
107
108
108
- /** @var CapabilitiesManager */
109
- private $ capabilitiesManager ;
109
+ /** @var IEventDispatcher */
110
+ private $ eventDispatcher ;
110
111
111
112
/**
112
113
* Return the identifier of this provider.
@@ -117,23 +118,6 @@ public function identifier() {
117
118
return 'ocMailShare ' ;
118
119
}
119
120
120
- /**
121
- * DefaultShareProvider constructor.
122
- *
123
- * @param IDBConnection $connection
124
- * @param ISecureRandom $secureRandom
125
- * @param IUserManager $userManager
126
- * @param IRootFolder $rootFolder
127
- * @param IL10N $l
128
- * @param ILogger $logger
129
- * @param IMailer $mailer
130
- * @param IURLGenerator $urlGenerator
131
- * @param IManager $activityManager
132
- * @param SettingsManager $settingsManager
133
- * @param Defaults $defaults
134
- * @param IHasher $hasher
135
- * @param CapabilitiesManager $capabilitiesManager
136
- */
137
121
public function __construct (
138
122
IDBConnection $ connection ,
139
123
ISecureRandom $ secureRandom ,
@@ -147,7 +131,7 @@ public function __construct(
147
131
SettingsManager $ settingsManager ,
148
132
Defaults $ defaults ,
149
133
IHasher $ hasher ,
150
- CapabilitiesManager $ capabilitiesManager
134
+ IEventDispatcher $ eventDispatcher
151
135
) {
152
136
$ this ->dbConnection = $ connection ;
153
137
$ this ->secureRandom = $ secureRandom ;
@@ -161,7 +145,7 @@ public function __construct(
161
145
$ this ->settingsManager = $ settingsManager ;
162
146
$ this ->defaults = $ defaults ;
163
147
$ this ->hasher = $ hasher ;
164
- $ this ->capabilitiesManager = $ capabilitiesManager ;
148
+ $ this ->eventDispatcher = $ eventDispatcher ;
165
149
}
166
150
167
151
/**
@@ -227,31 +211,15 @@ protected function autoGeneratePassword($share) {
227
211
);
228
212
}
229
213
230
- $ passwordPolicy = $ this ->getPasswordPolicy ();
231
- $ passwordCharset = ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS ;
232
- $ passwordLength = 8 ;
233
- if (!empty ($ passwordPolicy )) {
234
- $ passwordLength = (int )$ passwordPolicy ['minLength ' ] > 0 ? (int )$ passwordPolicy ['minLength ' ] : $ passwordLength ;
235
- $ passwordCharset .= $ passwordPolicy ['enforceSpecialCharacters ' ] ? ISecureRandom::CHAR_SYMBOLS : '' ;
236
- }
214
+ $ passwordEvent = new GenerateSecurePasswordEvent ();
215
+ $ this ->eventDispatcher ->dispatchTyped ($ passwordEvent );
237
216
238
- $ password = $ this ->secureRandom ->generate ($ passwordLength , $ passwordCharset );
239
-
240
- return $ password ;
241
- }
242
-
243
- /**
244
- * get password policy
245
- *
246
- * @return array
247
- */
248
- protected function getPasswordPolicy () {
249
- $ capabilities = $ this ->capabilitiesManager ->getCapabilities ();
250
- if (isset ($ capabilities ['password_policy ' ])) {
251
- return $ capabilities ['password_policy ' ];
217
+ $ password = $ passwordEvent ->getPassword ();
218
+ if ($ password === null ) {
219
+ $ password = $ this ->secureRandom ->generate (8 , ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS );
252
220
}
253
221
254
- return [] ;
222
+ return $ password ;
255
223
}
256
224
257
225
/**
0 commit comments