org.xins.server
Class IPFilter

java.lang.Object
  extended byorg.xins.server.IPFilter

public final class IPFilter
extends Object

Filter for IP addresses.

Filter expression format

An IPFilter instance is created using a so-called filter expression. This filter expression specifies the IP address and mask to use for matching a subject IP address.

A filter expression must match the following format:

"a.a.a.a", optionally followed by: /n, where a is a number between 0 and 255, with no leading zeroes, and n is a number between 0 and 32, no leading zeroes; if n is not specified.

Example code

An IPFilter object is created and used as follows:

IPFilter filter = IPFilter.parseFilter("10.0.0.0/24");
if (filter.match("10.0.0.1")) {
   // IP is granted access
} else {
   // IP is denied access
}

Since:
XINS 1.0.0
Version:
$Revision: 1.36 $ $Date: 2006/10/05 15:35:29 $
Author:
Ernst de Haan, Peter Troon

Method Summary
 String getBaseIP()
          Returns the base IP address.
 String getExpression()
          Returns the filter expression.
 int getMask()
          Returns the mask.
 boolean match(String ipString)
          Determines if the specified IP address is authorized.
static IPFilter parseIPFilter(String expression)
          Creates an IPFilter object for the specified filter expression.
 String toString()
          Returns a textual representation of this filter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

parseIPFilter

public static final IPFilter parseIPFilter(String expression)
                                    throws IllegalArgumentException,
                                           ParseException
Creates an IPFilter object for the specified filter expression. The expression consists of a base IP address and a bit count. The bit count indicates how many bits in an IP address must match the bits in the base IP address.

Parameters:
expression - the filter expression, cannot be null and must match the format for a filter expression. then 32 is assumed.
Returns:
the constructed IPFilter object, never null.
Throws:
IllegalArgumentException - if expression == null.
ParseException - if expression does not match the specified format.

getExpression

public final String getExpression()
Returns the filter expression.

Returns:
the original filter expression, never null.

getBaseIP

public final String getBaseIP()
Returns the base IP address.

Returns:
the base IP address, in the form a.a.a.a/n, where a is a number between 0 and 255, with no leading zeroes; never null.

getMask

public final int getMask()
Returns the mask.

Returns:
the mask, between 0 and 32.

match

public final boolean match(String ipString)
                    throws IllegalArgumentException,
                           ParseException
Determines if the specified IP address is authorized.

Parameters:
ipString - the IP address of which must be determined if it is authorized, cannot be null and must match the form: a.a.a.a/n, where a is a number between 0 and 255, with no leading zeroes.
Returns:
true if the IP address is authorized to access the protected resource, otherwise false.
Throws:
IllegalArgumentException - if ipString == null.
ParseException - if ip does not match the specified format.

toString

public final String toString()
Returns a textual representation of this filter. The implementation of this method returns the filter expression passed.

Returns:
a textual presentation, never null.


See http://www.xins.org/.