org.apache.lenya.ac.impl
Class AbstractIPRange

java.lang.Object
  extended by org.apache.avalon.framework.logger.AbstractLogEnabled
      extended by org.apache.lenya.ac.impl.AbstractItem
          extended by org.apache.lenya.ac.impl.AbstractGroupable
              extended by org.apache.lenya.ac.impl.AbstractIPRange
All Implemented Interfaces:
java.lang.Comparable, org.apache.avalon.framework.logger.LogEnabled, org.apache.lenya.ac.Accreditable, org.apache.lenya.ac.Groupable, org.apache.lenya.ac.IPRange, org.apache.lenya.ac.Item
Direct Known Subclasses:
FileIPRange

public abstract class AbstractIPRange
extends AbstractGroupable
implements org.apache.lenya.ac.IPRange

A range of IP addresses, expressed by a network address and a subnet mask.

Note: this class does not enforce that the network address and the subnet mask have the same size (i.e. either both IPv4 or both IPv6 addresses). If the the network address and subnet mask have different sizes, the range does not contain any hosts, that is contains(Machine) will always return false.


Constructor Summary
AbstractIPRange(org.apache.lenya.ac.ItemManager itemManager, org.apache.avalon.framework.logger.Logger logger)
          Ctor.
AbstractIPRange(org.apache.lenya.ac.ItemManager itemManager, org.apache.avalon.framework.logger.Logger logger, java.lang.String id)
          Ctor.
 
Method Summary
 boolean contains(org.apache.lenya.ac.Machine machine)
          Checks if this IP range contains a certain machine.
 void delete()
          Delete an IP range
 java.io.File getConfigurationDirectory()
          Returns the configuration directory.
 java.net.InetAddress getNetworkAddress()
          Returns the network address.
 java.net.InetAddress getSubnetMask()
          Returns the subnet mask.
static boolean isValidSubnet(java.net.InetAddress networkAddress, java.net.InetAddress subnetMask)
          Deprecated. This method is currently not implemented, probably not necessary.and could be removed in the future. Therefore it should not be used.
abstract  void save()
          Save the IP range
protected  void setConfigurationDirectory(java.io.File _configurationDirectory)
           
 void setNetworkAddress(byte[] address)
          Sets the network address.
 void setNetworkAddress(java.lang.String address)
          Sets the network address.
 void setSubnetMask(byte[] mask)
          Sets the subnet mask.
 void setSubnetMask(java.lang.String mask)
          Sets the subnet mask.
 
Methods inherited from class org.apache.lenya.ac.impl.AbstractGroupable
addedToGroup, getAccreditables, getGroups, removedFromGroup, removeFromAllGroups
 
Methods inherited from class org.apache.lenya.ac.impl.AbstractItem
compareTo, equals, getAccreditableManager, getDescription, getId, getItemManager, getName, hashCode, setDescription, setId, setName, toString
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.lenya.ac.Accreditable
getAccreditables
 
Methods inherited from interface org.apache.lenya.ac.Item
configure, getDescription, getId, getItemManager, getName, setDescription, setName
 
Methods inherited from interface org.apache.avalon.framework.logger.LogEnabled
enableLogging
 
Methods inherited from interface org.apache.lenya.ac.Groupable
addedToGroup, getGroups, removedFromGroup, removeFromAllGroups
 

Constructor Detail

AbstractIPRange

public AbstractIPRange(org.apache.lenya.ac.ItemManager itemManager,
                       org.apache.avalon.framework.logger.Logger logger)
Ctor. Initializes the the IP range with the local host (127.0.0.1/24 for IPv4, ::1/128 for IPv6).

Parameters:
itemManager - The item manager.
logger - The logger.

AbstractIPRange

public AbstractIPRange(org.apache.lenya.ac.ItemManager itemManager,
                       org.apache.avalon.framework.logger.Logger logger,
                       java.lang.String id)
Ctor.

Parameters:
itemManager - The item manager.
logger - The logger.
id - The IP range ID.
Method Detail

getConfigurationDirectory

public java.io.File getConfigurationDirectory()
Returns the configuration directory.

Returns:
A file object.

setConfigurationDirectory

protected void setConfigurationDirectory(java.io.File _configurationDirectory)

save

public abstract void save()
                   throws org.apache.lenya.ac.AccessControlException
Save the IP range

Specified by:
save in interface org.apache.lenya.ac.IPRange
Throws:
org.apache.lenya.ac.AccessControlException - if the save failed

delete

public void delete()
            throws org.apache.lenya.ac.AccessControlException
Delete an IP range

Specified by:
delete in interface org.apache.lenya.ac.IPRange
Throws:
org.apache.lenya.ac.AccessControlException - if the delete failed

setNetworkAddress

public void setNetworkAddress(java.lang.String address)
                       throws org.apache.lenya.ac.AccessControlException
Sets the network address. This method accepts numeric IPv4 addresses like "129.168.0.32", numeric IPv6 addresses like "1080::8:800:200C:417A" as well as hostnames (if DNS resolution is available) like "localhost" or "www.apache.com".

Specified by:
setNetworkAddress in interface org.apache.lenya.ac.IPRange
Parameters:
address - a String like "192.168.0.32", "::1", ...
Throws:
org.apache.lenya.ac.AccessControlException - when the conversion of the String to an InetAddress failed
See Also:
setNetworkAddress(byte[])

setNetworkAddress

public void setNetworkAddress(byte[] address)
                       throws org.apache.lenya.ac.AccessControlException
Sets the network address. The method accepts numeric IPv4 addresses (specified by byte arrays of length 4) or IPv6 addresses (specified by byte arrays of length 16).

Specified by:
setNetworkAddress in interface org.apache.lenya.ac.IPRange
Parameters:
address - a byte array of the length 4 or 16
Throws:
org.apache.lenya.ac.AccessControlException - when the conversion of the byte array to an InetAddress failed.
See Also:
setNetworkAddress(String)

getNetworkAddress

public java.net.InetAddress getNetworkAddress()
Returns the network address.

Specified by:
getNetworkAddress in interface org.apache.lenya.ac.IPRange
Returns:
an InetAddress representing the network address

setSubnetMask

public void setSubnetMask(java.lang.String mask)
                   throws org.apache.lenya.ac.AccessControlException
Sets the subnet mask. See setNetworkAddress(String) for the allowed formats of the mask string. (However, the hostname format will usually not be of much use for setting the mask.)

Only valid subnet masks are accepted, for which the binary representation is a sequence of 1-bits followed by a sequence of 0-bits. For example "255.128.0.0" is valid while "255.128.0.1" is not.

Specified by:
setSubnetMask in interface org.apache.lenya.ac.IPRange
Parameters:
mask - a String like "255.255.255.0"
Throws:
org.apache.lenya.ac.AccessControlException - when the conversion of the String to an InetAddress failed.
See Also:
setSubnetMask(byte[])

setSubnetMask

public void setSubnetMask(byte[] mask)
                   throws org.apache.lenya.ac.AccessControlException
Sets the subnet mask.

Only valid subnet masks are accepted, for which the binary representation is a sequence of 1-bits followed by a sequence of 0-bits. For example { 255, 128, 0, 0 } is valid while { 255, 128, 0, 1 } is not.

Specified by:
setSubnetMask in interface org.apache.lenya.ac.IPRange
Parameters:
mask - A byte array of the length 4.
Throws:
org.apache.lenya.ac.AccessControlException - when the conversion of the byte array to an InetAddress failed.
See Also:
setSubnetMask(String)

getSubnetMask

public java.net.InetAddress getSubnetMask()
Returns the subnet mask.

Specified by:
getSubnetMask in interface org.apache.lenya.ac.IPRange
Returns:
An InetAddress value.

isValidSubnet

public static boolean isValidSubnet(java.net.InetAddress networkAddress,
                                    java.net.InetAddress subnetMask)
Deprecated. This method is currently not implemented, probably not necessary.and could be removed in the future. Therefore it should not be used.

Checks if a network address / subnet mask combination describes a valid subnet.

Parameters:
networkAddress - The network address.
subnetMask - The subnet mask.
Returns:
A boolean value.

contains

public boolean contains(org.apache.lenya.ac.Machine machine)
Checks if this IP range contains a certain machine.

Note: if the network address and the subnet mask of this IP range have different sizes (i.e. one is IPv4 and one is IPv6), this method will always return false, no matter what machine has been specified!

Further, if the machine address and the IP range (i.e. network address and subnet mask) have different sizes, the method will return false. (In other words: an IPv4 range never contains an IPv6 address and the other way round.)

Note that the above can lead to confusion. For example the local subnet in IPv4 ( 127.0.0.0/8) will not contain the localhost in IPv6 ( ::1), and the localhost in IPv4 (127.0.0.1) will not be contained in the local subnet in IPv6 (::1/128).

Specified by:
contains in interface org.apache.lenya.ac.IPRange
Parameters:
machine - the machine to check for
Returns:
a boolean value
See Also:
InetAddressUtil.contains(java.net.InetAddress, java.net.InetAddress, java.net.InetAddress)


Copyright $ Apache Software Foundation. All Rights Reserved.