net.sourceforge.jradiusclient
Class RadiusPacket

java.lang.Object
  |
  +--net.sourceforge.jradiusclient.RadiusPacket
Direct Known Subclasses:
AccountingRequest, ChapAccessRequest, PapAccessRequest

public class RadiusPacket
extends java.lang.Object

Released under the LGPL

Version:
$Revision: 1.11 $
Author:
Robert J. Loihl

Field Summary
static int ACCESS_ACCEPT
           
static int ACCESS_CHALLENGE
           
static int ACCESS_REJECT
           
static int ACCESS_REQUEST
           
static int ACCOUNTING_MESSAGE
           
static int ACCOUNTING_REQUEST
           
static int ACCOUNTING_RESPONSE
           
static int ACCOUNTING_STATUS
           
static java.lang.String EMPTYSTRING
           
static int MAX_PACKET_LENGTH
           
static int MIN_PACKET_LENGTH
           
static int PASSWORD_ACCEPT
           
static int PASSWORD_REJECT
           
static int PASSWORD_REQUEST
           
static short RADIUS_HEADER_LENGTH
          RADIUS_HEADER_LENGTH is 20 bytes (corresponding to 1 byte for code + 1 byte for Identifier + 2 bytes for Length + 16 bytes for Request Authenticator) It is not a coincidence that it is the same as the MIN_PACKET_LENGTH
static int RESERVED
           
static int STATUS_CLIENT
           
static int STATUS_SERVER
           
 
Constructor Summary
RadiusPacket(int type)
          builds a type RadiusPacket with no Attributes set
RadiusPacket(int type, byte identifier)
           
RadiusPacket(int type, byte identifier, java.util.List attributeList)
          Builds a RadiusPacket with a predefined set of attributes
RadiusPacket(int type, java.util.List attributeList)
          Builds a RadiusPacket with a predefined set of attributes
 
Method Summary
 RadiusAttribute getAttribute(int attributeType)
          retrieve a RadiusAttribute from this RadiusPacket
protected  byte[] getAttributeBytes()
          get the byte array
 java.util.Collection getAttributes()
          get all of the RadiusAttributes in this RadiusPacket
 byte getPacketIdentifier()
          Return the packetIdentifier for this RadiusPacket.
 byte getPacketType()
          get the packet type for this RadiusPacket
 void setAttribute(RadiusAttribute radiusAttribute)
          Adds a RadiusAttribute to this RadiusPacket
 void setAttributes(java.util.List attributeList)
          Add a set of RadiusAttributes to this RadiusPacket
protected  void validateAttribute(RadiusAttribute attribute)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MIN_PACKET_LENGTH

public static final int MIN_PACKET_LENGTH
See Also:
Constant Field Values

MAX_PACKET_LENGTH

public static final int MAX_PACKET_LENGTH
See Also:
Constant Field Values

RADIUS_HEADER_LENGTH

public static final short RADIUS_HEADER_LENGTH
RADIUS_HEADER_LENGTH is 20 bytes (corresponding to 1 byte for code + 1 byte for Identifier + 2 bytes for Length + 16 bytes for Request Authenticator) It is not a coincidence that it is the same as the MIN_PACKET_LENGTH

See Also:
Constant Field Values

EMPTYSTRING

public static final java.lang.String EMPTYSTRING
See Also:
Constant Field Values

ACCESS_REQUEST

public static final int ACCESS_REQUEST
See Also:
Constant Field Values

ACCESS_ACCEPT

public static final int ACCESS_ACCEPT
See Also:
Constant Field Values

ACCESS_REJECT

public static final int ACCESS_REJECT
See Also:
Constant Field Values

ACCOUNTING_REQUEST

public static final int ACCOUNTING_REQUEST
See Also:
Constant Field Values

ACCOUNTING_RESPONSE

public static final int ACCOUNTING_RESPONSE
See Also:
Constant Field Values

ACCOUNTING_STATUS

public static final int ACCOUNTING_STATUS
See Also:
Constant Field Values

PASSWORD_REQUEST

public static final int PASSWORD_REQUEST
See Also:
Constant Field Values

PASSWORD_ACCEPT

public static final int PASSWORD_ACCEPT
See Also:
Constant Field Values

PASSWORD_REJECT

public static final int PASSWORD_REJECT
See Also:
Constant Field Values

ACCOUNTING_MESSAGE

public static final int ACCOUNTING_MESSAGE
See Also:
Constant Field Values

ACCESS_CHALLENGE

public static final int ACCESS_CHALLENGE
See Also:
Constant Field Values

STATUS_SERVER

public static final int STATUS_SERVER
See Also:
Constant Field Values

STATUS_CLIENT

public static final int STATUS_CLIENT
See Also:
Constant Field Values

RESERVED

public static final int RESERVED
See Also:
Constant Field Values
Constructor Detail

RadiusPacket

public RadiusPacket(int type)
             throws InvalidParameterException
builds a type RadiusPacket with no Attributes set

Parameters:
type - int a PacketType to send.
Throws:
InvalidParameterException - if the attributeList is null or contains non-RadiusAttribute type entries

RadiusPacket

public RadiusPacket(int type,
                    byte identifier)
             throws InvalidParameterException
Parameters:
type -
identifier -
Throws:
InvalidParameterException

RadiusPacket

public RadiusPacket(int type,
                    java.util.List attributeList)
             throws InvalidParameterException
Builds a RadiusPacket with a predefined set of attributes

Parameters:
type - int a PacketType to send.
attributeList - a list of RadiusAttribute objects to initialize this RadiusPacket with
Throws:
InvalidParameterException - if the attributeList is null or contains non-RadiusAttribute type entries

RadiusPacket

public RadiusPacket(int type,
                    byte identifier,
                    java.util.List attributeList)
             throws InvalidParameterException
Builds a RadiusPacket with a predefined set of attributes

Parameters:
type -
identifier -
attributeList -
Throws:
InvalidParameterException
Method Detail

setAttribute

public void setAttribute(RadiusAttribute radiusAttribute)
                  throws InvalidParameterException
Adds a RadiusAttribute to this RadiusPacket

Parameters:
radiusAttribute - A RadiusAttribute to set on this RadiusPacket
Throws:
InvalidParameterException - if the parameter radiusAttribute was null

setAttributes

public void setAttributes(java.util.List attributeList)
                   throws InvalidParameterException
Add a set of RadiusAttributes to this RadiusPacket

Parameters:
attributeList - a list of RadiusAttribute objects to add to this RadiusPacket
Throws:
InvalidParameterException - if the attributeList is null or contains non-RadiusAttribute type entries

validateAttribute

protected void validateAttribute(RadiusAttribute attribute)
                          throws InvalidParameterException
InvalidParameterException

getAttribute

public RadiusAttribute getAttribute(int attributeType)
                             throws InvalidParameterException,
                                    RadiusException
retrieve a RadiusAttribute from this RadiusPacket

Parameters:
attributeType - an integer between 0 and 256 (i.e. a byte) from the list of Radius constants in net.sourceforge.jradiusclient.RadiusValues
Returns:
a single RadiusAttribute from the RadiusPacket
Throws:
RadiusException - if no attribute of type attributeType is stored in this RadiusPacket
InvalidParameterException - if the attributeType is not between 0 and 256 (i.e. a byte)

getAttributes

public java.util.Collection getAttributes()
get all of the RadiusAttributes in this RadiusPacket

Returns:
a java.util.Collection of RadiusAttributes

getPacketType

public byte getPacketType()
get the packet type for this RadiusPacket

Returns:
packet type for this RadiusPacket

getPacketIdentifier

public byte getPacketIdentifier()
Return the packetIdentifier for this RadiusPacket. This can be used to match request packets to response packets

Returns:
the packet identifier for this object.

getAttributeBytes

protected final byte[] getAttributeBytes()
                                  throws RadiusException
get the byte array

Returns:
a byte array of the raw bytes for all of the RadiusAttributes assigned to this RadiusPacket
Throws:
RadiusException - If there is any error assembling the bytes into a byte array