AXL Software

com.theorem.radserver3
Class Attribute

Object
  extended byA
      extended byAttribute
All Implemented Interfaces:
Serializable

public class Attribute
extends A
implements Serializable

RADIUS attribute class. Holds attribute data and provides symbolic values for standard RADIUS attributes. Usually used in conjunction with the AttributeList class which provides convenient methods for access to groups of attributes.

See Also:
AttributeList, Serialized Form

Field Summary
static int DATA_TYPE_DATE
          The attribute data is probably a date - 8.
static int DATA_TYPE_ENCRYPT1
          The attribute uses encryption type 1 -PAP encoding (can be OR'd with other values) - 64.
static int DATA_TYPE_ENCRYPT2
          The attribute uses encryption type 2 - SALT encoding (can be OR'd with other values) - 128.
static int DATA_TYPE_ENCRYPT3
          The attribute uses encryption type 3 - Ascend encoding (can be OR'd with other values) - 256.
static int DATA_TYPE_INTEGER
          The attribute data is probably an integer - 1.
static int DATA_TYPE_IPADDRESS
          The attribute data is probably an IP Address (IPV4 or IPV6) - 16.
static int DATA_TYPE_OCTETS
          The attribute data is probably binary octets - 2.
static int DATA_TYPE_STRING
          The attribute data is probably a string - 4.
static int DATA_TYPE_TUNNEL
          The attribute is a tunnel attribute which can be OR'd with other values - 32.
static int DATA_TYPE_UNKNOWN
          The attribute data type is unknown - 0.
 int length
          Attribute length including tag and length byte.
 
Fields inherited from class A
Acct_Authentic, Acct_Delay_Time, Acct_Input_Gigawords, Acct_Input_Octets, Acct_Input_Packets, Acct_Interim_Interval, Acct_Link_Count, Acct_Multi_Session_Id, Acct_Output_Gigawords, Acct_Output_Octets, Acct_Output_Packets, Acct_Session_Id, Acct_Session_Time, Acct_Status_Type, Acct_Terminate_Cause, Acct_Tunnel_Connection, Acct_Tunnel_Packets_Lost, ARAP_Challenge_Response, ARAP_Features, ARAP_Password, ARAP_Security, ARAP_Security_Data, ARAP_Zone_Access, Basic_Location_Policy_Rules, Callback_Id, Callback_Number, Called_Station_Id, Calling_Station_Id, CHAP_Challenge, CHAP_Password, Chargeable_User_Identity, Class, Configuration_Token, Connect_Info, Delegated_IPv6_Prefix, Digest_Attributes, Digest_Response, EAP_Key_Name, EAP_Message, Egress_VLAN_Name, Egress_VLANID, Error_Cause, Event_Timestamp, Extended_Location_Policy_Rules, Filter_Id, Framed_AppleTalk_Link, Framed_AppleTalk_Network, Framed_AppleTalk_Zone, Framed_Compression, Framed_Interface_Id, Framed_IP_Address, Framed_IP_Netmask, Framed_IPv6_Pool, Framed_IPv6_Prefix, Framed_IPv6_Route, Framed_IPX_Network, Framed_Management, Framed_MTU, Framed_Pool, Framed_Protocol, Framed_Route, Framed_Routing, Idle_Timeout, Ingress_Filters, Location_Capable, Location_Data, Location_Information, Login_IP_Host, Login_IPv6_Host, Login_LAT_Group, Login_LAT_Node, Login_LAT_Port, Login_LAT_Service, Login_Service, Login_TCP_Port, Management_Policy_Id, Management_Privilege_Level, Management_Transport_Protection, Message_Authenticator, NAS_Filter_Rule, NAS_Identifier, NAS_IP_Address, NAS_IPv6_Address, NAS_Port, NAS_Port_Id, NAS_Port_Type, Old_Password, Operator_Name, Originating_Line_Info, Password_Retry, PKM_Auth_Key, PKM_CA_Cert, PKM_Config_Settings, PKM_Cryptosuite_List, PKM_SA_Descriptor, PKM_SAID, PKM_SS_Cert, Port_Limit, Prompt, Proxy_State, Reply_Message, Requested_Location_Info, Service_Type, Session_Timeout, State, Termination_Action, Tunnel_Assignment_Id, Tunnel_Client_Auth_Id, Tunnel_Client_Endpoint, Tunnel_Medium_Type, Tunnel_Password, Tunnel_Preference, Tunnel_Private_Group_Id, Tunnel_Server_Auth_Id, Tunnel_Server_Endpoint, Tunnel_Type, User_Name, User_Password, User_Priority_Table, Vendor_Specific
 
Constructor Summary
Attribute(int type)
          Attribute Constructor for an attribute with no data.
Attribute(int type, byte[] attributeData)
          Attribute Constructor for an attribute with data.
Attribute(int type, Date date)
          Attribute Constructor for an attribute with a Date value.
Attribute(int type, int value)
          Attribute Constructor for an attribute with integer data.
Attribute(int type, int tunnelTag, byte[] attribute)
          Attribute Constructor for Tunnel attributes
 
Method Summary
 void convertToTunnel()
          Convert an attribute to a Tunnel attribute.
 boolean equals(Object obj)
          Indicates whether some other object is "equal to" this one.
 byte[] getAttribute()
          Returns raw attribute data including the tag, length, and if it's a tunnel attribute, the tunnel tag.
 byte[] getAttributeData()
          Get attribute value field data.
 int getDataLength()
          Get attribute value data field length.
 int getDataType()
          Get the data type for this attribute.
 int getDataType(int vendorId)
          Get the data type for this attribute.
static int getDataType(int vendorId, int tag)
          Get the data type for an attribute.
 Date getDate()
          Return a Date value from a 4 byte attribute.
 int getInt()
          Get an int value from the Attribute data.
 InetAddress getIP()
          Return an IP address from a 4 byte binary attribute (like NAS-IP-Address).
 int getLength()
          Get attribute's raw length including tag, length and data.
 String getName()
          Get the name of this attribute tag.
static String getName(int tag)
          Get the name of an attribute tag.
 String getString()
          Return an attribute value as a string.
 int getTag()
          Get tag field value.
static int getTag(String name)
          Get the attribute tag number from the symbolic name.
 int getTunnelTag()
          Get the tunnel tag.
 byte[] getTunnelValue()
          Get a tunnel attribute's value.
 String getValueName()
          Get the symbolic representation of this attribute's value.
static int getValueName(int attribute, String value)
          Get the numeric representation of an attribute's symbolic value.
 int getVendorID()
          Get Vendor-Specific ID number from this attribute.
 boolean isLongTag()
          Determine if this attribute has a long tag (16 bit).
 boolean isPrintable()
          Determine if this attribute's data is printable (UTF-8).
static boolean isPrintable(byte[] b)
          Determine if a byte array is printable (UTF-8).
static boolean isPrintable(byte[] b, int start, int length)
          Determine if a byte array is printable (UTF-8).
 boolean isPrintableAscii()
          Determine if this attribute's data is printable (eg ASCII-printable).
static boolean isPrintableAscii(byte[] b)
          Determine if a byte array is printable (eg ASCII-printable).
static boolean isPrintableAscii(byte[] b, int start, int length)
          Determine if a byte array is printable (eg ASCII-printable).
 boolean isTunnelAttribute()
          Determine if this is a tunnel attribute.
static void setDataType(int tag, int dataType)
          Set an attribute to a specific data type.
 Attribute setLongTag()
          Enable the long (16 bit) tags - Warning: - if you think you need to use this you probably don't understand the RADIUS protocol and will cause problems for yourself and others.
 Attribute setLongTag(boolean enable)
          Optionally enable the long tags - Enable the long (16 bit) tags - Warning: - if you think you need to use this you probably don't understand the RADIUS protocol and will cause problems for yourself and others.
static String toIPString(byte[] b)
          Display a 4 octet value as an IP address.
static String toIPString(byte[] b, int start)
          Display a 4 octet value as an IP address.
 String toString()
          Display Attribute as a string.
 String toString(int vendorId)
          Display Attribute as a string from a given vendor ID (for Vendor specific attributes).
 
Methods inherited from class Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DATA_TYPE_DATE

public static final int DATA_TYPE_DATE
The attribute data is probably a date - 8.

See Also:
getDataType(), Constant Field Values

DATA_TYPE_ENCRYPT1

public static final int DATA_TYPE_ENCRYPT1
The attribute uses encryption type 1 -PAP encoding (can be OR'd with other values) - 64.

See Also:
Constant Field Values

DATA_TYPE_ENCRYPT2

public static final int DATA_TYPE_ENCRYPT2
The attribute uses encryption type 2 - SALT encoding (can be OR'd with other values) - 128.

See Also:
Constant Field Values

DATA_TYPE_ENCRYPT3

public static final int DATA_TYPE_ENCRYPT3
The attribute uses encryption type 3 - Ascend encoding (can be OR'd with other values) - 256.

See Also:
Constant Field Values

DATA_TYPE_INTEGER

public static final int DATA_TYPE_INTEGER
The attribute data is probably an integer - 1.

See Also:
getDataType(), Constant Field Values

DATA_TYPE_IPADDRESS

public static final int DATA_TYPE_IPADDRESS
The attribute data is probably an IP Address (IPV4 or IPV6) - 16.

See Also:
getDataType(), Constant Field Values

DATA_TYPE_OCTETS

public static final int DATA_TYPE_OCTETS
The attribute data is probably binary octets - 2.

See Also:
getDataType(), Constant Field Values

DATA_TYPE_STRING

public static final int DATA_TYPE_STRING
The attribute data is probably a string - 4.

See Also:
getDataType(), Constant Field Values

DATA_TYPE_TUNNEL

public static final int DATA_TYPE_TUNNEL
The attribute is a tunnel attribute which can be OR'd with other values - 32. Since tunnel attributes must decode their data differently than regular attributes tunnel data must be decoded after the convertToTunnel() method is used.

See Also:
getDataType(), Constant Field Values

DATA_TYPE_UNKNOWN

public static final int DATA_TYPE_UNKNOWN
The attribute data type is unknown - 0.

See Also:
getDataType(), Constant Field Values

length

public int length
Attribute length including tag and length byte. For tunnel attributes this includes the tunnel tag byte.

Constructor Detail

Attribute

public Attribute(int type)
Attribute Constructor for an attribute with no data.

Parameters:
type - Attribute tag.

Attribute

public Attribute(int type,
                 byte[] attributeData)
Attribute Constructor for an attribute with data.

Parameters:
type - attribute tag.
attributeData - value.

Attribute

public Attribute(int type,
                 Date date)
Attribute Constructor for an attribute with a Date value.

Parameters:
type - Attribute tag. param date Date.
Since:
3.40

Attribute

public Attribute(int type,
                 int value)
Attribute Constructor for an attribute with integer data.

Parameters:
type - Attribute tag.
Since:
3.32

Attribute

public Attribute(int type,
                 int tunnelTag,
                 byte[] attribute)
Attribute Constructor for Tunnel attributes

Parameters:
type - attribute type
tunnelTag - Tunnel tag
attribute - value
Method Detail

convertToTunnel

public void convertToTunnel()
Convert an attribute to a Tunnel attribute.

Attributes in a response must be converted to Tunnel Attributes to be interpreted properly. It's harmless to reconvert attributes.


equals

public boolean equals(Object obj)
Indicates whether some other object is "equal to" this one.

Parameters:
obj - - the reference object with which to compare.
Returns:
true if the object equals this object.

getAttribute

public byte[] getAttribute()
Returns raw attribute data including the tag, length, and if it's a tunnel attribute, the tunnel tag.

Returns:
raw attribute including tag and length fields. Tunnel attributes will also contain the tunnel tag.

getAttributeData

public byte[] getAttributeData()
Get attribute value field data.

If this is a tunnel attribute the tunnel tag is included in the data. This is useful if you're moving attribute data around without regard for it's contents (E.g. getting attributes from an AttributeList and moving them to another list. Please use convertToTunnel() if this is a tunnel attribute to access the tunnel tag properly or use the method getTunnelValue() .

Returns:
Attribute's data field's binary value.

getDataLength

public int getDataLength()
Get attribute value data field length.

Note for Tunnel attributes:
If this is a tunnel attribute the length reported will depend on whether the attribute was created as a tunnel attribute or the convertToTunnel() method was used. In both these cases the value will be the the length of the tunnel data. If the tunnel attribute has not been converted from an ordinary attribute to a tunnel attribute the length will include the tunnel tag.

Returns:
data length.

getDataType

public int getDataType()
Get the data type for this attribute. The data type is a guess at the type of data stored in the attribute.

Returns:
The data type.
Since:
3.29

getDataType

public int getDataType(int vendorId)
Get the data type for this attribute.

Parameters:
vendorId - The vendor id for this attribute or 0 for no vendor.
Returns:
The data type.
Since:
3.29

getDataType

public static int getDataType(int vendorId,
                              int tag)
Get the data type for an attribute. The data type is a guess at the type of data stored in the attribute.

Parameters:
vendorId - The vendor id for this attribute or 0 for no vendor.
tag - The attribute type - e.g. Attribute.User_Name.
Returns:
The data type - one of DATA_TYPE_STRING, DATA_TYPE_INTEGER, DATA_TYPE_OCTETS, DATA_TYPE_IPADDRESS, and DATA_TYPE_DATE. The DATA_TYPE_TUNNEL will be OR'd with the above data types for tunnel attributes.
Since:
3.29, 3.43a
See Also:
DATA_TYPE_STRING, DATA_TYPE_INTEGER, DATA_TYPE_OCTETS, DATA_TYPE_IPADDRESS, DATA_TYPE_DATE, DATA_TYPE_TUNNEL

getDate

public Date getDate()
Return a Date value from a 4 byte attribute. This is for attributes like Event-Time.

Returns:
Date value.

getInt

public int getInt()
Get an int value from the Attribute data.

Returns:
Integer value or 0 if the data doesn't hold an integer. An integer value has exactly four bytes.

getIP

public InetAddress getIP()
Return an IP address from a 4 byte binary attribute (like NAS-IP-Address).

Returns:
the IP address or null if the data length isn't four (IPV4) or sixteen (IPV6) bytes long.

getLength

public int getLength()
Get attribute's raw length including tag, length and data.

Returns:
length of entire raw attribute (includes tag and length bytes).

getName

public String getName()
Get the name of this attribute tag. For example Attribute.getName(Attribute.NAS_IP_Address) returns"NAS-IP-Address".

Returns:
Human readable version of the name

getName

public static String getName(int tag)
Get the name of an attribute tag. For example Attribute.getName(Attribute.NAS_IP_Address) returns"NAS-IP-Address".

Parameters:
tag - Attribute type.
Returns:
Human readable version of the name

getString

public String getString()
Return an attribute value as a string.

Returns:
attribute string value.

getTag

public int getTag()
Get tag field value.

Returns:
tag value.

getTag

public static int getTag(String name)
Get the attribute tag number from the symbolic name.

Parameters:
name - Symbolic name of attribute ("NAS-IP-Address");
Returns:
The attribute type. E.g. "NAS-IP-Address" returns 4. If there is no known mapping for an attribute name -1 is returned.

getTunnelTag

public int getTunnelTag()
Get the tunnel tag.

Returns:
The tunnel tag number.

getTunnelValue

public byte[] getTunnelValue()
Get a tunnel attribute's value. This should not be performed on a non-tunnel

Returns:
Tunnel attribute's data value without the tag information.
Since:
3.37

getValueName

public String getValueName()
Get the symbolic representation of this attribute's value. Some attributes, like Framed-Protocol, have symbolic values, like 'PPP' for example. This method would return 1 for "PPP:

Returns:
The symbolic value or null if the symbolic name cannot be found.

getValueName

public static int getValueName(int attribute,
                               String value)
Get the numeric representation of an attribute's symbolic value. Some attributes, like Framed-Protocol, have symbolic values, like 'PPP' for example. This method translates the symbolic name

Parameters:
attribute - Attribute type.
value - Symbolic value, like "PPP".
Returns:
numeric value or -1 if the symbolic name cannot be found.

getVendorID

public int getVendorID()
Get Vendor-Specific ID number from this attribute. If the attribute is not a Vendor-Specific attribute the return value will be junk.


isLongTag

public boolean isLongTag()
Determine if this attribute has a long tag (16 bit).

Returns:
true if it has a long tag field.
Since:
Server 3.43.

isPrintable

public boolean isPrintable()
Determine if this attribute's data is printable (UTF-8).

Returns:
true if printable.

isPrintable

public static boolean isPrintable(byte[] b)
Determine if a byte array is printable (UTF-8).

Parameters:
b - Bytes to test.
Returns:
true if printable.

isPrintable

public static boolean isPrintable(byte[] b,
                                  int start,
                                  int length)
Determine if a byte array is printable (UTF-8).

Parameters:
b - Bytes to test.
start - start position.
length - Length to test.
Returns:
true if printable.

isPrintableAscii

public boolean isPrintableAscii()
Determine if this attribute's data is printable (eg ASCII-printable).

Returns:
true if printable.

isPrintableAscii

public static boolean isPrintableAscii(byte[] b)
Determine if a byte array is printable (eg ASCII-printable).

Parameters:
b - Bytes to test.
Returns:
true if printable.

isPrintableAscii

public static boolean isPrintableAscii(byte[] b,
                                       int start,
                                       int length)
Determine if a byte array is printable (eg ASCII-printable).

Parameters:
b - Bytes to test.
start - start position.
length - Length to test.
Returns:
true if printable.

isTunnelAttribute

public boolean isTunnelAttribute()
Determine if this is a tunnel attribute.

Returns:
True if this is a tunnel attribute.

setDataType

public static void setDataType(int tag,
                               int dataType)
Set an attribute to a specific data type. The getDataType() method is used to extract a probable data type. This method can be used to alter the data type for an existing attribute or create a type for a new attribute. For example if you want to interpret the User-Password as a STRING instead of OCTETS use setDataType(Attribute.User_Password, STRING).

Parameters:
tag - Attribute type, E.g. Attribute.User_Name.
dataType - Set to one of the data types, E.g. STRING.
Since:
3.43a
See Also:
DATA_TYPE_STRING, DATA_TYPE_INTEGER, DATA_TYPE_OCTETS, DATA_TYPE_IPADDRESS, DATA_TYPE_DATE, DATA_TYPE_TUNNEL

setLongTag

public Attribute setLongTag()
Enable the long (16 bit) tags - Warning: - if you think you need to use this you probably don't understand the RADIUS protocol and will cause problems for yourself and others. Long tags are ONLY for SOME Vendor-Specific sub-attributes. This cannot be used to expand general (non-VSA sub-attribute) tags to values over 255 as it violates the RADIUS protocol.

Returns:
this attribute.
Since:
Server 3.43.

setLongTag

public Attribute setLongTag(boolean enable)
Optionally enable the long tags - Enable the long (16 bit) tags - Warning: - if you think you need to use this you probably don't understand the RADIUS protocol and will cause problems for yourself and others. Long tags are ONLY for SOME Vendor-Specific sub-attributes. This cannot be used to expand general (non-VSA sub-attribute) tags to values over 255 as it violates the RADIUS protocol.

Parameters:
enable - Enable the long tags if true.
Returns:
this attribute.
Since:
Server 3.43.

toIPString

public static String toIPString(byte[] b)
Display a 4 octet value as an IP address.

Parameters:
b - Bytes
Returns:
IP address string.

toIPString

public static String toIPString(byte[] b,
                                int start)
Display a 4 octet value as an IP address.

Parameters:
b - Bytes
start - Start position in b.
Returns:
IP address string.

toString

public String toString()
Display Attribute as a string.

Returns:
String representation of the Attribute.

toString

public String toString(int vendorId)
Display Attribute as a string from a given vendor ID (for Vendor specific attributes).

Returns:
String representation of the Attribute.

AXL Software

Submit a bug report or feature request

Copyright 1998-2010 AXL Software PO Box 97, Viola, Delaware 19979, U.S.A. All Rights Reserved.