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.3: The isValidUser and isValidGroup methods

5.2.2.2.3: The isValidUser and isValidGroup methods

The isValidUser and isValidGroup methods are used to determine whether a provided user or group name appears in the registry. The implementations of both methods must check that the name supplied as an argument appears in the registry as the name of a user or group and return either a value of TRUE if the name appears or FALSE if it doesn't. WebSphere Application Server expects both the isValidUser and isValidGroup methods to throw the CustomRegistryException exception in case of any problems.

To validate users and groups against the sample registry, each method iterates through the entries in the appropriate file and examines the value in the field for the user or group name. When a match is found, the method stops looking and returns a TRUE value. If the entire file is traversed without a match, the method returns a FALSE value. Figure 7 shows the isValidUser method--and the structure of the isValidGroup method--as implemented in the FileRegistrySample class. The only difference between the two methods is the file over which they iterate.

Figure 7. Code example: The isValidUser and isValidGroup methods in the FileRegistrySample class

public boolean isValidUser(String userName)
throws CustomRegistryException
{
String s;
boolean isValid = false;
BufferedReader in = null;

try {
in = fileOpen(USERFILENAME);
while ((s=in.readLine())!=null) {
if (!s.startsWith("#")) {
int index = s.indexOf(":");
 if ((s.substring(0,index)).equals(userName)) {
 isValid=true;
break;
}
}
}
}
catch (Exception ex) {
throw new CustomRegistryException(ex.getMessage());
}
finally {
fileClose(in);
}
return isValid;
}

public boolean isValidGroup(String userName)
throws CustomRegistryException
{
String s;
boolean isValid = false;
BufferedReader in = null;
try {
in = fileOpen(GROUPFILENAME);
...
}
catch (Exception ex) { ... }
finally { ... }

return isValid;
}

Go to previous article: getRealm and initialize methods Go to next article: The getUsers and getGroups methods

 

 
Go to previous article: getRealm and initialize methods Go to next article: The getUsers and getGroups methods