// Get the filename and parse the xml doc
String realmFileName = args.get(FILE_NAME_ARGUMENT) == null ? DEFAULT_FILE_NAME
: (String) args.get(FILE_NAME_ARGUMENT);
File realmFile = new File(realmFileName);
if (!realmFile.exists())
throw new WinstoneException(REALM_RESOURCES.getString(
"FileRealm.FileNotFound", realmFile.getPath()));
try {
InputStream inFile = new FileInputStream(realmFile);
Document doc = this.parseStreamToXML(inFile);
inFile.close();
Node rootElm = doc.getDocumentElement();
for (int n = 0; n < rootElm.getChildNodes().getLength(); n++) {
Node child = rootElm.getChildNodes().item(n);
if ((child.getNodeType() == Node.ELEMENT_NODE)
&& (child.getNodeName().equals(ELEM_USER))) {
String userName = null;
String password = null;
String roleList = null;
// Loop through for attributes
for (int j = 0; j < child.getAttributes().getLength(); j++) {
Node thisAtt = child.getAttributes().item(j);
if (thisAtt.getNodeName().equals(ATT_USERNAME))
userName = thisAtt.getNodeValue();
else if (thisAtt.getNodeName().equals(ATT_PASSWORD))
password = thisAtt.getNodeValue();
else if (thisAtt.getNodeName().equals(ATT_ROLELIST))
roleList = thisAtt.getNodeValue();
}
if ((userName == null) || (password == null)
|| (roleList == null))
Logger.log(Logger.FULL_DEBUG, REALM_RESOURCES,
"FileRealm.SkippingUser", userName);
else {
// Parse the role list into an array and sort it
StringTokenizer st = new StringTokenizer(roleList, ",");
List rl = new ArrayList();
for (; st.hasMoreTokens();) {
String currentRole = st.nextToken();
if (rolesAllowed.contains(currentRole))
rl.add(currentRole);
}
Object roleArray[] = rl.toArray();
Arrays.sort(roleArray);
this.passwords.put(userName, password);
this.roles.put(userName, Arrays.asList(roleArray));
}
}
}
Logger.log(Logger.DEBUG, REALM_RESOURCES, "FileRealm.Initialised",
"" + this.passwords.size());
} catch (java.io.IOException err) {
throw new WinstoneException(REALM_RESOURCES
.getString("FileRealm.ErrorLoading"), err);
}
}