This host filter ver. 1.2

This is a Java servlet filter (as per Servlet API 2.3). This filter proceeds (enables) requests from the directly provided hosts (detected by IP addresses) only. Additionally filter proceeds (enables) requests from the localhost. Any another request will be terminated with 403 HTTP status code.

How to use it:

a) download thishostflt.jar and save it in WEB-INF/lib

b) describe this filter in web.xml. There is one optional initial parameter host. This parameter describes a comma separated list of IP's for allowed hosts. By default (without this parameter) filter enables requests from the localhost (127.0.0.1) only.
 


<filter>
  <filter-name>ThisHostFilter</filter-name>
  <filter-class>com.cj.ip.ThisHostFilter</filter-class>
  <init-param>
    <param-name>host</param-name>
    <param-value>list_of_IP's</param-value>
  </init-param>
</filter>

c) describe a mapping for this filter in web.xml. E.g.:
 


<filter-mapping>
  <filter-name>ThisHostFilter</filter-name>
  <url-pattern>*.jpg</url-pattern>
</filter-mapping>

Also you may exclude some of your files from the processing. Parameter exclude contains regular expresion to match excluded urls. By default is empty (include all).

The typical use cases for this filter are:

- direct access restriction
- prevent bandwidth theft or "hotlinking" as a direct linking to your web site's files (images, video, etc.). An example would be using an <img> tag to display a JPEG image from your site on someone else's web page etc.

   For downloading:

    ThisHost package:  thishostflt.jar
 

 ©  Coldbeans     Comments?

See also JSOS - the largest collection of servlets and filters.
 


     

Also in Coldtags: