2.5 Localizing the Prompts in Your Authentication Class

You need to create a JSP page for displaying the login prompts. When doing so, you might want to allow the prompts to be displayed in multiple languages.

To enable the text so that it can be displayed in multiple languages, you need to do the following:

2.5.1 Creating a Properties File

You need to create a list of the strings to be displayed when prompting users for login credentials and reacting to their input. You need to create a string constant for each string and place the string constant and string in a properties file. The following properties file contains some sample string constants for a few of the prompts that your JSP page might need.

LOGIN=Login
USERNAME_PROMPT=Username:
CONTACT_ADMINISTRATOR_PROMPT=Contact your system administrator.
SAMPLE_AUTH_FAILED_MSG=Authentication Failed.
CONTINUE_PROMPT=Continue
CONTINUE_TITLE=Continue
LOGIN_ERROR_PROMPT=Authentication Error. 

The name for this properties file needs to end with the Java defined constants for each language. For the English version for use in the United States, the file would end with en_US.properties, for example, SampleResources_en_US.properties. The base portion of the name (in this example, SampleResources) stays the same for all languages.

You need to create such a file, with the appropriately translated strings and name, for each language you want to support.

2.5.2 Creating a Resource Class

You need to extend the com.novell.nidp.resource.NIDPResDesc class with a resource class that knows how to call your properties files and retrieve the strings. The following sample code extends the NIDPResDesc class with a class called SampleResDesc, defines the base name for the properties file (SampleResources), and defines a string constant for each string in the properties file.

#############need a package name line #####################
import com.novell.nidp.resource.NIDPResDesc;

public class SampleResDesc extends NIDPResDesc
{
    private static final String SAMPLE_BUNDLE_BASENAME =
                         "SampleResources";
    private static final String KEYS_PREFIX = "";
    
 // Names of localized strings and messages
 public static final String LOGIN = "LOGIN";
 public static final String USERNAME_PROMPT = "USERNAME_PROMPT";
 public static final String CONTACT_ADMINISTRATOR_PROMPT =
                              "CONTACT_ADMINISTRATOR_PROMPT";
 public static final String SAMPLE_AUTH_FAILED_MSG = 
                              "SAMPLE_AUTH_FAILED_MSG";
 public static final String CONTINUE_PROMPT = "CONTINUE_PROMPT";
 public static final String CONTINUE_TITLE = "CONTINUE_TITLE";
 public static final String LOGIN_ERROR_PROMPT = "LOGIN_ERROR_PROMPT"; 

 private static SampleResDesc m_instance = null;

    private SampleResDesc()
    {
        super(SAMPLE_BUNDLE_BASENAME, KEYS_PREFIX);
    }
    
    public static SampleResDesc getInstance()
    {
        if (null == m_instance)
        {
            m_instance = new SampleResDesc();|
        }
        return m_instance;
    }

}

2.5.3 Creating or Modifying a JSP Page

The JSP page generates the prompts for user credentials by calling your extended resource class to retrieve the strings. The following snippet of a JSP page gets the local language code, and then calls the extended resource class (SampleResDesc) to display the string for the string constant USERNAME_PROMPT.

.
.
.
<%@ page import="com.novell.nidp.*" %>
<%@ page import="com.novell.nidp.resource.*" %>
<%
      Locale locale = request.getLocale();
      String strLanguageCode = locale.getLanguage();
      String strLanguageCodeLowercase = strLanguageCode.toLowerCase();
      NIDPResource sampleResource = NIDPResourceManager.getInstance()
            .get(SampleResDesc.getInstance(), locale);
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//<%=strLanguageCode%>">
<html lang="<%=strLanguageCode%>">
.
.
.
<table>
     <tr>
           <td>
                  <label style="width: 100px"><%= sampleResource.
                   getString(SampleResDesc.USERNAME_PROMPT) %></label>
           </td>
           <td width="100%">
                  <input id="My_User_ID" type="text" class="smalltext"
                         name="My_User_ID" size="30">&nbsp;&nbsp;
                  <input alt="<%=sampleResource.getString0
                           (SampleResDesc.LOGIN)%>" 
                         border="0" name="loginButton" 
                         src="<%=request.getContextPath() %>/images/
                           <%=strLanguageCodeLowercase%>/
                             btnlogin_<%=strLanguageCodeLowercase%>.gif"
                         type="image" value="Login"
                         onclick="mySubmit()">
.
.
.

For your authentication class, this JSP snippet needs to be extended to include the prompts for the other authentication credentials your class requires. As you add prompts to the JSP page, these constants need to be added to your resource class and properties files.

The name of this JSP page needs to correspond to the page you call in your authentication class. See lines 109 - 111 in the sample class (Section 2.4.5, PasswordClass Example Code).

When you create the jar file for your authentication class, the properties files and the Java resource file need to be included. The JSP page for your authentication class needs to be added to the /opt/novell/nids/lib/webapp/jsp directory of Identity Server. For information about how to add a file, see Adding Configurations to a Cluster in the NetIQ Access Manager 5.0 Administration Guide.