Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.owasp.appsensor.storage.jpa2;
 
 
 
This is a jpa2 implementation of the org.owasp.appsensor.storage.EventStore. Implementations of the org.owasp.appsensor.listener.EventListener interface can register with this class and be notified when new org.owasp.appsensor.Events are added to the data store The implementation stores the org.owasp.appsensor.Event in a jpa2 driven DB.

Author(s):
John Melton (jtmelton@gmail.com) http://www.jtmelton.com/
public class Jpa2EventStore extends EventStore {
	private Logger logger;

maintain a repository to read/write org.owasp.appsensor.Events from
	public void addEvent(Event event) {
		.warn("Security event " + event.getDetectionPoint().getLabel() + " triggered by user: " + event.getUser().getUsername());
		super.notifyListeners(event);
	}

	public Collection<EventfindEvents(SearchCriteria criteria) {
		if (criteria == null) {
			throw new IllegalArgumentException("criteria must be non-null");
		}
		Collection<Eventmatches = new ArrayList<Event>();
		User user = criteria.getUser();
		DetectionPoint detectionPoint = criteria.getDetectionPoint();
		Collection<StringdetectionSystemIds = criteria.getDetectionSystemIds(); 
		DateTime earliest = DateUtils.fromString(criteria.getEarliest());
		// TODO: instead of findAll every time (inefficient), update this to do actual query
		for (Event event : .findAll()) {
			//check user match if user specified
			boolean userMatch = (user != null) ? user.equals(event.getUser()) : true;
			//check detection system match if detection systems specified
			boolean detectionSystemMatch = (detectionSystemIds != null && detectionSystemIds.size() > 0) ? 
					detectionSystemIds.contains(event.getDetectionSystemId()) : true;
			//check detection point match if detection point specified
			boolean detectionPointMatch = (detectionPoint != null) ? 
					detectionPoint.typeMatches(event.getDetectionPoint()) : true;
			boolean earliestMatch = (earliest != null) ? earliest.isBefore(DateUtils.fromString(event.getTimestamp())) : true;
			if (userMatch && detectionSystemMatch && detectionPointMatch && earliestMatch) {
				matches.add(event);
			}
		}
		return matches;
	}
New to GrepCode? Check out our FAQ X