package com.theorem.radserver3.examples.vendorspecific; import com.theorem.radserver3.*; /** * Vendor specific examples. *
* Modern Vendor-Specific attributes look very much like a miniature RADIUS attribute * block. That is to say the VS attribute contains sub-attributes consisting of a tag, length, * and value. *
* Although some implementations allow several sub-attributes in one VSA this * is not universal. Some systems want each piece of information in it's own VSA. * It's probably safer to send one piece of information in each VSA than several * in one block. The examples below will make this concept clearer. *
* The VendorSpecific class extends the AttributeList class. This allows the VSA to * hold one or more sub-attributes exactly as standard RADIUS attributes are added * to the packet's attribute block. */ public class VSExamples { /** * Creating some Vendor-Specific attributes and return them as an attribute list. * @return AttributeList containing the attributes. */ public AttributeList createVS_One() { // Create an Ascend Vendor-Specific attribute. VendorSpecific vsAscend1 = new VendorSpecific(Ascend.VENDORID); // Add the Ascend Ascend-Session attribute with the value of 5. vsAscend1.addAttribute(Ascend.Ascend_Session_Type, 5); // In this example we're writing for an implementation that only permits one // piece of information per VSA. We want to send two pieces of vendor information. // Create the second VSA. VendorSpecific vsAscend2 = new VendorSpecific(Ascend.VENDORID); // Add the Ascend Ascend-Add-Seconds attribute with the value of 100. vsAscend2.addAttribute(Ascend.Ascend_Add_Seconds , 100); // Return both VSA's as an attribute list. AttributeList retList = new AttributeList(); retList.addAttribute(vsAscend1.getAttribute()); retList.addAttribute(vsAscend1.getAttribute()); return retList; } /** * Creating some Vendor-Specific attributes and return them as an attribute list. * @return AttributeList containing the attributes. */ public AttributeList createVS_Two() { // Create an Ascend Vendor-Specific attribute. In this version we // are permitted to place multiple pieces of information in one VSA. // This practice varies - see createVS_One() for a different method. VendorSpecific vsAscend = new VendorSpecific(Ascend.VENDORID); // Add the Ascend Ascend-Session attribute with the value of 5. vsAscend.addAttribute(Ascend.Ascend_Session_Type, 5); // Add the Ascend Ascend-Add-Seconds attribute with the value of 100. vsAscend.addAttribute(Ascend.Ascend_Add_Seconds , 100); // Return both VSA's as an attribute list. AttributeList retList = new AttributeList(); retList.addAttribute(vsAscend.getAttribute()); return retList; } /** * Creating some Cisco Vendor-Specific attributes and return them as an attribute list. * @return AttributeList containing the attributes. */ public AttributeList createCisco() { // It's not clear if Cisco can handle multiple attribute information in one VSA // so we'll create multiple instances. // Create the attribute list to return. AttributeList retList = new AttributeList(); VendorSpecific vsCisco; vsCisco = new VendorSpecific(Cisco.VENDORID); vsCisco.addAttribute(Cisco.avpair, "323_credit_amount=1"); retList.addAttribute(vsCisco.getAttribute()); vsCisco = new VendorSpecific(Cisco.VENDORID); vsCisco.addAttribute(Cisco.avpair, "h323-currency=2"); retList.addAttribute(vsCisco.getAttribute()); return retList; } /** * Retrieve VSA's. * This safely assumes we are expecting either individual information in several * VSA's or one VSA with a collection of information. * * @param requestList Attribute request list from the client or server. */ public void extractAscend(AttributeList requestList) { // Assume we're only going after Ascend VSA's. // Get them from the request attribute list. VendorSpecific vsAscend[] = requestList.getVendorSpecific(Ascend.VENDORID); // Loop over what might potientially be multiple Ascend VSA's. // If everything is stored in one VSA we're still safe. for (int i = 0; i < vsAscend.length; i++) { // For convenience get the current Ascend VSA from the array, VendorSpecific vsa = vsAscend[i]; // The VSA may contain a single entry or a list. Get each value. int vsLen = vsa.size(); for (int j = 0; j < vsLen; j++) { // For convenience get the attribute. Attribute a = vsa.getAttributeAt(j); // Switch on the particular type of Ascend sub attribute. // The type is held in the tag. switch (a.getTag()) { case Ascend.Ascend_Auth_Type: // Do something like get the authtication type. int authType = a.getInt(); break; case Ascend.Ascend_Assign_IP_Server: // do something. break; // ... more cases we might handle. default: // Ascend attributes we don't understand or don't // care about. break; } } } } /** * Example that illustrates generating VSA's with long tags. * Normally tags are 8 bits, but there is a movement to use 16 bits. */ public void longTags() { System.out.println("Short tags, regular VSA"); VendorSpecific svs = new VendorSpecific(Ascend.VENDORID); svs.addAttribute(99, 9); System.out.println(svs); System.out.println(); // Create a VSA with long tags. VendorSpecific vs = new VendorSpecific(Ascend.VENDORID, VendorSpecific.LONG_TAGS); // Create an attribute with a large tag number (value > 255). vs.addAttribute(999, 9); System.out.println("Ascend VSA with long tags:\n" + vs); Attribute a = vs.getAttribute(); System.out.println("Ascend long tag vsa: \n" + vs); vs = new VendorSpecific(a).setLongTag(); System.out.println("Ascend long tag vsa: \n" + vs); } /** * Run the examples. */ public static void main(String a[]) { try { VSExamples g = new VSExamples(); new Cisco(); new Ascend(); new A(); g.go(); } catch (Exception e) { e.printStackTrace(); } } private void go() throws Exception { longTags(); } }