Class AttributeTemplate

java.lang.Object
org.tinyradius.core.attribute.AttributeTemplate

public class AttributeTemplate extends Object
Represents a Radius attribute type.
  • Constructor Details

    • AttributeTemplate

      public AttributeTemplate(int vendorId, int type, String name, String rawDataType)
      Create a new attribute type. Convenience method that assumes no encrypt and no Tag support.
      Parameters:
      vendorId - vendor ID or -1 if N/A
      type - sub-attribute type code, as unsigned byte
      name - sub-attribute name
      rawDataType - string | octets | integer | date | ipaddr | ipv6addr | ipv6prefix
      See Also:
    • AttributeTemplate

      public AttributeTemplate(int vendorId, int type, String name, String rawDataType, byte encryptFlag, boolean hasTag)
      Create a new attribute type.
      Parameters:
      vendorId - vendor ID or -1 if N/A
      type - sub-attribute type code, as unsigned byte
      name - sub-attribute name
      rawDataType - string | octets | integer | date | ipaddr | ipv6addr | ipv6prefix
      encryptFlag - encrypt flag as per FreeRadius dictionary format, can be 1/2/3, or default 0 for none
      hasTag - whether attribute supports tags, as defined in RFC2868, default false
  • Method Details

    • create

      public RadiusAttribute create(Dictionary dictionary, byte tag, byte[] value)
      Create RadiusAttribute.
      Parameters:
      dictionary - dictionary to use
      tag - tag as per RFC2868
      value - value to set attribute
      Returns:
      new RadiusAttribute
    • create

      public RadiusAttribute create(Dictionary dictionary, byte tag, String value)
      Create RadiusAttribute.
      Parameters:
      dictionary - dictionary to use
      tag - tag as per RFC2868
      value - value to set attribute
      Returns:
      new RadiusAttribute
    • parse

      public RadiusAttribute parse(Dictionary dictionary, io.netty.buffer.ByteBuf data)
      Parse RadiusAttribute from raw byte data.

      If attribute type has encryption, this will create an OctetsAttribute wrapped in EncodedDecorator, otherwise uses the type specified in dictionary.

      Parameters:
      dictionary - dictionary to use
      data - attribute data to parse incl. type/length
      Returns:
      new RadiusAttribute
    • createEncoded

      public RadiusAttribute createEncoded(Dictionary dictionary, byte tag, byte[] encodedValue)
      Create RadiusAttribute with encoded data.

      If attribute type supports encryption, this will return an OctetsAttribute as underlying implementation so contents aren't validated at construction.

      Parameters:
      dictionary - dictionary to use
      tag - tag as per RFC2868
      encodedValue - encoded data, attribute data excl. type/length/tag
      Returns:
      new RadiusAttribute
    • getType

      public int getType()
      Returns:
      Radius type code for this attribute e.g. '1' (for User-Name)
    • getName

      public String getName()
      Returns:
      name of type e.g. 'User-Name'
    • getVendorId

      public int getVendorId()
      Returns:
      vendor ID or -1 if not applicable
    • getDataType

      public String getDataType()
      Returns:
      string | octets | integer | date | ipaddr | ipv6addr | ipv6prefix
    • isTagged

      public boolean isTagged()
      Returns:
      whether attribute supports Tag field as per RFC2868
    • encryptEnabled

      public boolean encryptEnabled()
    • getCodecType

      public AttributeCodecType getCodecType()
      Returns:
      one of AttributeCodecType enum, defaults to NO_ENCRYPT for none
    • getEnumeration

      public String getEnumeration(int value)
      Parameters:
      value - int value
      Returns:
      the name of the given integer value if this attribute is an enumeration, or null if it is not or if the integer value is unknown.
    • getEnumeration

      public Integer getEnumeration(String value)
      Parameters:
      value - string value
      Returns:
      the number of the given string value if this attribute is an enumeration, or null if it is not or if the string value is unknown.
    • addEnumerationValue

      public void addEnumerationValue(int num, String name)
      Adds a name for an integer value of this attribute.
      Parameters:
      num - number that shall get a name
      name - the name for this number
    • encode

      public RadiusAttribute encode(RadiusAttribute attribute, byte[] requestAuth, String secret) throws RadiusPacketException
      Parameters:
      attribute - attribute to encode
      requestAuth - (corresponding) request packet authenticator
      secret - shared secret to encode with
      Returns:
      attribute with encoded data
      Throws:
      RadiusPacketException - errors encoding attribute
    • decode

      public RadiusAttribute decode(RadiusAttribute attribute, byte[] requestAuth, String secret) throws RadiusPacketException
      Parameters:
      attribute - attribute to decode
      requestAuth - (corresponding) request packet authenticator
      secret - shared secret to decode with
      Returns:
      attribute with decoded data
      Throws:
      RadiusPacketException - errors decoding attribute
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object