1 2 package org.roller.presentation.filters; 3 4 import java.io.IOException ; 5 import java.util.Arrays ; 6 import java.util.List ; 7 8 import javax.servlet.Filter ; 9 import javax.servlet.FilterChain ; 10 import javax.servlet.FilterConfig ; 11 import javax.servlet.ServletException ; 12 import javax.servlet.ServletRequest ; 13 import javax.servlet.ServletResponse ; 14 import javax.servlet.http.HttpServletRequest ; 15 import javax.servlet.http.HttpServletResponse ; 16 17 import org.apache.commons.logging.Log; 18 import org.apache.commons.logging.LogFactory; 19 import org.roller.util.StringUtils; 20 21 28 public class IPBanFilter implements Filter 29 { 30 private List denyFrom = null; 31 private static Log mLogger = 32 LogFactory.getFactory().getInstance(IPBanFilter.class); 33 34 public IPBanFilter() 35 { 36 super(); 37 } 38 39 public void init(FilterConfig filterConfig) throws ServletException 40 { 41 49 String denyFromParam = filterConfig.getInitParameter("denyFrom"); 50 denyFrom = Arrays.asList(StringUtils.split(denyFromParam,",")); 51 } 52 53 public void doFilter( 54 ServletRequest req, 55 ServletResponse res, 56 FilterChain chain) 57 throws IOException , ServletException 58 { 59 HttpServletRequest request = (HttpServletRequest ) req; 60 HttpServletResponse response = (HttpServletResponse ) res; 61 if (denyFrom.contains(request.getRemoteAddr())) 62 { 63 response.setStatus(HttpServletResponse.SC_FORBIDDEN); 64 return; 65 } 66 else 67 { 68 chain.doFilter(request, response); 69 } 70 } 71 72 public void destroy() 73 { 74 } 75 } 76 | Popular Tags |