mirror of
https://github.com/bitwarden/browser
synced 2025-12-10 21:33:27 +00:00
[EC-320] Add organization vault export to event logs (#3136)
* Added organizationId to EventData and EventRequest * Added EventType Organization_ClientExportedVault * Sending organizationId on Organization Export event * Checking that the user belongs to the organization * Added organizationExportResponse model * Added API method to get Organization vault export data * Updated getOrganizationDecryptedExport to use new API method
This commit is contained in:
@@ -130,6 +130,7 @@ import {
|
||||
OrganizationConnectionConfigApis,
|
||||
OrganizationConnectionResponse,
|
||||
} from "../models/response/organizationConnectionResponse";
|
||||
import { OrganizationExportResponse } from "../models/response/organizationExportResponse";
|
||||
import { OrganizationKeysResponse } from "../models/response/organizationKeysResponse";
|
||||
import { OrganizationResponse } from "../models/response/organizationResponse";
|
||||
import { OrganizationSponsorshipSyncStatusResponse } from "../models/response/organizationSponsorshipSyncStatusResponse";
|
||||
@@ -734,4 +735,5 @@ export abstract class ApiService {
|
||||
request: KeyConnectorUserKeyRequest
|
||||
) => Promise<void>;
|
||||
getKeyConnectorAlive: (keyConnectorUrl: string) => Promise<void>;
|
||||
getOrganizationExport: (organizationId: string) => Promise<OrganizationExportResponse>;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
import { EventType } from "../enums/eventType";
|
||||
|
||||
export abstract class EventService {
|
||||
collect: (eventType: EventType, cipherId?: string, uploadImmediately?: boolean) => Promise<any>;
|
||||
collect: (
|
||||
eventType: EventType,
|
||||
cipherId?: string,
|
||||
uploadImmediately?: boolean,
|
||||
organizationId?: string
|
||||
) => Promise<any>;
|
||||
uploadEvents: (userId?: string) => Promise<any>;
|
||||
clearEvents: (userId?: string) => Promise<any>;
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ export enum EventType {
|
||||
|
||||
Organization_Updated = 1600,
|
||||
Organization_PurgedVault = 1601,
|
||||
// Organization_ClientExportedVault = 1602,
|
||||
Organization_ClientExportedVault = 1602,
|
||||
Organization_VaultAccessed = 1603,
|
||||
Organization_EnabledSso = 1604,
|
||||
Organization_DisabledSso = 1605,
|
||||
|
||||
@@ -4,4 +4,5 @@ export class EventData {
|
||||
type: EventType;
|
||||
cipherId: string;
|
||||
date: string;
|
||||
organizationId: string;
|
||||
}
|
||||
|
||||
@@ -4,4 +4,5 @@ export class EventRequest {
|
||||
type: EventType;
|
||||
cipherId: string;
|
||||
date: string;
|
||||
organizationId: string;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import { BaseResponse } from "./baseResponse";
|
||||
import { CipherResponse } from "./cipherResponse";
|
||||
import { CollectionResponse } from "./collectionResponse";
|
||||
import { ListResponse } from "./listResponse";
|
||||
|
||||
export class OrganizationExportResponse extends BaseResponse {
|
||||
collections: ListResponse<CollectionResponse>;
|
||||
ciphers: ListResponse<CipherResponse>;
|
||||
|
||||
constructor(response: any) {
|
||||
super(response);
|
||||
this.collections = this.getResponseProperty("Collections");
|
||||
this.ciphers = this.getResponseProperty("Ciphers");
|
||||
}
|
||||
}
|
||||
@@ -139,6 +139,7 @@ import {
|
||||
OrganizationConnectionConfigApis,
|
||||
OrganizationConnectionResponse,
|
||||
} from "../models/response/organizationConnectionResponse";
|
||||
import { OrganizationExportResponse } from "../models/response/organizationExportResponse";
|
||||
import { OrganizationKeysResponse } from "../models/response/organizationKeysResponse";
|
||||
import { OrganizationResponse } from "../models/response/organizationResponse";
|
||||
import { OrganizationSponsorshipSyncStatusResponse } from "../models/response/organizationSponsorshipSyncStatusResponse";
|
||||
@@ -2323,6 +2324,17 @@ export class ApiService implements ApiServiceAbstraction {
|
||||
}
|
||||
}
|
||||
|
||||
async getOrganizationExport(organizationId: string): Promise<OrganizationExportResponse> {
|
||||
const r = await this.send(
|
||||
"GET",
|
||||
"/organizations/" + organizationId + "/export",
|
||||
null,
|
||||
true,
|
||||
true
|
||||
);
|
||||
return new OrganizationExportResponse(r);
|
||||
}
|
||||
|
||||
// Helpers
|
||||
|
||||
async getActiveBearerToken(): Promise<string> {
|
||||
|
||||
@@ -34,7 +34,8 @@ export class EventService implements EventServiceAbstraction {
|
||||
async collect(
|
||||
eventType: EventType,
|
||||
cipherId: string = null,
|
||||
uploadImmediately = false
|
||||
uploadImmediately = false,
|
||||
organizationId: string = null
|
||||
): Promise<any> {
|
||||
const authed = await this.stateService.getIsAuthenticated();
|
||||
if (!authed) {
|
||||
@@ -54,6 +55,11 @@ export class EventService implements EventServiceAbstraction {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (organizationId != null) {
|
||||
if (!orgIds.has(organizationId)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
let eventCollection = await this.stateService.getEventCollection();
|
||||
if (eventCollection == null) {
|
||||
eventCollection = [];
|
||||
@@ -62,6 +68,7 @@ export class EventService implements EventServiceAbstraction {
|
||||
event.type = eventType;
|
||||
event.cipherId = cipherId;
|
||||
event.date = new Date().toISOString();
|
||||
event.organizationId = organizationId;
|
||||
eventCollection.push(event);
|
||||
await this.stateService.setEventCollection(eventCollection);
|
||||
if (uploadImmediately) {
|
||||
@@ -83,6 +90,7 @@ export class EventService implements EventServiceAbstraction {
|
||||
req.type = e.type;
|
||||
req.cipherId = e.cipherId;
|
||||
req.date = e.date;
|
||||
req.organizationId = e.organizationId;
|
||||
return req;
|
||||
});
|
||||
try {
|
||||
|
||||
@@ -245,38 +245,41 @@ export class ExportService implements ExportServiceAbstraction {
|
||||
const promises = [];
|
||||
|
||||
promises.push(
|
||||
this.apiService.getCollections(organizationId).then((collections) => {
|
||||
const collectionPromises: any = [];
|
||||
if (collections != null && collections.data != null && collections.data.length > 0) {
|
||||
collections.data.forEach((c) => {
|
||||
const collection = new Collection(new CollectionData(c as CollectionDetailsResponse));
|
||||
collectionPromises.push(
|
||||
collection.decrypt().then((decCol) => {
|
||||
decCollections.push(decCol);
|
||||
})
|
||||
);
|
||||
});
|
||||
}
|
||||
return Promise.all(collectionPromises);
|
||||
})
|
||||
);
|
||||
|
||||
promises.push(
|
||||
this.apiService.getCiphersOrganization(organizationId).then((ciphers) => {
|
||||
const cipherPromises: any = [];
|
||||
if (ciphers != null && ciphers.data != null && ciphers.data.length > 0) {
|
||||
ciphers.data
|
||||
.filter((c) => c.deletedDate === null)
|
||||
.forEach((c) => {
|
||||
const cipher = new Cipher(new CipherData(c));
|
||||
cipherPromises.push(
|
||||
cipher.decrypt().then((decCipher) => {
|
||||
decCiphers.push(decCipher);
|
||||
this.apiService.getOrganizationExport(organizationId).then((exportData) => {
|
||||
const exportPromises: any = [];
|
||||
if (exportData != null) {
|
||||
if (
|
||||
exportData.collections != null &&
|
||||
exportData.collections.data != null &&
|
||||
exportData.collections.data.length > 0
|
||||
) {
|
||||
exportData.collections.data.forEach((c) => {
|
||||
const collection = new Collection(new CollectionData(c as CollectionDetailsResponse));
|
||||
exportPromises.push(
|
||||
collection.decrypt().then((decCol) => {
|
||||
decCollections.push(decCol);
|
||||
})
|
||||
);
|
||||
});
|
||||
}
|
||||
if (
|
||||
exportData.ciphers != null &&
|
||||
exportData.ciphers.data != null &&
|
||||
exportData.ciphers.data.length > 0
|
||||
) {
|
||||
exportData.ciphers.data
|
||||
.filter((c) => c.deletedDate === null)
|
||||
.forEach((c) => {
|
||||
const cipher = new Cipher(new CipherData(c));
|
||||
exportPromises.push(
|
||||
cipher.decrypt().then((decCipher) => {
|
||||
decCiphers.push(decCipher);
|
||||
})
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
return Promise.all(cipherPromises);
|
||||
return Promise.all(exportPromises);
|
||||
})
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user