|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.tinyradius.packet.RadiusPacket
public class RadiusPacket
This class represents a Radius packet. Subclasses provide convenience methods for special packet types.
Field Summary | |
---|---|
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 Summary | |
---|---|
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 attributes)
Builds a Radius packet with the given type, identifier and attributes. |
Method Summary | |
---|---|
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 |
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. |
protected byte[] |
createRequestAuthenticator(java.lang.String sharedSecret)
Creates a request authenticator for this packet. |
protected byte[] |
createResponseAuthenticator(java.lang.String sharedSecret,
int packetLength,
byte[] attributes,
byte[] requestAuthenticator)
Creates an authenticator for a Radius response 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 appropiate RadiusPacket descendant object. |
protected void |
decodeRequestAttributes(java.lang.String sharedSecret)
Can be overriden to decode encoded request 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 appropiate 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 appropiate RadiusPacket descendant object. |
static RadiusPacket |
decodeResponsePacket(Dictionary dictionary,
java.io.InputStream in,
java.lang.String sharedSecret,
RadiusPacket request)
Reads a Radius response packet from the given input stream and creates an appropiate RadiusPacket descendant object. |
static RadiusPacket |
decodeResponsePacket(java.io.InputStream in,
java.lang.String sharedSecret,
RadiusPacket request)
Reads a Radius response packet from the given input stream and creates an appropiate 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 response 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 |
getAttributes()
Returns a list of all attributes belonging to this Radius packet. |
java.util.List |
getAttributes(int attributeType)
Returns all attributes of this packet of the given type. |
java.util.List |
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()
Returns the dictionary this Radius packet uses. |
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 |
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 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 request authenticator as specified by RFC 2866. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
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
Constructor Detail |
---|
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 attributes)
type
- packet typeidentifier
- packet identifierattributes
- list of RadiusAttribute objectspublic RadiusPacket()
Method Detail |
---|
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 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 getAttributes(int attributeType)
attributeType
- type of attributes to get
public java.util.List getAttributes(int vendorId, int attributeType)
vendorId
- vendor IDattributeType
- attribute type code
public java.util.List getAttributes()
public RadiusAttribute getAttribute(int type)
type
- attribute type
java.lang.RuntimeException
- if there are multiple occurences of the
requested attribute typepublic RadiusAttribute getAttribute(int vendorId, int type)
vendorId
- vendor IDtype
- attribute type
java.lang.RuntimeException
- if there are multiple occurences of the
requested attribute typepublic RadiusAttribute getAttribute(java.lang.String type)
type
- attribute type name
java.lang.RuntimeException
- if the attribute occurs multiple timespublic java.lang.String getAttributeValue(java.lang.String type)
type
- attribute type name
java.lang.IllegalArgumentException
- if the type name is unknown
java.lang.RuntimeException
- attribute occurs multiple timespublic java.util.List getVendorAttributes(int vendorId)
vendorId
- vendor ID of the attribute(s)
public VendorSpecificAttribute getVendorAttribute(int vendorId)
vendorId
- vendor ID of the attribute
getVendorAttributes(int)
public void encodeRequestPacket(java.io.OutputStream out, java.lang.String sharedSecret) throws java.io.IOException
out
- output stream to usesharedSecret
- shared secret to be used to encode this packet
java.io.IOException
- communication errorpublic void encodeResponsePacket(java.io.OutputStream out, java.lang.String sharedSecret, RadiusPacket request) throws java.io.IOException
out
- output stream to usesharedSecret
- shared secret to be used to encode this packetrequest
- Radius request packet
java.io.IOException
- communication errorpublic static RadiusPacket decodeRequestPacket(java.io.InputStream in, java.lang.String sharedSecret) throws java.io.IOException, RadiusException
sharedSecret
- shared secret to be used to decode this packet
java.io.IOException
- IO error
RadiusException
- malformed packetpublic static RadiusPacket decodeResponsePacket(java.io.InputStream in, java.lang.String sharedSecret, RadiusPacket request) throws java.io.IOException, RadiusException
sharedSecret
- shared secret to be used to decode this packetrequest
- Radius request packet
java.io.IOException
- IO error
RadiusException
- 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 packet
java.io.IOException
- IO error
RadiusException
- 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 packet
java.io.IOException
- IO error
RadiusException
- malformed packetpublic static int getNextPacketIdentifier()
public static RadiusPacket createRadiusPacket(int type)
type
- packet type
public 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
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 request packet
java.io.IOException
- communication error
java.lang.RuntimeException
- if required packet data has not been setprotected void encodeRequestAttributes(java.lang.String sharedSecret)
sharedSecret
- protected byte[] createRequestAuthenticator(java.lang.String sharedSecret)
sharedSecret
- shared secret that secures the communication
with the other Radius server/client
protected byte[] updateRequestAuthenticator(java.lang.String sharedSecret, int packetLength, byte[] attributes)
sharedSecret
- shared secretpacketLength
- length of the final Radius packetattributes
- attribute data
protected byte[] createResponseAuthenticator(java.lang.String sharedSecret, int packetLength, byte[] attributes, byte[] requestAuthenticator)
sharedSecret
- shared secretpacketLength
- length of response packetattributes
- encoded attributes of response packetrequestAuthenticator
- request packet authenticator
protected 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 attributessharedSecret
- 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 decoded
java.io.IOException
- if an IO error occurred
RadiusException
- if the Radius packet is malformedprotected void decodeRequestAttributes(java.lang.String sharedSecret) throws RadiusException
sharedSecret
-
RadiusException
protected 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 response packetattributes
- attribute data of the response packetrequestAuthenticator
- 16 bytes authenticator of the request packet belonging
to this response packet
RadiusException
protected java.security.MessageDigest getMd5Digest()
protected byte[] getAttributeBytes() throws java.io.IOException
java.io.IOException
- error writing data
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |