UNPKG

@appsensorlike/appsensorlike

Version:

A port of OWASP AppSensor reference implementation

74 lines (73 loc) 2.76 kB
import { SearchCriteria } from "../../../core/criteria/criteria.js"; class LocalRequestHandler { constructor(appSensorServer) { this.appSensorServer = appSensorServer; } /** * {@inheritDoc} */ async addEvent(event) { const detSystem = event.getDetectionSystem(); if (LocalRequestHandler.detectionSystemId === null && detSystem !== null) { LocalRequestHandler.detectionSystemId = detSystem.getDetectionSystemId(); } const eventStore = this.appSensorServer.getEventStore(); if (eventStore) { await eventStore.addEvent(event); } } /** * {@inheritDoc} */ async addAttack(attack) { const detSystem = attack.getDetectionSystem(); if (LocalRequestHandler.detectionSystemId == null && detSystem !== null) { LocalRequestHandler.detectionSystemId = detSystem.getDetectionSystemId(); } const attackStore = this.appSensorServer.getAttackStore(); if (attackStore) { await attackStore.addAttack(attack); } } /** * {@inheritDoc} */ async getResponses(earliest) { const detSystem = LocalRequestHandler.detectionSystemId !== null ? LocalRequestHandler.detectionSystemId : ""; const criteria = new SearchCriteria(). setDetectionSystemIds([detSystem]). setEarliest(earliest); let responses = []; const responseStore = this.appSensorServer.getResponseStore(); if (responseStore) { responses = await responseStore.findResponses(criteria); } return responses; } async getEvents(earliest) { const detSystem = LocalRequestHandler.detectionSystemId !== null ? LocalRequestHandler.detectionSystemId : ""; const criteria = new SearchCriteria(). setDetectionSystemIds([detSystem]). setEarliest(earliest); let events = []; const eventStore = this.appSensorServer.getEventStore(); if (eventStore) { events = await eventStore.findEvents(criteria); } return events; } async getAttacks(earliest) { const detSystem = LocalRequestHandler.detectionSystemId !== null ? LocalRequestHandler.detectionSystemId : ""; const criteria = new SearchCriteria(). setDetectionSystemIds([detSystem]). setEarliest(earliest); let attacks = []; const attackStore = this.appSensorServer.getAttackStore(); if (attackStore) { attacks = await attackStore.findAttacks(criteria); } return attacks; } } LocalRequestHandler.detectionSystemId = null; //start with blank export { LocalRequestHandler };