public class RadiusPacket extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
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 |
| 构造器和说明 |
|---|
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,
List attributes)
Builds a Radius packet with the given type, identifier and
attributes.
|
| 限定符和类型 | 方法和说明 |
|---|---|
void |
addAttribute(RadiusAttribute attribute)
Adds a Radius attribute to this packet.
|
void |
addAttribute(String typeName,
String value)
Adds a Radius attribute to this packet.
|
protected void |
checkRequestAuthenticator(String sharedSecret,
int packetLength,
byte[] attributes)
Checks the request authenticator against the supplied shared secret.
|
protected void |
checkResponseAuthenticator(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(String sharedSecret)
Creates a request authenticator for this packet.
|
protected byte[] |
createResponseAuthenticator(String sharedSecret,
int packetLength,
byte[] attributes,
byte[] requestAuthenticator)
Creates an authenticator for a Radius response packet.
|
protected static RadiusPacket |
decodePacket(Dictionary dictionary,
InputStream in,
String sharedSecret,
RadiusPacket request)
Reads a Radius packet from the given input stream and
creates an appropiate RadiusPacket descendant object.
|
protected void |
decodeRequestAttributes(String sharedSecret)
Can be overriden to decode encoded request attributes such as
User-Password.
|
static RadiusPacket |
decodeRequestPacket(Dictionary dictionary,
InputStream in,
String sharedSecret)
Reads a Radius request packet from the given input stream and
creates an appropiate RadiusPacket descendant object.
|
static RadiusPacket |
decodeRequestPacket(InputStream in,
String sharedSecret)
Reads a Radius request packet from the given input stream and
creates an appropiate RadiusPacket descendant object.
|
static RadiusPacket |
decodeResponsePacket(Dictionary dictionary,
InputStream in,
String sharedSecret,
RadiusPacket request)
Reads a Radius response packet from the given input stream and
creates an appropiate RadiusPacket descendant object.
|
static RadiusPacket |
decodeResponsePacket(InputStream in,
String sharedSecret,
RadiusPacket request)
Reads a Radius response packet from the given input stream and
creates an appropiate RadiusPacket descendant object.
|
protected void |
encodePacket(OutputStream out,
String sharedSecret,
RadiusPacket request)
Encodes this Radius packet and sends it to the specified output
stream.
|
protected void |
encodeRequestAttributes(String sharedSecret)
This method exists for subclasses to be overridden in order to
encode packet attributes like the User-Password attribute.
|
void |
encodeRequestPacket(OutputStream out,
String sharedSecret)
Encodes this Radius packet and sends it to the specified output
stream.
|
void |
encodeResponsePacket(OutputStream out,
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(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.
|
List |
getAttributes()
Returns a list of all attributes belonging to this Radius
packet.
|
List |
getAttributes(int attributeType)
Returns all attributes of this packet of the given type.
|
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.
|
String |
getAttributeValue(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 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.
|
String |
getPacketTypeName()
Returns the type name of this Radius packet.
|
VendorSpecificAttribute |
getVendorAttribute(int vendorId)
已过时。
use getVendorAttributes(int)
|
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(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.
|
String |
toString()
String representation of this packet, for debugging purposes.
|
protected byte[] |
updateRequestAuthenticator(String sharedSecret,
int packetLength,
byte[] attributes)
AccountingRequest overrides this
method to create a request 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,
List 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 String getPacketTypeName()
public void setPacketType(int type)
type - packet type, 0-255public void setAttributes(List attributes)
attributes - list of RadiusAttribute objectspublic void addAttribute(RadiusAttribute attribute)
attribute - RadiusAttribute objectpublic void addAttribute(String typeName, String value)
typeName - name of the attribute, for example "NAS-Ip-Address"value - value of the attribute, for example "127.0.0.1"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 List getAttributes(int attributeType)
attributeType - type of attributes to getpublic List getAttributes(int vendorId, int attributeType)
vendorId - vendor IDattributeType - attribute type codepublic List getAttributes()
public RadiusAttribute getAttribute(int type)
type - attribute typeRuntimeException - if there are multiple occurences of the
requested attribute typepublic RadiusAttribute getAttribute(int vendorId, int type)
vendorId - vendor IDtype - attribute typeRuntimeException - if there are multiple occurences of the
requested attribute typepublic RadiusAttribute getAttribute(String type)
type - attribute type nameRuntimeException - if the attribute occurs multiple timespublic String getAttributeValue(String type)
type - attribute type nameIllegalArgumentException - if the type name is unknownRuntimeException - attribute occurs multiple timespublic List 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(OutputStream out, String sharedSecret) throws IOException
out - output stream to usesharedSecret - shared secret to be used to encode this packetIOException - communication errorpublic void encodeResponsePacket(OutputStream out, String sharedSecret, RadiusPacket request) throws IOException
out - output stream to usesharedSecret - shared secret to be used to encode this packetrequest - Radius request packetIOException - communication errorpublic static RadiusPacket decodeRequestPacket(InputStream in, String sharedSecret) throws IOException, RadiusException
sharedSecret - shared secret to be used to decode this packetIOException - IO errorRadiusException - malformed packetpublic static RadiusPacket decodeResponsePacket(InputStream in, String sharedSecret, RadiusPacket request) throws IOException, RadiusException
sharedSecret - shared secret to be used to decode this packetrequest - Radius request packetIOException - IO errorRadiusException - malformed packetpublic static RadiusPacket decodeRequestPacket(Dictionary dictionary, InputStream in, String sharedSecret) throws IOException, RadiusException
dictionary - dictionary to use for attributesin - InputStream to read packet fromsharedSecret - shared secret to be used to decode this packetIOException - IO errorRadiusException - malformed packetpublic static RadiusPacket decodeResponsePacket(Dictionary dictionary, InputStream in, String sharedSecret, RadiusPacket request) throws IOException, RadiusException
dictionary - dictionary to use for attributesin - InputStream to read packet fromsharedSecret - shared secret to be used to decode this packetrequest - Radius request packetIOException - IO errorRadiusException - malformed packetpublic static int getNextPacketIdentifier()
public static RadiusPacket createRadiusPacket(int type)
type - packet typepublic String toString()
toString 在类中 ObjectObject.toString()public byte[] getAuthenticator()
public void setAuthenticator(byte[] authenticator)
authenticator - authenticatorpublic Dictionary getDictionary()
public void setDictionary(Dictionary dictionary)
dictionary - Dictionary class to useDefaultDictionaryprotected void encodePacket(OutputStream out, String sharedSecret, RadiusPacket request) throws 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 packetIOException - communication errorRuntimeException - if required packet data has not been setprotected void encodeRequestAttributes(String sharedSecret)
sharedSecret - protected byte[] createRequestAuthenticator(String sharedSecret)
sharedSecret - shared secret that secures the communication
with the other Radius server/clientprotected byte[] updateRequestAuthenticator(String sharedSecret, int packetLength, byte[] attributes)
sharedSecret - shared secretpacketLength - length of the final Radius packetattributes - attribute dataprotected byte[] createResponseAuthenticator(String sharedSecret, int packetLength, byte[] attributes, byte[] requestAuthenticator)
sharedSecret - shared secretpacketLength - length of response packetattributes - encoded attributes of response packetrequestAuthenticator - request packet authenticatorprotected static RadiusPacket decodePacket(Dictionary dictionary, InputStream in, String sharedSecret, RadiusPacket request) throws 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 decodedIOException - if an IO error occurredRadiusException - if the Radius packet is malformedprotected void checkRequestAuthenticator(String sharedSecret, int packetLength, byte[] attributes) throws RadiusException
sharedSecret - shared secretpacketLength - total length of the packetattributes - request attribute dataRadiusExceptionprotected void decodeRequestAttributes(String sharedSecret) throws RadiusException
sharedSecret - RadiusExceptionprotected void checkResponseAuthenticator(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 packetRadiusExceptionprotected MessageDigest getMd5Digest()
protected byte[] getAttributeBytes()
throws IOException
IOException - error writing dataCopyright © 2016. All rights reserved.