List of usage examples for org.apache.commons.configuration FileConfiguration getList
List getList(String key);
From source file:org.glite.slcs.acl.impl.XMLFileAccessControlList.java
/** * Creates a list of {@link AccessControlRule}s loaded from the * {@link FileConfiguration}./*from w w w.ja v a 2 s .c om*/ * * @param config * The ACL FileConfiguration object * @return A {@link List} of {@link AccessControlRule}s */ static private List createACLAccessControlRules(FileConfiguration config) { List accessControlRules = new LinkedList(); // list all rules int i = 0; while (true) { String rulePrefix = "AccessControlRule(" + i + ")"; i++; // get the name and id of the rule String ruleGroup = config.getString(rulePrefix + "[@group]"); if (ruleGroup == null) { if (LOG.isDebugEnabled()) { LOG.debug(rulePrefix + ": no more rules"); } // no more ACL rule to read, exit while loop break; } int ruleId = config.getInt(rulePrefix + "[@id]"); // create an empty rule AccessControlRule rule = new AccessControlRule(ruleId, ruleGroup); // get the attributes name-value for the rule List attributeNames = config.getList(rulePrefix + ".Attribute[@name]"); if (attributeNames.isEmpty()) { LOG.error(rulePrefix + ": no attribute in rule, skipping..."); // error, skipping continue; } AttributeDefinitions attributeDefinitions = AttributeDefinitionsFactory.getInstance(); List attributeValues = config.getList(rulePrefix + ".Attribute"); for (int j = 0; j < attributeNames.size(); j++) { String name = (String) attributeNames.get(j); String value = (String) attributeValues.get(j); Attribute attribute = attributeDefinitions.createAttribute(name, value); // add attribute to the rule rule.addAttribute(attribute); } // add the rule to the list if (LOG.isDebugEnabled()) { LOG.debug("adding rule in ACL: " + rule); } accessControlRules.add(rule); } // while return accessControlRules; }
From source file:org.glite.slcs.group.impl.XMLFileGroupManager.java
/** * Creates the list of groups defined in the FileConfiguration. * /*from w w w .j av a 2 s. c o m*/ * @param config * The FileConfiguration object. * @return The list of {@link Group}s. */ static private List createGroups(FileConfiguration config) { // get the attribute definition helper for the attribute display name SLCSServerConfiguration slcsConfig = SLCSServerConfiguration.getInstance(); AttributeDefinitions attributeDefinitions = slcsConfig.getAttributeDefinitions(); // create an empty groups list List groups = new LinkedList(); // list all groups int i = 0; boolean moreGroup = true; while (moreGroup) { String groupPrefix = "Group(" + i + ")"; i++; // get the name of the group String groupName = config.getString(groupPrefix + "[@name]"); if (groupName != null) { // create an empty named group Group group = new Group(groupName); // list all members of this group int j = 0; boolean moreMember = true; while (moreMember) { String memberPrefix = groupPrefix + ".GroupMember(" + j + ")"; j++; // get the attributes name and value for the group member List attributeNames = config.getList(memberPrefix + ".Attribute[@name]"); if (!attributeNames.isEmpty()) { // create an empty member GroupMember member = new GroupMember(); List memberAttributes = new ArrayList(); // list and add the membership attributes List attributeValues = config.getList(memberPrefix + ".Attribute"); for (int k = 0; k < attributeNames.size(); k++) { String name = (String) attributeNames.get(k); String value = (String) attributeValues.get(k); Attribute attribute = attributeDefinitions.createAttribute(name, value); // add attribute to the group membership attributes // list memberAttributes.add(attribute); } // set the membership attributes list member.setAttributes(memberAttributes); // and add the member to the group group.addGroupMember(member); } else { moreMember = false; if (LOG.isDebugEnabled()) { LOG.debug(memberPrefix + ": no more group members"); } } } // while all members // get all constrained attributes for the group ACL rules String constraintPrefix = groupPrefix + ".AccessControlRuleConstraint"; // get the attributes name and value for the group ACL rule // constraint List attributeNames = config.getList(constraintPrefix + ".Attribute[@name]"); if (!attributeNames.isEmpty()) { List constrainedAttributes = new ArrayList(); // list and add the ACL rule attributes constraints List attributeValues = config.getList(constraintPrefix + ".Attribute"); for (int k = 0; k < attributeNames.size(); k++) { String name = (String) attributeNames.get(k); String value = (String) attributeValues.get(k); Attribute attribute = attributeDefinitions.createAttribute(name, value); // add attribute constraint list attribute.setConstrained(true); constrainedAttributes.add(attribute); } // set the group ACL rule constraint group.setRuleAttributesConstraint(constrainedAttributes); } // add the group to the groups list // TODO: check for group without members groups.add(group); } else { moreGroup = false; if (LOG.isDebugEnabled()) { LOG.debug(groupPrefix + ": no more groups"); } } } // while all groups return groups; }