public class RadiusPacket
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static int |
ACCESS_ACCEPT |
static int |
ACCESS_CHALLENGE |
static int |
ACCESS_REJECT |
static int |
ACCESS_REQUEST
Packet type codes.
|
static int |
ACCOUNTING_MESSAGE |
static int |
ACCOUNTING_REQUEST |
static int |
ACCOUNTING_RESPONSE |
static int |
ACCOUNTING_STATUS |
static int |
COA_ACK |
static int |
COA_NAK |
static int |
COA_REQUEST |
static int |
DISCONNECT_ACK |
static int |
DISCONNECT_NAK |
static int |
DISCONNECT_REQUEST |
static int |
MAX_PACKET_LENGTH
Maximum packet length.
|
static int |
PASSWORD_ACCEPT |
static int |
PASSWORD_REJECT |
static int |
PASSWORD_REQUEST |
static int |
RADIUS_HEADER_LENGTH
Packet header length.
|
static int |
RESERVED |
static int |
STATUS_ACCEPT |
static int |
STATUS_CLIENT |
static int |
STATUS_REJECT |
static int |
STATUS_REQUEST |
static int |
STATUS_SERVER |
Constructor and Description |
---|
RadiusPacket()
Builds an empty Radius packet.
|
RadiusPacket(int type)
Builds a Radius packet without attributes.
|
RadiusPacket(int type,
int identifier)
Builds a Radius packet with the given type and identifier
and without attributes.
|
RadiusPacket(int type,
int identifier,
java.util.List<RadiusAttribute> attributes)
Builds a Radius packet with the given type, identifier and
attributes.
|
Modifier and Type | Method and Description |
---|---|
void |
addAttribute(RadiusAttribute attribute)
Adds a Radius attribute to this packet.
|
void |
addAttribute(java.lang.String typeName,
java.lang.String value)
Adds a Radius attribute to this packet.
|
protected void |
checkRequestAuthenticator(java.lang.String sharedSecret,
int packetLength,
byte[] attributes)
Checks the clientRequest authenticator against the supplied shared secret.
|
protected void |
checkResponseAuthenticator(java.lang.String sharedSecret,
int packetLength,
byte[] attributes,
byte[] requestAuthenticator)
This method checks the authenticator of this Radius packet.
|
static RadiusPacket |
createRadiusPacket(int type)
Creates a RadiusPacket object.
|
static RadiusPacket |
createRadiusPacket(int type,
Dictionary dictionary)
Creates a RadiusPacket object.
|
protected byte[] |
createRequestAuthenticator(java.lang.String sharedSecret)
Creates a clientRequest authenticator for this packet.
|
protected byte[] |
createResponseAuthenticator(java.lang.String sharedSecret,
int packetLength,
byte[] attributes,
byte[] requestAuthenticator)
Creates an authenticator for a Radius clientResponse packet.
|
protected static RadiusPacket |
decodePacket(Dictionary dictionary,
java.io.InputStream in,
java.lang.String sharedSecret,
RadiusPacket request)
Reads a Radius packet from the given input stream and
creates an appropriate RadiusPacket descendant object.
|
protected void |
decodeRequestAttributes(java.lang.String sharedSecret)
Can be overriden to decode encoded clientRequest attributes such as
User-Password.
|
static RadiusPacket |
decodeRequestPacket(Dictionary dictionary,
java.io.InputStream in,
java.lang.String sharedSecret)
Reads a Radius request packet from the given input stream and
creates an appropriate RadiusPacket descendant object.
|
static RadiusPacket |
decodeRequestPacket(java.io.InputStream in,
java.lang.String sharedSecret)
Reads a Radius request packet from the given input stream and
creates an appropriate RadiusPacket descendant object.
|
static RadiusPacket |
decodeResponsePacket(Dictionary dictionary,
java.io.InputStream in,
java.lang.String sharedSecret,
RadiusPacket request)
Reads a Radius clientResponse packet from the given input stream and
creates an appropriate RadiusPacket descendant object.
|
static RadiusPacket |
decodeResponsePacket(java.io.InputStream in,
java.lang.String sharedSecret,
RadiusPacket request)
Reads a Radius clientResponse packet from the given input stream and
creates an appropriate RadiusPacket descendant object.
|
protected void |
encodePacket(java.io.OutputStream out,
java.lang.String sharedSecret,
RadiusPacket request)
Encodes this Radius packet and sends it to the specified output
stream.
|
protected void |
encodeRequestAttributes(java.lang.String sharedSecret)
This method exists for subclasses to be overridden in order to
encode packet attributes like the User-Password attribute.
|
void |
encodeRequestPacket(java.io.OutputStream out,
java.lang.String sharedSecret)
Encodes this Radius packet and sends it to the specified output stream.
|
void |
encodeResponsePacket(java.io.OutputStream out,
java.lang.String sharedSecret,
RadiusPacket request)
Encodes this Radius clientResponse packet and sends it to the specified output
stream.
|
RadiusAttribute |
getAttribute(int type)
Returns a Radius attribute of the given type which may only occur once
in the Radius packet.
|
RadiusAttribute |
getAttribute(int vendorId,
int type)
Returns a Radius attribute of the given type and vendor ID
which may only occur once in the Radius packet.
|
RadiusAttribute |
getAttribute(java.lang.String type)
Returns a single Radius attribute of the given type name.
|
protected byte[] |
getAttributeBytes()
Encodes the attributes of this Radius packet to a byte array.
|
java.util.List<RadiusAttribute> |
getAttributes()
Returns a list of all attributes belonging to this Radius
packet.
|
java.util.List<RadiusAttribute> |
getAttributes(int attributeType)
Returns all attributes of this packet of the given type.
|
java.util.List<RadiusAttribute> |
getAttributes(int vendorId,
int attributeType)
Returns all attributes of this packet that have got the
given type and belong to the given vendor ID.
|
java.lang.String |
getAttributeValue(java.lang.String type)
Returns the value of the Radius attribute of the given type or
null if there is no such attribute.
|
byte[] |
getAuthenticator()
Returns the authenticator for this Radius packet.
|
Dictionary |
getDictionary() |
protected java.security.MessageDigest |
getMd5Digest()
Returns a MD5 digest.
|
static int |
getNextPacketIdentifier()
Retrieves the next packet identifier to use and increments the static
storage.
|
int |
getPacketIdentifier()
Returns the packet identifier for this Radius packet.
|
int |
getPacketType()
Returns the type of this Radius packet.
|
java.lang.String |
getPacketTypeName()
Returns the type name of this Radius packet.
|
VendorSpecificAttribute |
getVendorAttribute(int vendorId)
Deprecated.
use getVendorAttributes(int)
|
java.util.List<VendorSpecificAttribute> |
getVendorAttributes(int vendorId)
Returns the Vendor-Specific attribute(s) for the given vendor ID.
|
void |
removeAttribute(RadiusAttribute attribute)
Removes the specified attribute from this packet.
|
void |
removeAttributes(int type)
Removes all attributes from this packet which have got
the specified type.
|
void |
removeAttributes(int vendorId,
int typeCode)
Removes all sub-attributes of the given vendor and
type.
|
void |
removeLastAttribute(int type)
Removes the last occurence of the attribute of the given
type from the packet.
|
void |
setAttributes(java.util.List<RadiusAttribute> attributes)
Sets the list of attributes for this Radius packet.
|
void |
setAuthenticator(byte[] authenticator)
Sets the authenticator to be used for this Radius packet.
|
void |
setDictionary(Dictionary dictionary)
Sets a custom dictionary to use.
|
void |
setPacketIdentifier(int identifier)
Sets the packet identifier for this Radius packet.
|
void |
setPacketType(int type)
Sets the type of this Radius packet.
|
java.lang.String |
toString()
String representation of this packet, for debugging purposes.
|
protected byte[] |
updateRequestAuthenticator(java.lang.String sharedSecret,
int packetLength,
byte[] attributes)
AccountingRequest overrides this
method to create a clientRequest authenticator as specified by RFC 2866.
|
public static final int ACCESS_REQUEST
public static final int ACCESS_ACCEPT
public static final int ACCESS_REJECT
public static final int ACCOUNTING_REQUEST
public static final int ACCOUNTING_RESPONSE
public static final int ACCOUNTING_STATUS
public static final int PASSWORD_REQUEST
public static final int PASSWORD_ACCEPT
public static final int PASSWORD_REJECT
public static final int ACCOUNTING_MESSAGE
public static final int ACCESS_CHALLENGE
public static final int STATUS_SERVER
public static final int STATUS_CLIENT
public static final int DISCONNECT_REQUEST
public static final int DISCONNECT_ACK
public static final int DISCONNECT_NAK
public static final int COA_REQUEST
public static final int COA_ACK
public static final int COA_NAK
public static final int STATUS_REQUEST
public static final int STATUS_ACCEPT
public static final int STATUS_REJECT
public static final int RESERVED
public static final int MAX_PACKET_LENGTH
public static final int RADIUS_HEADER_LENGTH
public RadiusPacket(int type)
type
- packet typepublic RadiusPacket(int type, int identifier)
type
- packet typeidentifier
- packet identifierpublic RadiusPacket(int type, int identifier, java.util.List<RadiusAttribute> attributes)
type
- packet typeidentifier
- packet identifierattributes
- list of RadiusAttribute objectspublic RadiusPacket()
public int getPacketIdentifier()
public void setPacketIdentifier(int identifier)
identifier
- packet identifier, 0-255public int getPacketType()
public java.lang.String getPacketTypeName()
public void setPacketType(int type)
type
- packet type, 0-255public void setAttributes(java.util.List<RadiusAttribute> attributes)
attributes
- list of RadiusAttribute objectspublic void addAttribute(RadiusAttribute attribute)
attribute
- RadiusAttribute objectpublic void addAttribute(java.lang.String typeName, java.lang.String value)
typeName
- name of the attribute, for example "NAS-Ip-Address"value
- value of the attribute, for example "127.0.0.1"java.lang.IllegalArgumentException
- if type name is unknownpublic void removeAttribute(RadiusAttribute attribute)
attribute
- RadiusAttribute to removepublic void removeAttributes(int type)
type
- attribute type to removepublic void removeLastAttribute(int type)
type
- attribute type codepublic void removeAttributes(int vendorId, int typeCode)
vendorId
- vendor IDtypeCode
- attribute type codepublic java.util.List<RadiusAttribute> getAttributes(int attributeType)
attributeType
- type of attributes to getpublic java.util.List<RadiusAttribute> getAttributes(int vendorId, int attributeType)
vendorId
- vendor IDattributeType
- attribute type codepublic java.util.List<RadiusAttribute> getAttributes()
public RadiusAttribute getAttribute(int type)
type
- attribute typejava.lang.RuntimeException
- if there are multiple occurences of the
requested attribute typepublic RadiusAttribute getAttribute(int vendorId, int type)
vendorId
- vendor IDtype
- attribute typejava.lang.RuntimeException
- if there are multiple occurences of the
requested attribute typepublic RadiusAttribute getAttribute(java.lang.String type)
type
- attribute type namejava.lang.RuntimeException
- if the attribute occurs multiple timespublic java.lang.String getAttributeValue(java.lang.String type)
type
- attribute type namejava.lang.IllegalArgumentException
- if the type name is unknownjava.lang.RuntimeException
- attribute occurs multiple timespublic java.util.List<VendorSpecificAttribute> getVendorAttributes(int vendorId)
vendorId
- vendor ID of the attribute(s)public VendorSpecificAttribute getVendorAttribute(int vendorId)
vendorId
- vendor ID of the attributegetVendorAttributes(int)
public void encodeRequestPacket(java.io.OutputStream out, java.lang.String sharedSecret) throws java.io.IOException, RadiusException
out
- output stream to usesharedSecret
- shared secret to be used to encode this packetjava.io.IOException
- communication errorRadiusException
- malformed packetpublic void encodeResponsePacket(java.io.OutputStream out, java.lang.String sharedSecret, RadiusPacket request) throws java.io.IOException, RadiusException
out
- output stream to usesharedSecret
- shared secret to be used to encode this packetrequest
- Radius request packetjava.io.IOException
- communication errorRadiusException
- malformed packetpublic static RadiusPacket decodeRequestPacket(java.io.InputStream in, java.lang.String sharedSecret) throws java.io.IOException, RadiusException
in
- input stream to read fromsharedSecret
- shared secret to be used to decode this packetjava.io.IOException
- IO errorRadiusException
- malformed packetpublic static RadiusPacket decodeResponsePacket(java.io.InputStream in, java.lang.String sharedSecret, RadiusPacket request) throws java.io.IOException, RadiusException
in
- input stream to read fromsharedSecret
- shared secret to be used to decode this packetrequest
- Radius request packetjava.io.IOException
- IO errorRadiusException
- malformed packetpublic static RadiusPacket decodeRequestPacket(Dictionary dictionary, java.io.InputStream in, java.lang.String sharedSecret) throws java.io.IOException, RadiusException
dictionary
- dictionary to use for attributesin
- InputStream to read packet fromsharedSecret
- shared secret to be used to decode this packetjava.io.IOException
- IO errorRadiusException
- malformed packetpublic static RadiusPacket decodeResponsePacket(Dictionary dictionary, java.io.InputStream in, java.lang.String sharedSecret, RadiusPacket request) throws java.io.IOException, RadiusException
dictionary
- dictionary to use for attributesin
- InputStream to read packet fromsharedSecret
- shared secret to be used to decode this packetrequest
- Radius request packetjava.io.IOException
- IO errorRadiusException
- malformed packetpublic static int getNextPacketIdentifier()
public static RadiusPacket createRadiusPacket(int type, Dictionary dictionary)
type
- packet typedictionary
- to use for packetpublic static RadiusPacket createRadiusPacket(int type)
type
- packet typepublic java.lang.String toString()
toString
in class java.lang.Object
Object.toString()
public byte[] getAuthenticator()
public void setAuthenticator(byte[] authenticator)
authenticator
- authenticatorpublic Dictionary getDictionary()
public void setDictionary(Dictionary dictionary)
dictionary
- Dictionary class to useDefaultDictionary
protected void encodePacket(java.io.OutputStream out, java.lang.String sharedSecret, RadiusPacket request) throws java.io.IOException, RadiusException
out
- output stream to usesharedSecret
- shared secret to be used to encode this packetrequest
- Radius request packet if this packet to be encoded
is a response packet, null if this packet is a clientRequest packetjava.io.IOException
- communication errorjava.lang.IllegalArgumentException
- if required packet data has not been setRadiusException
- malformed packetprotected void encodeRequestAttributes(java.lang.String sharedSecret) throws RadiusException
sharedSecret
- used for encodingRadiusException
- malformed packetprotected byte[] createRequestAuthenticator(java.lang.String sharedSecret)
sharedSecret
- shared secret that secures the communication
with the other Radius server/clientprotected byte[] updateRequestAuthenticator(java.lang.String sharedSecret, int packetLength, byte[] attributes)
sharedSecret
- shared secretpacketLength
- length of the final Radius packetattributes
- attribute dataprotected byte[] createResponseAuthenticator(java.lang.String sharedSecret, int packetLength, byte[] attributes, byte[] requestAuthenticator)
sharedSecret
- shared secretpacketLength
- length of clientResponse packetattributes
- encoded attributes of clientResponse packetrequestAuthenticator
- clientRequest packet authenticatorprotected static RadiusPacket decodePacket(Dictionary dictionary, java.io.InputStream in, java.lang.String sharedSecret, RadiusPacket request) throws java.io.IOException, RadiusException
dictionary
- dictionary to use for attributesin
- inputStream to read fromsharedSecret
- shared secret to be used to decode this packetrequest
- Radius request packet if this is a response packet to be
decoded, null if this is a request packet to be decodedjava.io.IOException
- IO errorRadiusException
- packet malformedprotected void checkRequestAuthenticator(java.lang.String sharedSecret, int packetLength, byte[] attributes) throws RadiusException
sharedSecret
- shared secretpacketLength
- total length of the packetattributes
- clientRequest attribute dataRadiusException
- malformed packetprotected void decodeRequestAttributes(java.lang.String sharedSecret) throws RadiusException
sharedSecret
- used for decodingRadiusException
- malformed packetprotected void checkResponseAuthenticator(java.lang.String sharedSecret, int packetLength, byte[] attributes, byte[] requestAuthenticator) throws RadiusException
sharedSecret
- shared secret to be used to encrypt the authenticatorpacketLength
- length of the clientResponse packetattributes
- attribute data of the clientResponse packetrequestAuthenticator
- 16 bytes authenticator of the clientRequest packet belonging
to this clientResponse packetRadiusException
- malformed packetprotected java.security.MessageDigest getMd5Digest()
protected byte[] getAttributeBytes() throws java.io.IOException
java.io.IOException
- error writing data