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.6: The getUserSecurityName and getGroupSecurityName methods

5.2.2.2.6: The getUserSecurityName and getGroupSecurityName methods

The getUserSecurityName and getGroupSecurityName methods allow the retrieval of the name of a user or group from a unique identifier.

WebSphere Application Server expects the methods to throw the EntryNotFoundException exception if the unique identifier does not exist in the registry and to throw the CustomRegistryException exception for any other conditions.

Figure 11 shows the implementation of the getUserSecurityName method for the example registry. The method iterates through the user-information file and attempts to locate an entry with the specified UID. If the UID is located, the corresponding name field is extracted and returned. If the UID is not found, the EntryNotFoundException exception is thrown. The getGroupSecurityName method does the same work on the group-information file.

Figure 11. Code example: The getUserSecurityName and getGroupSecurityName methods in the FileRegistrySample class

public String getUserSecurityName(String uniqueId)
throws CustomRegistryException, EntryNotFoundException
{
String s, usrSecName = null;
BufferedReader in = null;

try {
in = fileOpen(USERFILENAME);

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

if (usrSecName == null) {
EntryNotFoundException ex =
new EntryNotFoundException(uniqueId);
}

return usrSecName;
}

public String getGroupSecurityName(String uniqueId)
throws CustomRegistryException, EntryNotFoundException
{
String s, grpSecName = null;
BufferedReader in = null;

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

return grpSecName;
}

Go to previous article: The getUniqueUserId and getUniqueGroupId methods Go to next article: The getUserDisplayName and getGroupDisplayName methods

 

 
Go to previous article: The getUniqueUserId and getUniqueGroupId methods Go to next article: The getUserDisplayName and getGroupDisplayName methods