Package org.tinyradius.packet
Class RadiusPacketEncoder
- java.lang.Object
-
- org.tinyradius.packet.RadiusPacketEncoder
-
public class RadiusPacketEncoder extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description RadiusPacketEncoder()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static RadiusPacket
createRadiusPacket(Dictionary dictionary, int type, int identifier, byte[] authenticator, java.util.List<RadiusAttribute> attributes)
Creates a RadiusPacket object.static RadiusPacket
fromDatagram(Dictionary dictionary, io.netty.channel.socket.DatagramPacket packet, java.lang.String sharedSecret)
Reads a request from the given input stream and creates an appropriate RadiusPacket/subclass.static RadiusPacket
fromDatagram(Dictionary dictionary, io.netty.channel.socket.DatagramPacket datagram, java.lang.String sharedSecret, RadiusPacket request)
Reads a response from the given input stream and creates an appropriate RadiusPacket descendant object.static RadiusPacket
fromDatagramUnverified(Dictionary dictionary, io.netty.channel.socket.DatagramPacket packet)
Reads a Radius packet from the given input stream and creates an appropriate RadiusPacket/subclass.static int
nextPacketId()
Increment the next packet identifier.static io.netty.channel.socket.DatagramPacket
toDatagram(RadiusPacket packet, java.net.InetSocketAddress address)
-
-
-
Method Detail
-
nextPacketId
public static int nextPacketId()
Increment the next packet identifier.- Returns:
- the next packet identifier to use
-
toDatagram
public static io.netty.channel.socket.DatagramPacket toDatagram(RadiusPacket packet, java.net.InetSocketAddress address) throws RadiusException
- Throws:
RadiusException
-
fromDatagramUnverified
public static RadiusPacket fromDatagramUnverified(Dictionary dictionary, io.netty.channel.socket.DatagramPacket packet) throws RadiusException
Reads a Radius packet from the given input stream and creates an appropriate RadiusPacket/subclass.Makes no distinction between reading requests/responses, and does not attempt to decode attributes/verify authenticators. RadiusPacket should be separately verified after this to check authenticators are valid and required attributes present.
Typically used to decode a response where the corresponding request (specifically the authenticator/identifier) are not available.
- Parameters:
dictionary
- dictionary to use for attributespacket
- DatagramPacket to read packet from- Returns:
- new RadiusPacket object
- Throws:
RadiusException
- malformed packet
-
fromDatagram
public static RadiusPacket fromDatagram(Dictionary dictionary, io.netty.channel.socket.DatagramPacket packet, java.lang.String sharedSecret) throws RadiusException
Reads a request from the given input stream and creates an appropriate RadiusPacket/subclass.Decodes the encrypted fields and attributes of the packet, and checks authenticator if appropriate.
- Parameters:
dictionary
- dictionary to use for attributespacket
- DatagramPacket to read packet fromsharedSecret
- shared secret to be used to decode this packet- Returns:
- new RadiusPacket object
- Throws:
RadiusException
- malformed packet
-
fromDatagram
public static RadiusPacket fromDatagram(Dictionary dictionary, io.netty.channel.socket.DatagramPacket datagram, java.lang.String sharedSecret, RadiusPacket request) throws RadiusException
Reads a response from the given input stream and creates an appropriate RadiusPacket descendant object.Decodes the encrypted fields and attributes of the packet, and checks authenticator if appropriate.
- Parameters:
dictionary
- dictionary to use for attributesdatagram
- DatagramPacket to read packet fromsharedSecret
- shared secret to be used to decode this packetrequest
- associated request packet if parsing response, or null if parsing request- Returns:
- new RadiusPacket object
- Throws:
RadiusException
- malformed packet
-
createRadiusPacket
public static RadiusPacket createRadiusPacket(Dictionary dictionary, int type, int identifier, byte[] authenticator, java.util.List<RadiusAttribute> attributes)
Creates a RadiusPacket object. Depending on the passed type, an appropriate packet is created. Also sets the type, and the the packet identifier.- Parameters:
type
- packet type- Returns:
- RadiusPacket object
-
-