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

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

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

		if (criteria == null) {
			throw new IllegalArgumentException("criteria must be non-null");
		}
		Collection<Attackmatches = new ArrayList<Attack>();
		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 (Attack attack : .findAll()) {
			//check user match if user specified
			boolean userMatch = (user != null) ? user.equals(attack.getUser()) : true;
			//check detection system match if detection systems specified
			boolean detectionSystemMatch = (detectionSystemIds != null && detectionSystemIds.size() > 0) ? 
					detectionSystemIds.contains(attack.getDetectionSystemId()) : true;
			//check detection point match if detection point specified
			boolean detectionPointMatch = (detectionPoint != null) ? 
					detectionPoint.typeMatches(attack.getDetectionPoint()) : true;
			boolean earliestMatch = (earliest != null) ? earliest.isBefore(DateUtils.fromString(attack.getTimestamp())) : true;
			if (userMatch && detectionSystemMatch && detectionPointMatch && earliestMatch) {
				matches.add(attack);
			}
		}
		return matches;
	}
New to GrepCode? Check out our FAQ X