The Attribute class holds attribute type information (e.g. Attribute.NAS_IP_Address),
handles creation, conversion to tunnel attributes, and performs simple retrieval
operations. The toString() method will return a human readable version
of the attribute and it's data.
The Attibute class can also translate symbolic names to numeric values, numeric values to symbolic names and common symbolic valus to integers and back.
// To convert a numeric attribute type to it's string value:
String name = Attribute.getName(Attribute.NAS_Identifier);
// To convert a symbolic attribute name to it's integer value:
int value = Attribute.getTag("NAS-IP-Address");
// To convert the PPP symbolic name to the integer value for Framed-Protocol:
int value = Attribute.getValueName(Attribute.Framed_Protocol, "PPP");
// To convert a symbolic value to a name for Framed-Protocol, value = 1
String name = Attribute.getValueName(Attribute.Framed_Protocol, 1);
When retrieving a tunnel attribute from an RADIUSClient.getAttributes() or
from AuthInfo.getReqestAttributeList() it must be converted to a tunnel
attribute like this:
AttributeList inList = auth.getRequestAttributeList();
Attribute tunnel[] = inList.getAttributes(Attribute.Tunnel_Type);
for (int i = 0; i < tunnel.length; i++) {
// Convert to a tunnel attribute (it's safe to do this more
// than once to an attribute.
Attribute t = tunnel[i].convertToTunnel();
...
}
The various parts of an attribute are available:
Attribute a = new Attribute(Attribute.Dial_Number, "555-1212");
// Get the attribute type:
int type = a.getTag();
// Get the tunnel tag and check to see if it's valid.
if (a.isTunnelAttribute()) {
int tunnelTag = a.getTunnelTag();
...
}
// Get the length of the attribute value data.
int payloadLength = a.getDataLength();
// Get the entire attribute's length including the tag, length and data.
int attrLen = a.getLength();
// Get the Vendor-Id for this attribute. If this isn't a Vendor-Specific // attribute junk will be returned. int vendor = a.getVendorID(); // Get the integer value for the attribute payload. // There is no guarantee that there is an integer value, // since it could be an octet string, IP address or time. int intValue = a.getInt(); // Get the string value. Once again the value could be some // other type. String x = a.getString(); // Get the IP address. Once again the value could be some other // type. If the length of the data isn't four bytes null is // returned. InetAddress ip = a.getIP(); // Get the displayable name of this attribute type. String attributeName = a.getName();
// A variation, get the displayable name of any attribute type. String otherName = a.getName(Attribute.NAS_Identifier); // The toString() displays the entire attribute. System.out.println(a);