mirror of
https://github.com/bitwarden/jslib
synced 2025-12-19 09:43:28 +00:00
[chore] Update recent KeyConnector changes to use stateService
This commit is contained in:
@@ -8,11 +8,8 @@ import { ApiService } from 'jslib-common/abstractions/api.service';
|
||||
import { I18nService } from 'jslib-common/abstractions/i18n.service';
|
||||
import { KeyConnectorService } from 'jslib-common/abstractions/keyConnector.service';
|
||||
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
|
||||
import { StorageService } from 'jslib-common/abstractions/storage.service';
|
||||
import { StateService } from 'jslib-common/abstractions/state.service';
|
||||
import { SyncService } from 'jslib-common/abstractions/sync.service';
|
||||
import { UserService } from 'jslib-common/abstractions/user.service';
|
||||
|
||||
import { ConstantsService } from 'jslib-common/services/constants.service';
|
||||
|
||||
import { Organization } from 'jslib-common/models/domain/organization';
|
||||
|
||||
@@ -27,14 +24,14 @@ export class RemovePasswordComponent implements OnInit {
|
||||
organization: Organization;
|
||||
email: string;
|
||||
|
||||
constructor(private router: Router, private userService: UserService,
|
||||
constructor(private router: Router, private stateService: StateService,
|
||||
private apiService: ApiService, private syncService: SyncService,
|
||||
private platformUtilsService: PlatformUtilsService, private i18nService: I18nService,
|
||||
private keyConnectorService: KeyConnectorService, private storageService: StorageService) { }
|
||||
private keyConnectorService: KeyConnectorService) { }
|
||||
|
||||
async ngOnInit() {
|
||||
this.organization = await this.keyConnectorService.getManagingOrganization();
|
||||
this.email = await this.userService.getEmail();
|
||||
this.email = await this.stateService.getEmail();
|
||||
await this.syncService.fullSync(false);
|
||||
this.loading = false;
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@ export abstract class StateService {
|
||||
getCanAccessPremium: (options?: StorageOptions) => Promise<boolean>;
|
||||
getClearClipboard: (options?: StorageOptions) => Promise<number>;
|
||||
getCollapsedGroupings: (options?: StorageOptions) => Promise<Set<string>>;
|
||||
getConvertAccountToKeyConnector: (options?: StorageOptions) => Promise<boolean>;
|
||||
getCryptoMasterKey: (options?: StorageOptions) => Promise<SymmetricCryptoKey>;
|
||||
getCryptoMasterKeyB64: (options: StorageOptions) => Promise<string>;
|
||||
getDecodedToken: (options?: StorageOptions) => Promise<any>;
|
||||
@@ -135,6 +136,7 @@ export abstract class StateService {
|
||||
getTheme: (options?: StorageOptions) => Promise<string>;
|
||||
getTwoFactorToken: (options?: StorageOptions) => Promise<string>;
|
||||
getUserId: (options?: StorageOptions) => Promise<string>;
|
||||
getUsesKeyConnector: (options?: StorageOptions) => Promise<boolean>;
|
||||
getVaultTimeout: (options?: StorageOptions) => Promise<number>;
|
||||
getVaultTimeoutAction: (options?: StorageOptions) => Promise<string>;
|
||||
getWindow: () => Promise<Map<string, any>>;
|
||||
@@ -152,6 +154,7 @@ export abstract class StateService {
|
||||
setBiometricUnlock: (value: boolean, options?: StorageOptions) => Promise<void>;
|
||||
setClearClipboard: (value: number, options?: StorageOptions) => Promise<void>;
|
||||
setCollapsedGroupings: (value: Set<string>, options?: StorageOptions) => Promise<void>;
|
||||
setConvertAccountToKeyConnector: (value: boolean, options?: StorageOptions) => Promise<void>;
|
||||
setCryptoMasterKey: (value: SymmetricCryptoKey, options?: StorageOptions) => Promise<void>;
|
||||
setCryptoMasterKeyB64: (value: string, options: StorageOptions) => Promise<void>;
|
||||
setDecodedToken: (value: any, options?: StorageOptions) => Promise<void>;
|
||||
@@ -238,6 +241,7 @@ export abstract class StateService {
|
||||
setSsoState: (value: string, options?: StorageOptions) => Promise<void>;
|
||||
setTheme: (value: string, options?: StorageOptions) => Promise<void>;
|
||||
setTwoFactorToken: (value: string, options?: StorageOptions) => Promise<void>;
|
||||
setUsesKeyConnector: (vaule: boolean, options?: StorageOptions) => Promise<void>;
|
||||
setVaultTimeout: (value: number, options?: StorageOptions) => Promise<void>;
|
||||
setVaultTimeoutAction: (value: string, options?: StorageOptions) => Promise<void>;
|
||||
setWindow: (value: Map<string, any>) => Promise<void>;
|
||||
|
||||
@@ -130,6 +130,8 @@ export class Account {
|
||||
enableBiometric: boolean;
|
||||
enableBiometrics: boolean;
|
||||
noAutoPromptBiometricsText: string;
|
||||
convertAccountToKeyConnector: boolean;
|
||||
usesKeyConnector: boolean;
|
||||
private hasPremiumPersonally: boolean;
|
||||
|
||||
constructor(userId: string, userEmail: string,
|
||||
|
||||
@@ -3,9 +3,9 @@ import { CryptoService } from '../abstractions/crypto.service';
|
||||
import { EnvironmentService } from '../abstractions/environment.service';
|
||||
import { KeyConnectorService as KeyConnectorServiceAbstraction } from '../abstractions/keyConnector.service';
|
||||
import { LogService } from '../abstractions/log.service';
|
||||
import { StorageService } from '../abstractions/storage.service';
|
||||
import { OrganizationService } from '../abstractions/organization.service';
|
||||
import { StateService } from '../abstractions/state.service';
|
||||
import { TokenService } from '../abstractions/token.service';
|
||||
import { UserService } from '../abstractions/user.service';
|
||||
|
||||
import { OrganizationUserType } from '../enums/organizationUserType';
|
||||
|
||||
@@ -15,26 +15,18 @@ import { SymmetricCryptoKey } from '../models/domain/symmetricCryptoKey';
|
||||
|
||||
import { KeyConnectorUserKeyRequest } from '../models/request/keyConnectorUserKeyRequest';
|
||||
|
||||
const Keys = {
|
||||
usesKeyConnector: 'usesKeyConnector',
|
||||
convertAccountToKeyConnector: 'convertAccountToKeyConnector',
|
||||
};
|
||||
|
||||
export class KeyConnectorService implements KeyConnectorServiceAbstraction {
|
||||
private usesKeyConnector?: boolean = null;
|
||||
|
||||
constructor(private storageService: StorageService, private userService: UserService,
|
||||
private cryptoService: CryptoService, private apiService: ApiService,
|
||||
private environmentService: EnvironmentService, private tokenService: TokenService,
|
||||
private logService: LogService) { }
|
||||
constructor(private stateService: StateService, private cryptoService: CryptoService,
|
||||
private apiService: ApiService, private environmentService: EnvironmentService,
|
||||
private tokenService: TokenService, private logService: LogService,
|
||||
private organizationService: OrganizationService) { }
|
||||
|
||||
setUsesKeyConnector(usesKeyConnector: boolean) {
|
||||
this.usesKeyConnector = usesKeyConnector;
|
||||
return this.storageService.save(Keys.usesKeyConnector, usesKeyConnector);
|
||||
return this.stateService.setUsesKeyConnector(usesKeyConnector);
|
||||
}
|
||||
|
||||
async getUsesKeyConnector(): Promise<boolean> {
|
||||
return this.usesKeyConnector ??= await this.storageService.get<boolean>(Keys.usesKeyConnector);
|
||||
return await this.stateService.getUsesKeyConnector();
|
||||
}
|
||||
|
||||
async userNeedsMigration() {
|
||||
@@ -80,7 +72,7 @@ export class KeyConnectorService implements KeyConnectorServiceAbstraction {
|
||||
}
|
||||
|
||||
async getManagingOrganization() {
|
||||
const orgs = await this.userService.getAllOrganizations();
|
||||
const orgs = await this.organizationService.getAll();
|
||||
return orgs.find(o =>
|
||||
o.usesKeyConnector &&
|
||||
o.type !== OrganizationUserType.Admin &&
|
||||
@@ -89,15 +81,15 @@ export class KeyConnectorService implements KeyConnectorServiceAbstraction {
|
||||
}
|
||||
|
||||
async setConvertAccountRequired(status: boolean) {
|
||||
await this.storageService.save(Keys.convertAccountToKeyConnector, status);
|
||||
await this.stateService.setConvertAccountToKeyConnector(status);
|
||||
}
|
||||
|
||||
async getConvertAccountRequired(): Promise<boolean> {
|
||||
return await this.storageService.get(Keys.convertAccountToKeyConnector);
|
||||
return await this.stateService.getConvertAccountToKeyConnector();
|
||||
}
|
||||
|
||||
async removeConvertAccountRequired() {
|
||||
await this.storageService.remove(Keys.convertAccountToKeyConnector);
|
||||
await this.stateService.setConvertAccountToKeyConnector(null);
|
||||
}
|
||||
|
||||
async clear() {
|
||||
|
||||
@@ -517,6 +517,14 @@ export class StateService implements StateServiceAbstraction {
|
||||
return (await this.getGlobals(this.reconcileOptions(options, this.defaultInMemoryOptions))).organizationInvitation;
|
||||
}
|
||||
|
||||
async getConvertAccountToKeyConnector(options?: StorageOptions): Promise<boolean> {
|
||||
return (await this.getAccount(this.reconcileOptions(options, this.defaultOnDiskOptions)))?.convertAccountToKeyConnector;
|
||||
};
|
||||
|
||||
async getUsesKeyConnector(options?: StorageOptions): Promise<boolean> {
|
||||
return (await this.getAccount(this.reconcileOptions(options, this.defaultInMemoryOptions)))?.usesKeyConnector;
|
||||
};
|
||||
|
||||
async setAccessToken(value: string, options?: StorageOptions): Promise<void> {
|
||||
const account = await this.getAccount(this.reconcileOptions(options, this.defaultInMemoryOptions));
|
||||
account.accessToken = value;
|
||||
@@ -1154,6 +1162,18 @@ export class StateService implements StateServiceAbstraction {
|
||||
await this.saveGlobals(globals, this.reconcileOptions(options, this.defaultInMemoryOptions));
|
||||
}
|
||||
|
||||
async setConvertAccountToKeyConnector(value: boolean, options?: StorageOptions): Promise<void> {
|
||||
const account = await this.getAccount(this.reconcileOptions(options, this.defaultOnDiskOptions));
|
||||
account.convertAccountToKeyConnector = value;
|
||||
await this.saveAccount(account, this.reconcileOptions(options, this.defaultOnDiskOptions));
|
||||
}
|
||||
|
||||
async setUsesKeyConnector(value: boolean, options?: StorageOptions): Promise<void> {
|
||||
const account = await this.getAccount(this.reconcileOptions(options, this.defaultInMemoryOptions));
|
||||
account.usesKeyConnector = value;
|
||||
await this.saveAccount(account, this.reconcileOptions(options, this.defaultInMemoryOptions));
|
||||
}
|
||||
|
||||
async setActiveUser(userId: string): Promise<void> {
|
||||
if (!this.state.accounts[userId]) {
|
||||
return;
|
||||
|
||||
@@ -13,11 +13,6 @@ import { SendService } from '../abstractions/send.service';
|
||||
import { SettingsService } from '../abstractions/settings.service';
|
||||
import { StateService } from '../abstractions/state.service';
|
||||
import { SyncService as SyncServiceAbstraction } from '../abstractions/sync.service';
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
import { TokenService } from '../abstractions/token.service';
|
||||
import { UserService } from '../abstractions/user.service';
|
||||
>>>>>>> master
|
||||
|
||||
import { CipherData } from '../models/data/cipherData';
|
||||
import { CollectionData } from '../models/data/collectionData';
|
||||
@@ -48,14 +43,9 @@ export class SyncService implements SyncServiceAbstraction {
|
||||
private cryptoService: CryptoService, private collectionService: CollectionService,
|
||||
private messagingService: MessagingService, private policyService: PolicyService,
|
||||
private sendService: SendService, private logService: LogService,
|
||||
<<<<<<< HEAD
|
||||
private logoutCallback: (expired: boolean) => Promise<void>, private stateService: StateService,
|
||||
private organizationService: OrganizationService, private providerService: ProviderService) {
|
||||
=======
|
||||
private tokenService: TokenService, private keyConnectorService: KeyConnectorService,
|
||||
private logoutCallback: (expired: boolean) => Promise<void>) {
|
||||
>>>>>>> master
|
||||
}
|
||||
private keyConnectorService: KeyConnectorService, private stateService: StateService,
|
||||
private organizationService: OrganizationService, private providerService: ProviderService,
|
||||
private logoutCallback: (expired: boolean) => Promise<void>) { }
|
||||
|
||||
async getLastSync(): Promise<Date> {
|
||||
if (await this.stateService.getUserId() == null) {
|
||||
@@ -298,16 +288,10 @@ export class SyncService implements SyncServiceAbstraction {
|
||||
await this.cryptoService.setEncPrivateKey(response.privateKey);
|
||||
await this.cryptoService.setProviderKeys(response.providers);
|
||||
await this.cryptoService.setOrgKeys(response.organizations, response.providerOrganizations);
|
||||
<<<<<<< HEAD
|
||||
await this.stateService.setSecurityStamp(response.securityStamp);
|
||||
await this.stateService.setEmailVerified(response.emailVerified);
|
||||
await this.stateService.setForcePasswordReset(response.forcePasswordReset);
|
||||
=======
|
||||
await this.userService.setSecurityStamp(response.securityStamp);
|
||||
await this.userService.setEmailVerified(response.emailVerified);
|
||||
await this.userService.setForcePasswordReset(response.forcePasswordReset);
|
||||
await this.keyConnectorService.setUsesKeyConnector(response.usesKeyConnector);
|
||||
>>>>>>> master
|
||||
|
||||
const organizations: { [id: string]: OrganizationData; } = {};
|
||||
response.organizations.forEach(o => {
|
||||
|
||||
@@ -19,18 +19,11 @@ export class VaultTimeoutService implements VaultTimeoutServiceAbstraction {
|
||||
|
||||
constructor(private cipherService: CipherService, private folderService: FolderService,
|
||||
private collectionService: CollectionService, private cryptoService: CryptoService,
|
||||
<<<<<<< HEAD
|
||||
protected platformUtilsService: PlatformUtilsService, private messagingService: MessagingService,
|
||||
private searchService: SearchService, private tokenService: TokenService,
|
||||
private policyService: PolicyService, private stateService: StateService,
|
||||
private lockedCallback: () => Promise<void> = null, private loggedOutCallback: (userId?: string) => Promise<void> = null) {
|
||||
=======
|
||||
protected platformUtilsService: PlatformUtilsService, private storageService: StorageService,
|
||||
private messagingService: MessagingService, private searchService: SearchService,
|
||||
private userService: UserService, private tokenService: TokenService, private policyService: PolicyService,
|
||||
private keyConnectorService: KeyConnectorService,
|
||||
private lockedCallback: () => Promise<void> = null, private loggedOutCallback: () => Promise<void> = null) {
|
||||
>>>>>>> master
|
||||
private policyService: PolicyService, private keyConnectorService: KeyConnectorService,
|
||||
private stateService: StateService, private lockedCallback: () => Promise<void> = null,
|
||||
private loggedOutCallback: (userId?: string) => Promise<void> = null) {
|
||||
}
|
||||
|
||||
init(checkOnInterval: boolean) {
|
||||
@@ -103,7 +96,15 @@ export class VaultTimeoutService implements VaultTimeoutServiceAbstraction {
|
||||
return;
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
if (await this.keyConnectorService.getUsesKeyConnector()) {
|
||||
const pinSet = await this.isPinLockSet();
|
||||
const pinLock = (pinSet[0] && await this.stateService.getDecryptedPinProtected() != null) || pinSet[1];
|
||||
|
||||
if (!pinLock && !await this.isBiometricLockSet()) {
|
||||
await this.logOut();
|
||||
}
|
||||
}
|
||||
|
||||
if (userId == null || userId === await this.stateService.getUserId()) {
|
||||
this.searchService.clearIndex();
|
||||
}
|
||||
@@ -119,29 +120,6 @@ export class VaultTimeoutService implements VaultTimeoutServiceAbstraction {
|
||||
await this.stateService.setBiometricLocked(true, { userId: userId });
|
||||
|
||||
this.messagingService.send('locked', { userId: userId });
|
||||
=======
|
||||
if (await this.keyConnectorService.getUsesKeyConnector()) {
|
||||
const pinSet = await this.isPinLockSet();
|
||||
const pinLock = (pinSet[0] && this.pinProtectedKey != null) || pinSet[1];
|
||||
|
||||
if (!pinLock && !await this.isBiometricLockSet()) {
|
||||
await this.logOut();
|
||||
}
|
||||
}
|
||||
|
||||
this.biometricLocked = true;
|
||||
this.everBeenUnlocked = true;
|
||||
await this.cryptoService.clearKey(false);
|
||||
await this.cryptoService.clearOrgKeys(true);
|
||||
await this.cryptoService.clearKeyPair(true);
|
||||
await this.cryptoService.clearEncKey(true);
|
||||
|
||||
this.folderService.clearCache();
|
||||
this.cipherService.clearCache();
|
||||
this.collectionService.clearCache();
|
||||
this.searchService.clearIndex();
|
||||
this.messagingService.send('locked');
|
||||
>>>>>>> master
|
||||
if (this.lockedCallback != null) {
|
||||
await this.lockedCallback();
|
||||
}
|
||||
|
||||
@@ -49,14 +49,9 @@ export class LoginCommand {
|
||||
protected i18nService: I18nService, protected environmentService: EnvironmentService,
|
||||
protected passwordGenerationService: PasswordGenerationService,
|
||||
protected cryptoFunctionService: CryptoFunctionService, protected platformUtilsService: PlatformUtilsService,
|
||||
<<<<<<< HEAD
|
||||
protected stateService: StateService, protected cryptoService: CryptoService,
|
||||
protected policyService: PolicyService, clientId: string, private syncService: SyncService) {
|
||||
=======
|
||||
protected userService: UserService, protected cryptoService: CryptoService,
|
||||
protected policyService: PolicyService, clientId: string, private syncService: SyncService,
|
||||
protected keyConnectorService: KeyConnectorService) {
|
||||
>>>>>>> master
|
||||
this.clientId = clientId;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user