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.ResponseStore. Implementations of the org.owasp.appsensor.listener.ResponseListener interface can register with this class and be notified when new org.owasp.appsensor.Responses are added to the data store The implementation stores the org.owasp.appsensor.Response in a jpa2 driven DB.

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

maintain a repository to read/write org.owasp.appsensor.Events from
	public void addResponse(Response response) {
		.warn("Security response " + response + " triggered for user: " + response.getUser().getUsername());
		super.notifyListeners(response);
	}

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