Package org.tinyradius.core.attribute
Class AttributeTemplate
java.lang.Object
org.tinyradius.core.attribute.AttributeTemplate
Represents a Radius attribute type.
-
Constructor Summary
ConstructorDescriptionAttributeTemplate
(int vendorId, int type, String name, String rawDataType) Create a new attribute type.AttributeTemplate
(int vendorId, int type, String name, String rawDataType, byte encryptFlag, boolean hasTag) Create a new attribute type. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addEnumerationValue
(int num, String name) Adds a name for an integer value of this attribute.create
(Dictionary dictionary, byte tag, byte[] value) Create RadiusAttribute.create
(Dictionary dictionary, byte tag, String value) Create RadiusAttribute.createEncoded
(Dictionary dictionary, byte tag, byte[] encodedValue) Create RadiusAttribute with encoded data.decode
(RadiusAttribute attribute, byte[] requestAuth, String secret) encode
(RadiusAttribute attribute, byte[] requestAuth, String secret) boolean
boolean
getEnumeration
(int value) getEnumeration
(String value) getName()
int
getType()
int
int
hashCode()
boolean
isTagged()
parse
(Dictionary dictionary, io.netty.buffer.ByteBuf data) Parse RadiusAttribute from raw byte data.toString()
-
Constructor Details
-
AttributeTemplate
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
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/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 nonehasTag
- 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 usedata
- attribute data to parse incl. type/length- Returns:
- new RadiusAttribute
-
createEncoded
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 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
- Returns:
- name of type e.g. 'User-Name'
-
getVendorId
public int getVendorId()- Returns:
- vendor ID or -1 if not applicable
-
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
- 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
- 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
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, 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, 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
-
equals
-
hashCode
public int hashCode()
-