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.9: The getUniqueUserIds and getUniqueGroupIds methods

5.2.2.2.9: The getUniqueUserIds and getUniqueGroupIds methods

The getUniqueUserIds and getUniqueGroupIds methods allow the retrieval of the unique identifiers for all members of a group and all the identifiers for the groups to which a user belongs. These methods are similar in function to the getGroupsForUser and getUsersForGroup methods; the difference is that these methods take unique identifiers are arguments and return lists of unique identifiers, and the getGroupsForUser and getUsersForGroup methods work with names. The similarly named getUniqueUserId and getUniqueGroupId methods also take user and group names are arguments.

WebSphere Application Server expects these methods to return null values if no matches are found, to throw the EntryNotFoundException exception if the requested user or group identifier does not exist in the registry, and to throw the CustomRegistryException exception for any other conditions.

Figure 14 shows the implementation of the getUniqueUserIds method for the example registry. The method iterates through the group-information file and attempts to locate an entry with the specified group identifier. If the identifier is located, the identifiers of all members are extracted and returned. If the group identifier is not found in the file, the EntryNotFoundException exception is thrown. The getUniqueGroupIds method does similar work on the user-information file.

Figure 14. Code example: The getUniqueUserIds and getUniqueGroupIds methods in the FileRegistrySample class

public List getUniqueUserIds(String uniqueGroupId)
throws CustomRegistryException,
EntryNotFoundException
{
String s = null;
List uniqueUserIds = new ArrayList();
BufferedReader in = null;

try {
in = fileOpen(GROUPFILENAME);
while ((s=in.readLine())!=null)
{
if (!s.startsWith("#")) {
int index = s.indexOf(":");
int index1 = s.indexOf(":", index+1);
if ((s.substring(index+1,index1)).equals(uniqueGroupId)) {
StringTokenizer st = new StringTokenizer(s, ":");
for (int i=0; i<2; i++)
st.nextToken();
String subs = st.nextToken();
StringTokenizer st1 = new StringTokenizer(subs, ",");
while (st1.hasMoreTokens())
uniqueUserIds.add(getUniqueUserId(st1.nextToken()));
break;
}
}
}
}
catch(Exception ex) {
throw new CustomRegistryException(ex.getMessage());
}
finally {
fileClose(in);
}

return uniqueUserIds;
}

public List getUniqueGroupIds(String uniqueUserId)
throws CustomRegistryException,
EntryNotFoundException
{
String s,uniqueGrpId = null;
List uniqueGrpIds=new ArrayList();
BufferedReader in = null;

try {
in = fileOpen(USERFILENAME);

while ((s=in.readLine())!=null)
{
...
}
}
catch(Exception ex) { ... }
finally { ... }

return uniqueGrpIds;
}

Go to previous article: The getGroupsForUser and getUsersForGroup methods Go to next article: The mapCertificate and checkPassword methods

 

 
Go to previous article: The getGroupsForUser and getUsersForGroup methods Go to next article: The mapCertificate and checkPassword methods