1 package com.openinventions.webappfilter.processor; 2 3 import com.openinventions.metaframework.*; 4 import org.apache.commons.logging.*; 5 6 public class AccessControlList implements Processor { 7 private static final Log log = LogFactory.getLog(AccessControlList.class); 8 private Element acl = null; 9 10 public void process(State state, Element context) throws Exception { 11 ElementFactory factory = (ElementFactory) state.get("com.openinventions.metaframework.ElementFactory"); 12 String mode = context.getValue("@mode"); 13 String file = context.getValue("file"); 14 file = (String ) state.get("rootDir") + "/" + file; 15 16 if (mode.equals("init")) { 17 log.error("init " + file); 18 acl = factory.read(file); 19 } else if (mode.equals("destroy")) { 20 log.error("destroy " + file); 21 factory.write(file, acl); 22 } else if (mode.equals("ban")) { 23 Element request = (Element) state.get("req"); 24 log.error("ban " + request.getValue("ip")); 25 acl.setValue("/deny-list/deny/match[xpath='request/ip']/string", request.getValue("ip")); 26 } else if (mode.equals("reject")) { 27 Element request = (Element) state.get("req"); 28 Element response = (Element) state.get("res"); 29 30 if (log.isDebugEnabled()) { 31 log.debug("acl =" + request.getValue("ip") + "=" + acl.isExists("/deny-list/deny/match[xpath='request/ip'][string='" + request.getValue("ip") + "']") + "=" + factory.toString(acl)); 32 } 33 34 if (acl.isExists("/deny-list/deny/match[xpath='request/ip'][string='" + request.getValue("ip") + "']")) { 35 response.setValue("body", "<html><body>You have been rejected from this website.</body></html>"); 36 state.set("filterDirection", "backward"); 37 } 38 } else { 39 log.error("Mode not set. Is this init or destory or something else? " + mode); 40 return; 41 } 42 } 43 } 44 95 | Popular Tags |