Class AttributeTemplate

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

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

    • AttributeTemplate

      public AttributeTemplate​(int vendorId, int type, java.lang.String name, java.lang.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(int, int, String, String, byte, boolean)
    • AttributeTemplate

      public AttributeTemplate​(int vendorId, int type, java.lang.String name, java.lang.String rawDataType, byte encryptFlag, boolean tagged)
      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
      tagged - 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, java.lang.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, byte[] rawData)
      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
      rawData - attribute data to parse excl. 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 use 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 java.lang.String getName()
      Returns:
      name of type e.g. 'User-Name'
    • getVendorId

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

      public java.lang.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 java.lang.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 java.lang.Integer getEnumeration​(java.lang.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, java.lang.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, java.lang.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, java.lang.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 java.lang.String toString()
      Overrides:
      toString in class java.lang.Object
    • equals

      public boolean equals​(java.lang.Object o)
      Overrides:
      equals in class java.lang.Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class java.lang.Object