01: /*
02:
03: This software is OSI Certified Open Source Software.
04: OSI Certified is a certification mark of the Open Source Initiative.
05:
06: The license (Mozilla version 1.0) can be read at the MMBase site.
07: See http://www.MMBase.org/license
08:
09: */
10: package org.mmbase.datatypes.processors;
11:
12: import org.mmbase.bridge.*;
13:
14: /**
15: * This processor can be used as a 'commit' processor on a string field. The field will then be set
16: * to the IP address of the current user. If at least that is possible.
17: *
18: * @author Michiel Meeuwissen
19: * @version $Id: Ip.java,v 1.2 2008/03/12 16:03:30 michiel Exp $
20: * @since MMBase-1.8.6
21: */
22:
23: public class Ip implements CommitProcessor {
24:
25: private static final long serialVersionUID = 1L;
26:
27: public void commit(Node node, Field field) {
28: javax.servlet.http.HttpServletRequest req = (javax.servlet.http.HttpServletRequest) node
29: .getCloud().getProperty("request");
30: if (req != null) {
31: String ip = req.getHeader("X-Forwarded-For");
32: if (ip == null || "".equals(ip)) {
33: ip = req.getRemoteAddr();
34: }
35: if (ip != null && !"".equals(ip)) {
36: node.setValueWithoutProcess(field.getName(), ip);
37: }
38: }
39: }
40:
41: public String toString() {
42: return "ip";
43: }
44: }
|