|
28 | 28 | use OC\DB\ConnectionFactory; |
29 | 29 | use OCA\UserSQL\Cache; |
30 | 30 | use OCA\UserSQL\Constant\App; |
| 31 | +use OCA\UserSQL\Constant\Opt; |
| 32 | +use OCA\UserSQL\Crypto\IPasswordAlgorithm; |
31 | 33 | use OCA\UserSQL\Platform\PlatformFactory; |
32 | 34 | use OCA\UserSQL\Properties; |
33 | 35 | use OCP\AppFramework\Controller; |
34 | 36 | use OCP\IL10N; |
35 | 37 | use OCP\ILogger; |
36 | 38 | use OCP\IRequest; |
| 39 | +use ReflectionClass; |
| 40 | +use ReflectionException; |
37 | 41 |
|
38 | 42 | /** |
39 | 43 | * The settings controller. |
@@ -72,7 +76,8 @@ class SettingsController extends Controller |
72 | 76 | public function __construct( |
73 | 77 | $appName, IRequest $request, ILogger $logger, IL10N $localization, |
74 | 78 | Properties $properties, Cache $cache |
75 | | - ) { |
| 79 | + ) |
| 80 | + { |
76 | 81 | parent::__construct($appName, $request); |
77 | 82 | $this->appName = $appName; |
78 | 83 | $this->logger = $logger; |
@@ -369,34 +374,42 @@ public function groupTableAutocomplete() |
369 | 374 | } |
370 | 375 |
|
371 | 376 | /** |
372 | | - * TODO |
| 377 | + * Get parameters for a password algorithm. |
373 | 378 | * |
374 | | - * @return array TODO |
| 379 | + * @return array Password algorithm parameters. |
| 380 | + * @throws ReflectionException Whenever Opt class cannot be initiated. |
375 | 381 | */ |
376 | 382 | public function cryptoParams() |
377 | 383 | { |
378 | | - sleep(3); |
379 | | - // TODO implement |
380 | | - // TODO add current values |
381 | | - return [ |
382 | | - "status" => "success", |
383 | | - "data" => [ |
384 | | - [ |
385 | | - "name" => "Memory cost (KiB)", |
386 | | - "value" => PASSWORD_ARGON2_DEFAULT_MEMORY_COST, |
387 | | - "min" => 1, "max" => 1048576 |
388 | | - ], |
389 | | - [ |
390 | | - "name" => "Time cost", |
391 | | - "value" => PASSWORD_ARGON2_DEFAULT_TIME_COST, "min" => 1, |
392 | | - "max" => 1024 |
393 | | - ], |
394 | | - [ |
395 | | - "name" => "Threads", |
396 | | - "value" => PASSWORD_ARGON2_DEFAULT_THREADS, "min" => 1, |
397 | | - "max" => 1024 |
398 | | - ] |
399 | | - ] |
400 | | - ]; |
| 384 | + $this->logger->debug( |
| 385 | + "Entering cryptoParams()", ["app" => $this->appName] |
| 386 | + ); |
| 387 | + |
| 388 | + /** |
| 389 | + * @var $passwordAlgorithm IPasswordAlgorithm |
| 390 | + */ |
| 391 | + $cryptoClass = $this->request->getParam("cryptoClass"); |
| 392 | + $passwordAlgorithm = new $cryptoClass($this->localization); |
| 393 | + $configuration = $passwordAlgorithm->configuration(); |
| 394 | + |
| 395 | + if ($cryptoClass === $this->properties[Opt::CRYPTO_CLASS]) { |
| 396 | + foreach ($configuration as $key => $value) { |
| 397 | + $opt = new ReflectionClass("OCA\UserSQL\Constant\Opt"); |
| 398 | + $param = $this->properties[$opt->getConstant( |
| 399 | + "CRYPTO_PARAM_" . $key |
| 400 | + )]; |
| 401 | + |
| 402 | + if (!empty($param)) { |
| 403 | + $value->value = $param; |
| 404 | + } |
| 405 | + } |
| 406 | + } |
| 407 | + |
| 408 | + $this->logger->debug( |
| 409 | + "Returning cryptoParams(): count(" . count($configuration) . ")", |
| 410 | + ["app" => $this->appName] |
| 411 | + ); |
| 412 | + |
| 413 | + return ["status" => "success", "data" => (array)$configuration]; |
401 | 414 | } |
402 | 415 | } |
0 commit comments