break;
}
final Set<Attribute> required = EnumSet.of(Attribute.ROLES_ATTR_NAME, Attribute.TYPE_ATTR_NAME);
List<String> roles = null;
AttributeDefinition perm = null;
final int count = reader.getAttributeCount();
for (int i = 0; i < count; i++) {
requireNoNamespaceAttribute(reader, i);
final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
required.remove(attribute);
switch (attribute) {
case ROLES_ATTR_NAME:
roles = parseRolesAttribute(reader, i);
break;
case TYPE_ATTR_NAME:
perm = SecurityRoleDefinition.ROLE_ATTRIBUTES_BY_XML_NAME.get(reader.getAttributeValue(i));
if (perm == null) {
throw ControllerMessages.MESSAGES.invalidAttributeValue(reader.getAttributeValue(i),
reader.getAttributeName(i), SecurityRoleDefinition.ROLE_ATTRIBUTES_BY_XML_NAME.keySet(),
reader.getLocation());
}
break;
default:
throw ParseUtils.unexpectedAttribute(reader, i);
}
}
if (!required.isEmpty()) {
throw missingRequired(reader, required);
}
for (String role : roles) {
role = role.trim();
Set<AttributeDefinition> perms = permsByRole.get(role);
if (perms == null) {
perms = new HashSet<AttributeDefinition>();
permsByRole.put(role, perms);
}
perms.add(perm);
}
// Scan to element end
reader.discardRemainder();
} while (reader.hasNext());
for (Map.Entry<String, Set<AttributeDefinition>> entry : permsByRole.entrySet()) {
final String role = entry.getKey();
final Set<AttributeDefinition> perms = entry.getValue();
final ModelNode addr = address.clone();
addr.add(ROLE, role);
final ModelNode operation = new ModelNode();
operation.get(OP).set(ADD);
operation.get(OP_ADDR).set(addr);
for (AttributeDefinition perm : SecurityRoleDefinition.ATTRIBUTES) {
operation.get(perm.getName()).set(perms.contains(perm));
}
operations.add(operation);
}
}