Class IPMatcher

java.lang.Object
org.dspace.authenticate.IPMatcher

public class IPMatcher extends Object

Quickly tests whether a given IP address matches an IP range. An IPMatcher is initialized with a particular IP range specification. Calls to match method will then quickly determine whether a given IP falls within that range.

Supported range specifications are:

  • Full IPv4 address, e.g. 12.34.56.78
  • Full IPv6 address, e.g. 2001:18e8:3:171:218:8bff:fe2a:56a4
  • Partial IPv4 address, e.g. 12.34 (which matches any IP starting 12.34)
  • IPv4 network/netmask, e.g. 18.25.0.0/255.255.0.0
  • IPv4 or IPv6 CIDR slash notation, e.g. 18.25.0.0/16, 2001:18e8:3:171::/64
Version:
$Revision$
Author:
Robert Tansley, Ben Bosman, Roeland Dillen
  • Constructor Summary

    Constructors
    Constructor
    Description
    IPMatcher(String ipSpec)
    Construct an IPMatcher that will test for the given IP specification
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    match(String ipIn)
    Determine whether the given full IP falls within the range this IPMatcher was initialized with.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • IPMatcher

      public IPMatcher(String ipSpec) throws IPMatcherException
      Construct an IPMatcher that will test for the given IP specification
      Parameters:
      ipSpec - IP specification (full or partial address, network/netmask, network/cidr)
      Throws:
      IPMatcherException - if there is an error parsing the specification (i.e. it is somehow malformed)
  • Method Details

    • match

      public boolean match(String ipIn) throws IPMatcherException
      Determine whether the given full IP falls within the range this IPMatcher was initialized with.
      Parameters:
      ipIn - IP address as dot-delimited String
      Returns:
      true if the IP matches the range of this IPMatcher; false otherwise
      Throws:
      IPMatcherException - if the IP passed in cannot be parsed correctly (i.e. is malformed)