Package org.tinyradius.core.attribute
Class AttributeTemplate
java.lang.Object
org.tinyradius.core.attribute.AttributeTemplate
public class AttributeTemplate
extends java.lang.Object
Represents a Radius attribute type.
-
Constructor Summary
Constructors Constructor Description AttributeTemplate(int vendorId, int type, java.lang.String name, java.lang.String rawDataType)
Create a new attribute type.AttributeTemplate(int vendorId, int type, java.lang.String name, java.lang.String rawDataType, byte encryptFlag, boolean tagged)
Create a new attribute type. -
Method Summary
Modifier and Type Method Description void
addEnumerationValue(int num, java.lang.String name)
Adds a name for an integer value of this attribute.RadiusAttribute
create(Dictionary dictionary, byte tag, byte[] value)
Create RadiusAttribute.RadiusAttribute
create(Dictionary dictionary, byte tag, java.lang.String value)
Create RadiusAttribute.RadiusAttribute
createEncoded(Dictionary dictionary, byte tag, byte[] encodedValue)
Create RadiusAttribute with encoded data.RadiusAttribute
decode(RadiusAttribute attribute, byte[] requestAuth, java.lang.String secret)
RadiusAttribute
encode(RadiusAttribute attribute, byte[] requestAuth, java.lang.String secret)
boolean
encryptEnabled()
boolean
equals(java.lang.Object o)
AttributeCodecType
getCodecType()
java.lang.String
getDataType()
java.lang.String
getEnumeration(int value)
java.lang.Integer
getEnumeration(java.lang.String value)
java.lang.String
getName()
int
getType()
int
getVendorId()
int
hashCode()
boolean
isTagged()
RadiusAttribute
parse(Dictionary dictionary, byte[] rawData)
Parse RadiusAttribute from raw byte data.java.lang.String
toString()
-
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/Atype
- sub-attribute type code, as unsigned bytename
- sub-attribute namerawDataType
- 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/Atype
- sub-attribute type code, as unsigned bytename
- sub-attribute namerawDataType
- string | octets | integer | date | ipaddr | ipv6addr | ipv6prefixencryptFlag
- encrypt flag as per FreeRadius dictionary format, can be 1/2/3, or default 0 for nonetagged
- whether attribute supports tags, as defined in RFC2868, default false
-
-
Method Details
-
create
Create RadiusAttribute.- Parameters:
dictionary
- dictionary to usetag
- tag as per RFC2868value
- value to set attribute- Returns:
- new RadiusAttribute
-
create
Create RadiusAttribute.- Parameters:
dictionary
- dictionary to usetag
- tag as per RFC2868value
- value to set attribute- Returns:
- new RadiusAttribute
-
parse
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 userawData
- attribute data to parse excl. type/length- Returns:
- new RadiusAttribute
-
createEncoded
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 usetag
- tag as per RFC2868encodedValue
- 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
- 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 namename
- the name for this number
-
encode
public RadiusAttribute encode(RadiusAttribute attribute, byte[] requestAuth, java.lang.String secret) throws RadiusPacketException- Parameters:
attribute
- attribute to encoderequestAuth
- (corresponding) request packet authenticatorsecret
- 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 decoderequestAuth
- (corresponding) request packet authenticatorsecret
- shared secret to decode with- Returns:
- attribute with decoded data
- Throws:
RadiusPacketException
- errors decoding attribute
-
toString
public java.lang.String toString()- Overrides:
toString
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()- Overrides:
hashCode
in classjava.lang.Object
-