UNPKG

@appsensorlike/appsensorlike

Version:

A port of OWASP AppSensor reference implementation

253 lines (252 loc) 10.8 kB
import { AppSensorEvent, Attack, Response } from "../core.js"; import { SearchCriteria } from "../criteria/criteria.js"; import { AttackListener, EventListener, ResponseListener } from "../listener/listener.js"; /** * A store is an observable object. * * It is watched by implementations of the {@link AttackListener} interfaces. * * In this case the analysis engines watch the *Store interfaces of AppSensor. * * In contrast to the ORIGINAL code here methods add/find/notify are asynchronous returning Promise<T>. */ declare abstract class AttackStore { private listeners; /** * Add an attack to the AttackStore * * @param attack the {@link Attack} object to add to the AttackStore */ abstract addAttack(attack: Attack): Promise<void>; /** * Finder for attacks in the AttackStore. * * @param criteria the {@link SearchCriteria} object to search by * @return a Promise which resolves to {@link Attack}[] objects matching the search criteria. */ abstract findAttacks(criteria: SearchCriteria): Promise<Attack[]>; /** * Count how many attacks in the AttackStore match the search criteria. * * ADDITION TO THE ORIGINAL CODE * * @param criteria the {@link SearchCriteria} object to search by * @return count of {@link Attack}s matching the search criteria. */ abstract countAttacks(criteria: SearchCriteria): Promise<number>; /** * Register an {@link AttackListener} to notify when Attacks are added * * @param listener the {@link AttackListener} to register * @param atBeginning if the listener has to be added at the first position, i.e. to be notified first */ registerListener(listener: AttackListener, atBeginning?: boolean): void; /** * Notify each {@link AttackListener} of the specified Attack * * @param attack the {@link Attack} to notify each AttackListener about */ notifyListeners(attack: Attack): Promise<void>; /** * Set {@link AttackListener}s so they can be notified of changes. * * @param listeners of {@link AttackListener}s that are set to be listeners on the AttackStore * @param atBeginning if the listener has to be added at the first position, i.e. to be notified first */ setListeners(listeners: AttackListener[], atBeginning?: boolean): void; /** * Finder for attacks in the AttackStore. * * @param criteria the {@link SearchCriteria} object to search by * @param attacks the {@link Attack} objects to match on - supplied by subclasses * @return Attack[] objects matching the search criteria. */ protected _findAttacks(criteria: SearchCriteria, attacks: Attack[]): Attack[]; /** * Count how many attacks in the AttackStore match the search criteria. * * ADDITION TO THE ORIGINAL CODE * * @param criteria the {@link SearchCriteria} object to search by * @param attacks the {@link Attack} objects to match on - supplied by subclasses * @return count of {@link Attack}s matching the search criteria. */ protected _countAttacks(criteria: SearchCriteria, attacks: Attack[]): number; /** * Finder for attacks in the AttackStore. * * The code was moved to {@link Utils} in order the same logic to be * utilized in other places as well * * @param criteria the {@link SearchCriteria} object to search by * @param attack the {@link Attack} object to match on * @return true or false depending on the matching of the search criteria to the {@link Attack} */ protected isMatchingAttack(criteria: SearchCriteria, attack: Attack): boolean; } /** * A store is an observable object. * * It is watched by implementations of the {@link EventListener} interfaces. * * In this case the analysis engines watch the *Store interfaces of AppSensor. * * In contrast to the ORIGINAL code here methods add/find/notify are asynchronous returning Promise<T>. */ declare abstract class EventStore { private listeners; /** * Add an {@link AppSensorEvent} to the EventStore * * @param event the {@link AppSensorEvent} to add to the EventStore */ abstract addEvent(event: AppSensorEvent): Promise<void>; /** * A finder for {@link AppSensorEvent} objects in the EventStore * * @param criteria the {@link SearchCriteria} object to search by * @return a Promise which resolves to {@link AppSensorEvent}[] objects matching the search criteria. */ abstract findEvents(criteria: SearchCriteria): Promise<AppSensorEvent[]>; /** * Count how many events in the EventStore match the search criteria. * * ADDITION TO THE ORIGINAL CODE * * @param criteria the {@link SearchCriteria} object to search by * @return count of {@link AppSensorEvent}s matching the search criteria. */ abstract countEvents(criteria: SearchCriteria): Promise<number>; /** * Register an {@link EventListener} to notify when {@link AppSensorEvent}s are added * * @param listener the {@link EventListener} to register * @param atBeginning if the listener has to be added at the first position, i.e. to be notified first */ registerListener(listener: EventListener, atBeginning?: boolean): void; /** * Notify each {@link EventListener} of the specified {@link AppSensorEvent} * * @param event the {@link AppSensorEvent} to notify each {@link EventListener} about */ notifyListeners(event: AppSensorEvent): Promise<void>; /** * Set {@link EventListener}s so they can be notified of changes. * * @param listeners of {@link EventListener}s that are set to be listeners on the EventStore * @param atBeginning if the listener has to be added at the first position, i.e. to be notified first */ setListeners(listeners: EventListener[], atBeginning?: boolean): void; /** * A finder for Event objects in the EventStore * * @param criteria the {@link SearchCriteria} object to search by * @param events the {@link AppSensorEvent} objects to match on - supplied by subclasses * @return AppSensorEvent[] objects matching the search criteria. */ _findEvents(criteria: SearchCriteria, events: AppSensorEvent[]): AppSensorEvent[]; /** * Count how many events in the EventStore match the search criteria. * * ADDITION TO THE ORIGINAL CODE * * @param criteria the {@link SearchCriteria} object to search by * @param events the {@link AppSensorEvent} objects to match on - supplied by subclasses * @return count of {@link AppSensorEvent}s matching the search criteria. */ _countEvents(criteria: SearchCriteria, events: AppSensorEvent[]): number; /** * A finder for Event objects in the EventStore * * The code was moved to {@link Utils} in order the same logic to be * utilized in other places as well * * @param criteria the {@link SearchCriteria} object to search by * @param event the {@link AppSensorEvent} object to match on * @return true or false depending on the matching of the search criteria to the event */ protected isMatchingEvent(criteria: SearchCriteria, event: AppSensorEvent): boolean; } /** * A store is an observable object. * * It is watched by implementations of the {@link ResponseListener} interfaces. * * In this case the analysis engines watch the *Store interfaces of AppSensor. * * In contrast to the ORIGINAL code here methods add/find/notify are asynchronous returning Promise<T>. * */ declare abstract class ResponseStore { private listeners; /** * Add a response to the ResponseStore * * @param response {@link Response} to add to the ResponseStore */ abstract addResponse(response: Response): Promise<void>; /** * Finder for responses in the ResponseStore * * @param criteria the {@link SearchCriteria} object to search by * @return a Promise which resolves to {@link Response}[] objects matching the search criteria. */ abstract findResponses(criteria: SearchCriteria): Promise<Response[]>; /** * Count how many responses in the ResponseStore match the search criteria. * * ADDITION TO THE ORIGINAL CODE * * @param criteria the {@link SearchCriteria} object to search by * @return count of {@link Response}s matching the search criteria. */ abstract countResponses(criteria: SearchCriteria): Promise<number>; /** * Finder for responses in the ResponseStore * * @param criteria the {@link SearchCriteria} object to search by * @return Response[] objects matching the search criteria. */ _findResponses(criteria: SearchCriteria, responses: Response[]): Response[]; /** * Count how many responses in the ResponseStore match the search criteria. * * ADDITION TO THE ORIGINAL CODE * * @param criteria the {@link SearchCriteria} object to search by * @param responses the {@link Response} objects to match on - supplied by subclasses * @return count of {@link Response}s matching the search criteria. */ _countResponses(criteria: SearchCriteria, responses: Response[]): number; /** * Register an {@link ResponseListener} to notify when {@link Response}s are added * * @param listener the {@link ResponseListener} to register */ registerListener(listener: ResponseListener, atBeginning?: boolean): void; /** * Notify each {@link ResponseListener} of the specified {@link Response} * * @param response the {@link Response} to notify each {@link ResponseListener} about */ notifyListeners(response: Response): Promise<void>; /** * Set {@link ResponseListener}s so they can be notified of changes. * * @param listeners of {@link ResponseListener}s that are set to be listeners on the ResponseStore * @param atBeginning if the listener has to be added at the first position, i.e. to be notified first */ setListeners(listeners: ResponseListener[], atBeginning?: boolean): void; /** * A finder for Response objects in the ResponseStore * * The code was moved to {@link Utils} in order the same logic to be * utilized in other places as well * * @param criteria the {@link SearchCriteria} object to search by * @param response the {@link Response} object to match on * @return true or false depending on the matching of the search criteria to the event */ protected isMatchingResponse(criteria: SearchCriteria, response: Response): boolean; } export { AttackStore, EventStore, ResponseStore };