mirror of
https://github.com/bitwarden/browser
synced 2025-12-16 16:23:44 +00:00
[PM-25206] Inject service instead of passing as param (#16801)
* Inject service instead of passing as param * [PM-25206] Move locking logic to LockService (#16802) * Move locking logic to lock service * Fix tests * Fix CLI * Fix test * FIx safari build * Update call to lock service * Remove locked callback * Clean up lock service logic * Add tests * Fix cli build * Add extension lock service * Fix cli build * Fix build * Undo ac changes * Undo ac changes * Run prettier * Fix build * Remove duplicate call * [PM-25206] Remove VaultTimeoutService lock logic (#16804) * Move consumers off of vaulttimeoutsettingsservice lock * Fix build * Fix build * Fix build * Fix firefox build * Fix test * Fix ts strict errors * Fix ts strict error * Undo AC changes * Cleanup * Fix * Fix missing service
This commit is contained in:
@@ -1,16 +1,22 @@
|
||||
// FIXME: Update this file to be type safe and remove this and next line
|
||||
// @ts-strict-ignore
|
||||
import { VaultTimeoutService } from "@bitwarden/common/key-management/vault-timeout";
|
||||
import { firstValueFrom } from "rxjs";
|
||||
|
||||
import { LockService } from "@bitwarden/auth/common";
|
||||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||
import { getUserId } from "@bitwarden/common/auth/services/account.service";
|
||||
|
||||
import { Response } from "../../models/response";
|
||||
import { MessageResponse } from "../../models/response/message.response";
|
||||
|
||||
export class LockCommand {
|
||||
constructor(private vaultTimeoutService: VaultTimeoutService) {}
|
||||
constructor(
|
||||
private lockService: LockService,
|
||||
private accountService: AccountService,
|
||||
) {}
|
||||
|
||||
async run() {
|
||||
await this.vaultTimeoutService.lock();
|
||||
process.env.BW_SESSION = null;
|
||||
const activeUserId = await firstValueFrom(getUserId(this.accountService.activeAccount$));
|
||||
await this.lockService.lock(activeUserId);
|
||||
process.env.BW_SESSION = undefined;
|
||||
const res = new MessageResponse("Your vault is locked.", null);
|
||||
return Response.success(res);
|
||||
}
|
||||
|
||||
10
apps/cli/src/key-management/cli-process-reload.service.ts
Normal file
10
apps/cli/src/key-management/cli-process-reload.service.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { ProcessReloadServiceAbstraction } from "@bitwarden/common/key-management/abstractions/process-reload.service";
|
||||
|
||||
/**
|
||||
* CLI implementation of ProcessReloadServiceAbstraction.
|
||||
* This is NOOP since there is no effective way to process reload the CLI.
|
||||
*/
|
||||
export class CliProcessReloadService extends ProcessReloadServiceAbstraction {
|
||||
async startProcessReload(): Promise<void> {}
|
||||
async cancelProcessReload(): Promise<void> {}
|
||||
}
|
||||
@@ -160,7 +160,10 @@ export class OssServeConfigurator {
|
||||
this.serviceContainer.cipherService,
|
||||
this.serviceContainer.accountService,
|
||||
);
|
||||
this.lockCommand = new LockCommand(this.serviceContainer.vaultTimeoutService);
|
||||
this.lockCommand = new LockCommand(
|
||||
serviceContainer.lockService,
|
||||
serviceContainer.accountService,
|
||||
);
|
||||
this.unlockCommand = new UnlockCommand(
|
||||
this.serviceContainer.accountService,
|
||||
this.serviceContainer.masterPasswordService,
|
||||
|
||||
10
apps/cli/src/platform/services/cli-system.service.ts
Normal file
10
apps/cli/src/platform/services/cli-system.service.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { SystemService } from "@bitwarden/common/platform/abstractions/system.service";
|
||||
|
||||
/**
|
||||
* CLI implementation of SystemService.
|
||||
* The implementation is NOOP since these functions are meant for GUI clients.
|
||||
*/
|
||||
export class CliSystemService extends SystemService {
|
||||
async clearClipboard(clipboardValue: string, timeoutMs?: number): Promise<void> {}
|
||||
async clearPendingClipboard(): Promise<any> {}
|
||||
}
|
||||
@@ -250,7 +250,10 @@ export class Program extends BaseProgram {
|
||||
return;
|
||||
}
|
||||
|
||||
const command = new LockCommand(this.serviceContainer.vaultTimeoutService);
|
||||
const command = new LockCommand(
|
||||
this.serviceContainer.lockService,
|
||||
this.serviceContainer.accountService,
|
||||
);
|
||||
const response = await command.run();
|
||||
this.processResponse(response);
|
||||
});
|
||||
|
||||
@@ -20,6 +20,9 @@ import {
|
||||
SsoUrlService,
|
||||
AuthRequestApiServiceAbstraction,
|
||||
DefaultAuthRequestApiService,
|
||||
DefaultLockService,
|
||||
DefaultLogoutService,
|
||||
LockService,
|
||||
} from "@bitwarden/auth/common";
|
||||
import { EventCollectionService as EventCollectionServiceAbstraction } from "@bitwarden/common/abstractions/event/event-collection.service";
|
||||
import { EventUploadService as EventUploadServiceAbstraction } from "@bitwarden/common/abstractions/event/event-upload.service";
|
||||
@@ -199,9 +202,11 @@ import {
|
||||
} from "@bitwarden/vault-export-core";
|
||||
|
||||
import { CliBiometricsService } from "../key-management/cli-biometrics-service";
|
||||
import { CliProcessReloadService } from "../key-management/cli-process-reload.service";
|
||||
import { flagEnabled } from "../platform/flags";
|
||||
import { CliPlatformUtilsService } from "../platform/services/cli-platform-utils.service";
|
||||
import { CliSdkLoadService } from "../platform/services/cli-sdk-load.service";
|
||||
import { CliSystemService } from "../platform/services/cli-system.service";
|
||||
import { ConsoleLogService } from "../platform/services/console-log.service";
|
||||
import { I18nService } from "../platform/services/i18n.service";
|
||||
import { LowdbStorageService } from "../platform/services/lowdb-storage.service";
|
||||
@@ -318,6 +323,7 @@ export class ServiceContainer {
|
||||
securityStateService: SecurityStateService;
|
||||
masterPasswordUnlockService: MasterPasswordUnlockService;
|
||||
cipherArchiveService: CipherArchiveService;
|
||||
lockService: LockService;
|
||||
|
||||
constructor() {
|
||||
let p = null;
|
||||
@@ -778,9 +784,6 @@ export class ServiceContainer {
|
||||
|
||||
this.folderApiService = new FolderApiService(this.folderService, this.apiService);
|
||||
|
||||
const lockedCallback = async (userId: UserId) =>
|
||||
await this.keyService.clearStoredUserKey(userId);
|
||||
|
||||
this.userVerificationApiService = new UserVerificationApiService(this.apiService);
|
||||
|
||||
this.userVerificationService = new UserVerificationService(
|
||||
@@ -796,25 +799,35 @@ export class ServiceContainer {
|
||||
);
|
||||
|
||||
const biometricService = new CliBiometricsService();
|
||||
const logoutService = new DefaultLogoutService(this.messagingService);
|
||||
const processReloadService = new CliProcessReloadService();
|
||||
const systemService = new CliSystemService();
|
||||
this.lockService = new DefaultLockService(
|
||||
this.accountService,
|
||||
biometricService,
|
||||
this.vaultTimeoutSettingsService,
|
||||
logoutService,
|
||||
this.messagingService,
|
||||
this.searchService,
|
||||
this.folderService,
|
||||
this.masterPasswordService,
|
||||
this.stateEventRunnerService,
|
||||
this.cipherService,
|
||||
this.authService,
|
||||
systemService,
|
||||
processReloadService,
|
||||
this.logService,
|
||||
this.keyService,
|
||||
);
|
||||
|
||||
this.vaultTimeoutService = new DefaultVaultTimeoutService(
|
||||
this.accountService,
|
||||
this.masterPasswordService,
|
||||
this.cipherService,
|
||||
this.folderService,
|
||||
this.collectionService,
|
||||
this.platformUtilsService,
|
||||
this.messagingService,
|
||||
this.searchService,
|
||||
this.stateService,
|
||||
this.tokenService,
|
||||
this.authService,
|
||||
this.vaultTimeoutSettingsService,
|
||||
this.stateEventRunnerService,
|
||||
this.taskSchedulerService,
|
||||
this.logService,
|
||||
biometricService,
|
||||
lockedCallback,
|
||||
this.lockService,
|
||||
undefined,
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user