setIdentifier('password::global') ->setVisibility(BackendService::VISIBILITY_DEFAULT) ->setScheme(self::SCHEME_PASSWORD) ->setText($l->t('Global credentials')); } public function getAuth($uid) { $auth = $this->credentialsManager->retrieve($uid, self::CREDENTIALS_IDENTIFIER); if (!is_array($auth)) { return [ 'user' => '', 'password' => '' ]; } else { $auth['password'] = self::PWD_PLACEHOLDER; return $auth; } } public function saveAuth($uid, $user, $password) { // Use old password if it has not changed. if ($password === self::PWD_PLACEHOLDER) { $auth = $this->credentialsManager->retrieve($uid, self::CREDENTIALS_IDENTIFIER); $password = $auth['password']; } $this->credentialsManager->store($uid, self::CREDENTIALS_IDENTIFIER, [ 'user' => $user, 'password' => $password ]); } /** * @return void */ public function manipulateStorageConfig(StorageConfig &$storage, ?IUser $user = null) { if ($storage->getType() === StorageConfig::MOUNT_TYPE_ADMIN) { $uid = ''; } elseif (is_null($user)) { throw new InsufficientDataForMeaningfulAnswerException('No credentials saved'); } else { $uid = $user->getUID(); } $credentials = $this->credentialsManager->retrieve($uid, self::CREDENTIALS_IDENTIFIER); if (is_array($credentials)) { $storage->setBackendOption('user', $credentials['user']); $storage->setBackendOption('password', $credentials['password']); } } }