InfoCenter Home >
5: Securing applications -- special topics >
5.2: Introduction to custom registries >
5.2.2: Implementing the CustomRegistry interface >
5.2.2.2: Writing the sample application >
5.2.2.2.7: The getUserDisplayName and getGroupDisplayName methods

5.2.2.2.7: The getUserDisplayName and getGroupDisplayName methods

The getUserDisplayName and getGroupDisplayName methods allow the retrieval of the display name, a descriptive field, associated with the name of a user or group. In the example registry, the annotation field is returned as the display name.

WebSphere Application Server expects the methods to throw the EntryNotFoundException exception if the specified user or group name is not found in the registry and to throw the CustomRegistryException exception for any other conditions. The display name is an optional value, so the methods must return NULL when no display name is found for named user or group.

Note   The getRemoteUser or getUserPrincipal method in a servlet or JSP, and the getCallerPrincipal method in an enterprise bean, also use the display name. These methods return the display name if one exists and the user name if a display name does not exist. Group display names are not an issue.

Figure 12 shows the implementation of the getUserDisplayName method for the example registry. The method calls the isValidUser method, described in Figure 7, to verify that the name appears in the registry. If it does not, the method throws the EntryNotFoundException exception. If the user name is valid, the corresponding annotation field is extracted and returned. The getGroupSecurityName method does the same work on the group-information file.

Figure 12. Code example: The getUserDisplayName and getGroupDisplayName methods in the FileRegistrySample class

public String getUserDisplayName(String userName)
throws CustomRegistryException, EntryNotFoundException
{
String s, displayName = null;
BufferedReader in = null;

if(!isValidUser(userName)) {
EntryNotFoundException nsee =
new EntryNotFoundException(userName);
throw nsee;
}

try {
in = fileOpen(USERFILENAME);

while ((s=in.readLine())!=null) {
if (!s.startsWith("#")) {
int index = s.indexOf(":");
int index1 = s.lastIndexOf(":");
if ((s.substring(0,index)).equals(userName)) {
displayName = s.substring(index1+1);
break;
}
}
}
}
catch(Exception ex) {
throw new CustomRegistryException(ex.getMessage());
}
finally {
fileClose(in);
}

return displayName;
}

public String getGroupDisplayName(String userName)
throws CustomRegistryException, EntryNotFoundException
{
String s,displayName = null;
BufferedReader in = null;

if(!isValidGroup(userName)) { ... }

try {
in = fileOpen(GROUPFILENAME);
...
}
catch(Exception ex) { ... }
finally { ... }

return displayName;
}

Go to previous article: The getUserSecurityName and getGroupSecurityName methods Go to next article: The getGroupsForUser and getUsersForGroup methods

 

 
Go to previous article: The getUserSecurityName and getGroupSecurityName methods Go to next article: The getGroupsForUser and getUsersForGroup methods