|
|
Because you enable page extensions on a per-locale basis, you can use different Java classes for each locale in a given CSRC installation.
This chapter describes the different Java classes and provides a step-by-step example of creating a page extension.
Page extensions use defined Java interfaces to control the affect of the subscriber's self-provisioning experience. These interfaces allow you to determine the appropriate locale to present to the subscriber, and help the user choose a user name or host name. You can also use these interfaces to allow the user to skip some of the User Registrar Subscriber pages.
When a new subscriber connects to User Registrar Subscriber, the locale for the subscriber is undetermined. If you have not enabled any other logic, User Registrar uses the global default locale.
The Locale Lookup page extension code takes effect before any other page is executed including the select_locale page. While the select_locale page allows the user to select a locale, the select_locale template still needs to be accessed from one of the locales making the locale lookup critical to proper behavior. For more information about the select_locale page, see the "Subscriber Selection of a Locale" section.
Example 5-1 shows the ILocaleLookup interface.
ILocaleLookup Java Interface
public interface com.cisco.csrc.ursub.ILocaleLookup
{
public String getLocale(String computerIP, String modemIP);
}
For example, if the getLocale() method determines that the English language should be used, the string returned would be en. If this method returns an illegal or unknown locale name, the behavior is the same as if it had returned null.
Example 5-2 shows a sample ILocaleLookup class.
public class SampleLocaleLookup
implements com.cisco.csrc.ursub.ILocaleLookup
{
public String getLocale(String computerIP, String modemIP)
{
// check if this is the university subnet.
if (modemIP.startsWith("123.123."))
return "University";
// if no particular locale is found, use the default.
return null;
}
}
This example class determines if the subscriber is accessing User Registrar Subscriber from a university subnet. If it is, User Registrar uses the University locale, otherwise the class instructs User Registrar to display the default locale.
![]() | Tips While the class could return en (or whatever the configured default is) by returning null, the code leaves the default behavior controlled in User Registrar Administrator and thereby does not require a code change if the locale default is changed. |
When a subscriber first accesses User Registrar Subscriber, the first page displayed is select_locale if multiple locales and the Use Select Locale options are enabled.The Locale Choices page extension allows you to display a subset of available locales. For example, residential customers should only be given the choice between Residential_English and Residential_Spanish even though University is also a valid locale.The Locale Choices page extension allows you to limit the choices for the residential subscribers to the two desired locales.
Example 5-3 shows the ILocaleChoices interface.
ILocaleChoices Java Interface
public interface com.cisco.csrc.ursub.ILocaleChoices
{
public String[] getLocaleChoices(String computerIP, String modemIP);
}
This class returns null if all the locales should be displayed to the subscriber, otherwise it returns a string array containing a list of locale names to be presented. User Registrar ignores the names on the list that are not in the system's locale list.
Example 5-4 shows a sample ILocaleChoices class. It limits the available locales to Residential_English and Residential_Spanish. The assumption is that the LocaleLookup page extension has already defined that this is a residential subscriber.
public class ResidentialLocaleChoices
implements com.cisco.csrc.ursub.ILocaleChoices
{
public String[] getLocale(String computerIP, String modemIP)
{
return new String[]
{ "Residential_English", "Residential_Spanish" };
}
}
When a subscriber begins the self-registration process, User Registrar displays the choose_username page. This page prompts the subscriber for a username and password. You can use the Username Lookup page extension to offer a suggestion for a username and password. For example, subscribers' username and password may correspond to their account number and PIN.
![]() | Tips Enabling a Username Lookup page extension that defaults the username and password to the respective values and then enabling Skip username selection, causes User Registrar to skip the choose_username page and thus, subscribers need know only their account number and PIN for initial registration and account maintenance. |
Example 5-5 shows the IUsernameLookup interface.
public interface com.cisco.csrc.ursub.IUsernameLookup
{
public String[] getUsername(
ICWAFObject accountobj, ICWAFObject subscriberobj,
ICWAFObject modemobj, ICWAFObject computerobj);
}
Example 5-6 shows a sample IUsernameLookup class.
public class SampleUsernameLookup
implements com.cisco.csrc.ursub.IUsernameLookup
{
public String[] getUsername(
ICWAFObject accountobj, ICWAFObject subscriberobj,
ICWAFObject modemobj, ICWAFObject computerobj)
{
// build a string array for the results.
String values[] = new String[2];
// populate the account number and PIN in the array.
values[0] = accountobj.getAttr("AccountNumber");
values[1] = accountobj.getAttr("PIN");
// return the values.
return values;
}
}
This sample class returns the account number and PIN of the subscriber as suggestions for the username and password. If User Registrar cannot find an appropriate suggestion, the code returns null.
You can call the getAttr() method on any of the input objects and it can access any of the attributes listed in the application schema. For multivalued attributes, use getAttrList() which returns a string array of values. Both getAttr() and getAttrList() return null if the object does not have the desired value set. Calling getAttr() or getAttrList() on an invalid attribute causes a Java exception to be thrown. If you are unfamiliar with exception catching, review a standard Java reference manual.
When the subscriber clicks Accept on the choose_username page, you can have the Username Check page extension perform additional validation and uniqueness checking on the supplied values.
For example, you could use the Username Check page extension to verify username uniqueness in an external e-mail server or you could use this page extension to provide a textual message containing a list of suggestions for alternative usernames.
Example 5-7 shows the IUsernameCheck interface.
public interface com.cisco.csrc.ursub.IUsernameCheck
{
public String isValidUsername(String username);
}
Example 5-8 shows a sample IUserCheck class.
public class SampleIUsernameCheck
implements com.cisco.csrc.ursub.IUsernameCheck
{
public String isValidUsername(String username)
{
// check if the username is valid.
if (username.equalsIgnoreCase("root") ||
username.equalsIgnoreCase("webmaster"))
return "You may not select '"+username+"' as a username.";
// if the username passed all the checks, return null.
return null;
}
}
This sample class checks for certain special usernames and ensures that they are not selected. If a reserved name is selected, the code returns an error message explaining that the selected username is not available. When the username passes all of the checks, the code returns null to allow the subscriber to select the desired username.
The activate_device page prompts subscribers for a hostname and description for their computer. You can use the Hostname Lookup page extension to offer a suggestion for a username and password. In addition, if you have enabled the Skip hostname selection, you must use the Hostname Lookup page extension because it is the only way to provide a hostname and description for a subscriber's computer.
For example, you could use the Hostname Lookup page extension to automatically generate a hostname from the computer's MAC address.
![]() | Tips By enabling a page extension that defaults the hostname and password to their respective values and then enabling Skip hostname selection, you could have subscribers skip the entire activate_device section and the subscriber would not need to understand what choosing a computer name means. |
Example 5-9 show the IHostname Lookup interface.
public interface com.cisco.csrc.ursub.IHostnameLookup
{
public STring[] getHostname(
ICWAFObject accountobj, ICWAFObject subscriberobj,
ICWAFObject modemobj, ICWAFObject computerobj);
}
Example 5-10 shows a sample IHostname Lookup class.
public class SampleHostnameLookup
implements com.cisco.csrc.ursub.IHostnameLookup
{
public String[] getHostname(
ICWAFObject accountobj, ICWAFObject subscriberobj,
ICWAFObject modemobj, ICWAFObject computerobj)
{
// build a string array for the results.
String values[] = new String[2];
// populate the hostname and description in the array.
values[0] = "comp-"+prepareHostname(modemobj.getAttr("MACAddress"));
values[1] = "acc-"+accountobj.getAttr("AccountNumber");
}
// simple helper method that strips out illegal characters
public String prepareHostname(String macaddr)
{
// create a buffer to use when stripping out the bad characters.
StringBuffer work = new StringBuffer();
// check each character in the mac address.
for (int i=0; i<macaddr.length(); i++)
{
// check if this is a valid character.
char c = macaddr.charAt(i);
switch (c)
{
// check for illegal hostname characters.
case ':': break;
case ',': break;
// if it isn't a bad character, add to the hostname.
default: buf.append(c);
}
}
// return the processed string.
return work.toString();
}
}
This sample class returns a generated hostname and description that is based on the current computer's MAC address and subscriber's account number. The hostname is the MAC address with any illegal characters removed. The description is the account number of the subscriber. The getAttr() method can be called on any of the input objects and can access the attributes listed in the application schema.
When a subscriber clicks Accept on the activate_device or update_device pages, you can have the Hostname Check page extension perform additional validation and uniqueness checking on the supplied values.
For example, you could use the Hostname Check page extension to verify hostname uniqueness in an external name server or have it provide a textual message containing a list of suggestions for alternative hostnames.
Example 5-11 shows the IHostnameCheck interface.
public interface com.cisco.csrc.ursub.IHostnameCheck
{
public String isValidHostname(String hostname);
}
![]() | Tips You could use the IHostname Check page extension to check for profanity in the hostnames and then, when detected, return a message stating that the hostname is inappropriate. |
Example 5-12 shows a sample IHostname Check class.
public class SampleHostnameCheck
implements com.cisco.csrc.ursub.IHostnameCheck
{
public String isValidHostname(String hostname)
{
// check if the hostname is valid.
if (hostname.equalsIgnoreCase("www") ||
hostname.equalsIgnoreCase("mail"))
return "You may not select '"+hostname+"' as a computer name.";
// if the hostname passed all the checks, return null.
return null;
}
}
This sample class checks for certain special hostnames and ensures that they are not selected. If a reserved name is selected, the code returns an error message explaining that the selected hostname is not available. When the hostname passes all of the checks, the code returns null to allow the subscriber to select the desired hostname.
For example, the Username Check page extension is used to provide additional username uniqueness checking when subscribers are registering with the system. The Java interface contains a single method isValidUsername() that determines whether a username is available. When developing page extensions, you must compile a new Java class for each instance.
To compile and enable a page extension, do the following:
1. Install the Java Development Kit (first-time only)
(a) Download the Java Development Kit (JDK) 1.1.x from Sun Microsystems.
http://www.javasoft.com/products/jdk/1.1/
(b) Follow the instructions included with the JDK to install the Java compiler.
2. Write the new page extension.
(a) Determine the name of your Java class.
For example, if you were writing a page extension for username uniqueness as it pertains to an external e-mail system, ExternalEmailUsernameCheck might be an appropriate name. This class name should contain only alphanumeric characters and cannot include spaces.
(b) Create a new file in the csrc/classes/csrc-ur-sub directory called XXXX.java where XXXX is identical to the name of your Java class. In the above case, the file name would be ExternalEmailUsernameCheck.java.
(c) Look up the interface for the appropriate page extension to check what the appropriate call to support is.
(d) Edit the newly created .java file and write a skeleton for the appropriate interface.
To do this, you must create a class for the page extension by having your new class implement the desired interface. In this instance, the .java file should look like the following:
public class ExternalEmailUsernameCheck
implements com.cisco.csrc.ursub.IUsernameCheck
{
public String isValidUsername(String username)
{
// write your logic here!
}
}
(e) Finish writing the page extension by filling in the method body (the "write your logic here" section in the example above).
3. Compile the new page extension.
(a) Verify where the Java compiler is located. Typically, it will be named javac in a bin directory under the main JDK directory.
A common installation location is c:\jdk1.1.8\bin\javac.
(b) Change to the csrc/classes/csrc-ur-sub directory in a console window.
cd /opt/csrc/classes/csrc-ur-sub
(c) Execute the Java compiler on the new Java class you have developed.
Solaris (on one line):
/opt/java/bin/javac -classpath ../cwaf.jar:. ExternalEmailUsernameCheck.java
(d) WinNT (on one line):
c:\jdk1.1.8\bin\javac -classpath ..\cwaf.jar;. ExternalEmailUsernameCheck.java
(e) If any errors occur, edit the .java file and remedy the problem. Continue editing and compiling until the Java compiler generates no errors.
(f) Verify that the page extension was successfully compiled by checking that there is a new file with the .class extension. In this example, the file would be called ExternalEmailUsernameCheck.class.
4. Enable the page extension through User Registrar Administrator
(a) Log in to User Registrar Administrator.
(b) On the Home Page, click Defaults.
![]()
![]()
![]()
![]()
![]()
![]()
![]()
Posted: Tue Sep 26 04:43:05 PDT 2000
Copyright 1989-2000©Cisco Systems Inc.