1 package org.apache.activemq.util; 2 3 import java.io.IOException ; 4 5 import javax.servlet.Filter ; 6 import javax.servlet.FilterChain ; 7 import javax.servlet.FilterConfig ; 8 import javax.servlet.ServletException ; 9 import javax.servlet.ServletRequest ; 10 import javax.servlet.ServletResponse ; 11 import javax.servlet.http.HttpServletRequest ; 12 import javax.servlet.http.HttpServletRequestWrapper ; 13 14 import org.mortbay.log.Log; 15 16 public class FilenameGuardFilter implements Filter { 17 18 public void destroy() { 19 } 21 22 public void init(FilterConfig config) throws ServletException { 23 } 25 26 public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException , ServletException { 27 if (request instanceof HttpServletRequest ) { 28 HttpServletRequest httpRequest = (HttpServletRequest )request; 29 GuardedHttpServletRequest guardedRequest = new GuardedHttpServletRequest(httpRequest); 30 chain.doFilter(guardedRequest, response); 31 } else { 32 chain.doFilter(request, response); 33 } 34 } 35 36 private static class GuardedHttpServletRequest extends HttpServletRequestWrapper { 37 38 public GuardedHttpServletRequest(HttpServletRequest httpRequest) { 39 super(httpRequest); 40 } 41 42 private String guard(String filename) { 43 String guarded = filename.replace(":", "_"); 44 if (Log.isDebugEnabled()) 45 { 46 Log.debug("guarded " + filename + " to "+ guarded); 47 } 48 return guarded; 49 } 50 51 @Override 52 public String getParameter(String name) { 53 if (name.equals("Destination")) { 54 return guard(super.getParameter(name)); 55 } else { 56 return super.getParameter(name); 57 } 58 } 59 60 @Override 61 public String getPathInfo() { 62 return guard(super.getPathInfo()); 63 } 64 65 @Override 66 public String getPathTranslated() { 67 return guard(super.getPathTranslated()); 68 } 69 70 @Override 71 public String getRequestURI() { 72 return guard(super.getRequestURI()); 73 } 74 } 75 } 76 | Popular Tags |