0

Is there a way to restrict/allow access to a specific file on Tomcat only to certain IPs? If there is no direct way to do this, what would be a good workaround?

I'd really appreciate your help.

user3782265
  • 1
  • 1
  • 1
  • This answer might help: http://stackoverflow.com/questions/579224/setting-catalina-policy-to-allow-file-access-by-servlets – Mandar Pandit Jun 27 '14 at 08:17

3 Answers3

0

Use a filter and get the ip from the request. However in case the request comes from behind a firewall, you'll get the firewall's ip.

Andres
  • 10,561
  • 4
  • 45
  • 63
0

There is a way to do so with Tomcat ;)

Code:

<Context path="/here is youre path to the files">
      <Valve className="org.apache.catalina.valves.RemoteAddrValve"
             allow="here u put the IP addresses you want to allow" deny="here u put the IP addresses you want to deny"/>
    </Context>

I highly recommend you to read the Tomcat Tips which have been published by O´reilly. Can be found here.

Number 10 on there Site is about your Question

EDIT: This has to be pasted to your Server.xml

EDIT1: OTHER Way can be found here Tomcat Valve settings

Community
  • 1
  • 1
CodeFanatic
  • 11,434
  • 1
  • 20
  • 38
0

There are various ways to do it, depending on exactly what you want to do. For example:

Or if you wanted something fine-grained (e.g. pattern matching on the path part of the request URL) then you could implement your own Filter class.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216