net.jradius.packet
Class RadiusFormat

java.lang.Object
  extended by net.jradius.packet.Format
      extended by net.jradius.packet.RadiusFormat
Direct Known Subclasses:
FreeRadiusFormat

public class RadiusFormat
extends Format

Default RadiusPacket/RadiusAttribute format class. This class formats and parses UDP RADIUS Packets. Derived classes implement other formats.

Author:
David Bird

Nested Class Summary
 
Nested classes/interfaces inherited from class net.jradius.packet.Format
Format.AttributeParseContext
 
Field Summary
static int VSA_HEADER_LENGTH
           
 
Constructor Summary
RadiusFormat()
           
 
Method Summary
static RadiusFormat getInstance()
           
 int headerLength(RadiusAttribute a)
           
 int headerLength(VSAttribute a)
          Packs a VSAttribute header into a DataOutputStream
 void packAttribute(ByteBuffer buffer, RadiusAttribute a)
          Packs a RadiusAttribute into a DataOutputStream
 void packHeader(ByteBuffer buffer, RadiusAttribute a)
          Packs a RadiusAttribute header into a DataOutputStream
 void packHeader(ByteBuffer buffer, RadiusAttribute a, int valueLength)
           
 void packHeader(ByteBuffer buffer, RadiusPacket p, byte[] attributeBytes, int offset, int attributesLength, String sharedSecret)
          Packs the RadiusPacket into a DataOutputStream
 void packHeader(ByteBuffer buffer, VSAttribute a)
           
 void packHeader(ByteBuffer buffer, VSAttribute a, int len)
           
 void packPacket(RadiusPacket packet, String sharedSecret, ByteBuffer buffer, boolean onWire)
          Packs a RadiusPacket into a byte array
static void setAttributeBytes(RadiusPacket packet, ByteBuffer buffer, int length)
          Parses attributes and places them in a RadiusPacket
 void unpackAttributeHeader(ByteBuffer buffer, Format.AttributeParseContext ctx)
           
 void unpackAttributeHeader(InputStream in, Format.AttributeParseContext ctx)
          Unpacks the header of a RadiusAttribute from a DataInputStream
 
Methods inherited from class net.jradius.packet.Format
getUnsignedByte, getUnsignedByte, getUnsignedInt, getUnsignedInt, getUnsignedShort, getUnsignedShort, packAttributeList, packAttributes, putUnsignedByte, putUnsignedByte, putUnsignedInt, putUnsignedInt, putUnsignedShort, putUnsignedShort, readUnsignedByte, readUnsignedInt, readUnsignedShort, unpackAttributes, writeUnsignedByte, writeUnsignedInt, writeUnsignedShort
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VSA_HEADER_LENGTH

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

RadiusFormat

public RadiusFormat()
Method Detail

getInstance

public static RadiusFormat getInstance()
Returns:
Returns a static instnace of this class

setAttributeBytes

public static void setAttributeBytes(RadiusPacket packet,
                                     ByteBuffer buffer,
                                     int length)
Parses attributes and places them in a RadiusPacket

Parameters:
packet - The RadiusPacket to parse attributes into
bAttributes - The attribute bytes to parse

packPacket

public void packPacket(RadiusPacket packet,
                       String sharedSecret,
                       ByteBuffer buffer,
                       boolean onWire)
                throws IOException
Packs a RadiusPacket into a byte array

Parameters:
packet - The RadiusPacket to pack
Throws:
IOException

packHeader

public void packHeader(ByteBuffer buffer,
                       RadiusPacket p,
                       byte[] attributeBytes,
                       int offset,
                       int attributesLength,
                       String sharedSecret)
                throws IOException
Packs the RadiusPacket into a DataOutputStream

Parameters:
out - The DataOutputStream to write to
p - The RadiusPacket to pack
attributeBytes - The RadiusPacket attributes
Throws:
IOException - public void packHeader(OutputStream out, RadiusPacket p, byte[] attributeBytes, String sharedSecret) throws IOException { int length = attributeBytes.length + RadiusPacket.RADIUS_HEADER_LENGTH; writeUnsignedByte(out, p.getCode()); writeUnsignedByte(out, p.getIdentifier()); writeUnsignedShort(out, length); out.write(p.getAuthenticator(attributeBytes, sharedSecret)); }

packAttribute

public void packAttribute(ByteBuffer buffer,
                          RadiusAttribute a)
Packs a RadiusAttribute into a DataOutputStream

Specified by:
packAttribute in class Format
Parameters:
out - The DataOutputStream to write attributes to
a - The RadiusAttribute to pack
Throws:
IOException - public void packAttribute(OutputStream out, RadiusAttribute a) throws IOException { AttributeValue attributeValue = a.getValue(); packHeader(out, a); attributeValue.getBytes(out); }

packHeader

public void packHeader(ByteBuffer buffer,
                       RadiusAttribute a)
Packs a RadiusAttribute header into a DataOutputStream

Parameters:
out - The DataOutputStream to write to
a - The RadiusAttribute to pack
Throws:
IOException - public void packHeader(OutputStream out, RadiusAttribute a) throws IOException { if (a instanceof VSAttribute) { packHeader(out, (VSAttribute)a); return; } AttributeValue attributeValue = a.getValue(); writeUnsignedByte(out, (int) a.getType()); writeUnsignedByte(out, attributeValue.getLength() + HEADER_LENGTH); }

packHeader

public void packHeader(ByteBuffer buffer,
                       RadiusAttribute a,
                       int valueLength)

headerLength

public int headerLength(VSAttribute a)
Packs a VSAttribute header into a DataOutputStream

Parameters:
out - The DataOutputStream to write to
a - The VSAttribute to pack
Throws:
IOException - public void packHeader(OutputStream out, VSAttribute a) throws IOException { AttributeValue attributeValue = a.getValue(); int len = attributeValue.getLength(); int vsaHeader = VSA_HEADER_LENGTH; if (a.hasContinuationByte()) vsaHeader ++; writeUnsignedByte(out, (int)a.getType()); writeUnsignedByte(out, len + vsaHeader); writeUnsignedInt(out, a.getVendorId()); writeUnsignedByte(out, (int)a.getVsaAttributeType()); len += 2; if (a.hasContinuationByte()) len ++; switch(a.getLengthLength()) { case 1: writeUnsignedByte(out, len); break; case 2: writeUnsignedShort(out, len); break; case 4: writeUnsignedInt(out, len); break; } if (a.hasContinuationByte()) { writeUnsignedByte(out, a.getContinuation()); } }

headerLength

public int headerLength(RadiusAttribute a)

packHeader

public void packHeader(ByteBuffer buffer,
                       VSAttribute a)

packHeader

public void packHeader(ByteBuffer buffer,
                       VSAttribute a,
                       int len)

unpackAttributeHeader

public void unpackAttributeHeader(InputStream in,
                                  Format.AttributeParseContext ctx)
                           throws IOException
Unpacks the header of a RadiusAttribute from a DataInputStream

Parameters:
in - The DataInputStream to read from
ctx - The Attribute Parser Context
Throws:
IOException

unpackAttributeHeader

public void unpackAttributeHeader(ByteBuffer buffer,
                                  Format.AttributeParseContext ctx)
                           throws IOException
Specified by:
unpackAttributeHeader in class Format
Throws:
IOException


Copyright © 2011 Coova Technologies, LLC, All Rights Reserved.