/** * @dataProvider dataTestSetupUser * * @param bool $hasKeys * @param bool $expected */ public function testSetupUser($hasKeys, $expected) { $this->keyManagerMock->expects($this->once())->method('userHasKeys')->with('uid')->willReturn($hasKeys); if ($hasKeys) { $this->keyManagerMock->expects($this->never())->method('storeKeyPair'); } else { $this->cryptMock->expects($this->once())->method('createKeyPair')->willReturn('keyPair'); $this->keyManagerMock->expects($this->once())->method('storeKeyPair')->with('uid', 'password', 'keyPair')->willReturn(true); } $this->assertSame($expected, $this->instance->setupUser('uid', 'password')); }
/** * create key-pair for every user */ protected function createKeyPairs() { $this->output->writeln("\n"); $progress = new ProgressBar($this->output); $progress->setFormat(" %message% \n [%bar%]"); $progress->start(); foreach ($this->userManager->getBackends() as $backend) { $limit = 500; $offset = 0; do { $users = $backend->getUsers('', $limit, $offset); foreach ($users as $user) { if ($this->keyManager->userHasKeys($user) === false) { $progress->setMessage('Create key-pair for ' . $user); $progress->advance(); $this->setupUserFS($user); $password = $this->generateOneTimePassword($user); $this->userSetup->setupUser($user, $password); } else { // users which already have a key-pair will be stored with a // empty password and filtered out later $this->userPasswords[$user] = ''; } } $offset += $limit; } while (count($users) >= $limit); } $progress->setMessage('Key-pair created for all users'); $progress->finish(); }
/** * setup encryption backend upon user created * * @note This method should never be called for users using client side encryption * @param array $params */ public function postCreateUser($params) { if (App::isEnabled('encryption')) { $this->userSetup->setupUser($params['uid'], $params['password']); } }
/** * after password reset we create a new key pair for the user * * @param array $params */ public function postPasswordReset($params) { $password = $params['password']; $this->keyManager->deleteUserKeys($params['uid']); $this->userSetup->setupUser($params['uid'], $password); }