loader.generate(reader,authFile.toURI(),new ItemDestination() {
public void send(Item item)
throws XMLException
{
if (item.getType()==Item.ItemType.ElementItem) {
Element e = (Element)item;
if (e.getName().equals(AdminXML.NM_USER)) {
String alias = e.getAttributeValue("alias");
if (alias==null) {
LOG.warning("Missing 'alias' attribute on user.");
return;
}
String uuid = e.getAttributeValue("id");
if (uuid==null) {
LOG.warning("Missing 'id' attribute on user.");
return;
}
String password = e.getAttributeValue("password");
if (password==null) {
password = e.getAttributeValue("md5-password");
} else {
try {
password = User.md5Password(password);
} catch (NoSuchAlgorithmException ex) {
throw new XMLException("Cannot MD5 password.",ex);
}
}
if (password==null) {
LOG.warning("Missing 'md5-password' or 'password' attribute on user.");
return;
}
String name = e.getAttributeValue("name");
if (name==null) {
name = alias;
}
String email = e.getAttributeValue("email");
LOG.fine(alias+","+uuid+","+name+","+email);
String groupsSpec = e.getAttributeValue("groups");
List<String> groupList = new ArrayList<String>();
if (groupsSpec!=null) {
String [] groupStrings = groupsSpec.split(",");
for (int i=0; i<groupStrings.length; i++) {
String group = groupStrings[i].trim();
if (group.length()!=0 && groups.get(group)!=null) {
LOG.fine(alias+": "+group);
groupList.add(group);
}
}
}
User u = new User(alias,UUID.fromString(uuid),name,email,groupList);
users.put(alias,u);
passwords.put(alias,password);
} else if (e.getName().equals(AdminXML.NM_GROUP)) {
String name = e.getAttributeValue("name");
if (name!=null) {
groups.put(name,name);
}
}
}