All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jwall.audit.processor.DefaultRequestHost Maven / Gradle / Ivy

/*
 *  Copyright (C) 2007-2014 Christian Bockermann 
 *
 *  This file is part of the  web-audit  library.
 *
 *  web-audit library is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  The  web-audit  library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see .
 *
 */
package org.jwall.audit.processor;

import java.util.List;
import java.util.Map;

import org.jwall.audit.EventProcessor;
import org.jwall.web.audit.AuditEvent;
import org.jwall.web.audit.ModSecurity;

/**
 * This simple event processor fills in a default host value for events that do
 * not come with a request header including a Host:-field.
 * 
 * @author Christian Bockermann <[email protected]>
 * 
 */
public class DefaultRequestHost implements EventProcessor {
	public final static String NOT_SET = "N/A";

	String value = NOT_SET;

	/**
	 * @see org.jwall.audit.EventProcessor#processEvent(org.jwall.audit.Event,
	 *      java.util.Map)
	 */
	@Override
	public AuditEvent processEvent(AuditEvent event, Map context)
			throws Exception {

		List values = event.getAll(ModSecurity.REQUEST_HEADERS
				+ ":Host");
		if (!event.isSet(ModSecurity.REQUEST_HEADERS + ":Host")
				|| values == null || values.isEmpty()
				|| "".equals(values.get(0).trim())) {
			event.set(ModSecurity.REQUEST_HEADERS + ":Host".toUpperCase(),
					value);
		}

		return event;
	}

	/**
	 * A simple getter for the default host value.
	 * 
	 * @return
	 */
	public String getValue() {
		return value;
	}

	/**
	 * A simple setter for the default host value.
	 * 
	 * @param defaultHost
	 */
	public void setValue(String defaultHost) {
		this.value = defaultHost;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy