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.5: The getUniqueUserId and getUniqueGroupId methods

5.2.2.2.5: The getUniqueUserId and getUniqueGroupId methods

The getUniqueUserId and getUniqueGroupId methods allow the retrieval of a unique identifier for a named user or group.

WebSphere Application Server expects the methods to throw the EntryNotFoundException exception if the user or group name does not exist in the registry and to throw the CustomRegistryException exception for any other conditions.

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

Figure 10. Code example: The getUniqueUserId and getUniqueGroupId methods in the FileRegistrySample class

public String getUniqueUserId(String userName)
throws CustomRegistryException, EntryNotFoundException
{
String s, uniqueUsrId = 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);
if ((s.substring(0,index)).equals(userName)) {
int index2 = s.indexOf(":", index1+1);
uniqueUsrId = s.substring(index1+1,index2);
break;
}
}
}
}
catch(Exception ex) {
throw new CustomRegistryException(ex.getMessage());
}
finally {
fileClose(in);
}

if (uniqueUsrId == null) {
EntryNotFoundException nsee =
new EntryNotFoundException(userName);
throw nsee;
}

return uniqueUsrId;
}

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

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

return uniqueGrpId;
}

Go to previous article: The getUsers and getGroups methods Go to next article: The getUserSecurityName and getGroupSecurityName methods

 

 
Go to previous article: The getUsers and getGroups methods Go to next article: The getUserSecurityName and getGroupSecurityName methods