tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From haim <>
Subject Re: IP based restriction
Date Mon, 04 Apr 2005 12:31:55 GMT
Try the following filer class
Add this to web.xml


import java.util.Properties;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

 * @author haim
public class AccessControl implements Filter {

      /* (non-Javadoc)
     * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
    public void init(FilterConfig arg0) throws ServletException {
        System.out.println("Init AccessControl");
     *  Filter the pages accessing back office by their IP address prefix.
     *  The following must be set in order to keep this filter working
     *  1. Setting of the filter in the web.xml file
     *  2. Defining address prefix in the file by 
defining the
     *        key access.filter
     *  @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, 
javax.servlet.ServletResponse, javax.servlet.FilterChain)
    public void doFilter(ServletRequest request, ServletResponse 
response, FilterChain chain)
         throws IOException, ServletException {
          HttpServletRequest httpReq = (HttpServletRequest) request;
          HttpServletResponse httpResp = (HttpServletResponse) response;
          String remoteAddress=request.getRemoteAddr();
          System.out.println("Backoffice Access request from "+  
          //allow only ip's starting with 10.0.
               System.out.println("Access aproved");
               System.out.println("Access rejected!");
         * Process the rest of the filter chain, if any, and ultimately
         * the requested servlet or JSP page.
          chain.doFilter(request, response);


Jobish P wrote:

>Hi all,
>I am a newbie to Tomcat. I have installed Tomcat 5.0.19 on Redhat LInux 9,
>and going fine. I would like to restrict some of my directories to certain
>IP's only, say a range of IP. How can I restrict access to a directory in
>/tomcat/webappas/ROOT on the basis of IP ? I tried with valves, but not
>sure how to restrict the restriction only to particular directories.
>It will be of nice if you could provide a solution,
>Indian Institute of Science
>To unsubscribe, e-mail:
>For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message