예제 #1
0
 private Element getSecurityContraintsElement() {
   Element securityContraints = new Element(SECURITY_CONSTRAINTS);
   List allGroupRules = mSecurityConstraints.getAllGroupRules();
   for (int i = 0; i < allGroupRules.size(); i++) {
     GroupRules groupRules = (GroupRules) allGroupRules.get(i);
     List rules = groupRules.getRules();
     if (rules.size() == 0) {
       continue;
     }
     Element groupRulesElement = new Element(GROUP_RULES);
     groupRulesElement.setAttribute(GROUP, groupRules.getGroupName());
     for (int j = 0; j < rules.size(); j++) {
       RuleDescription ruleDescription = (RuleDescription) rules.get(j);
       Element ruleElement;
       if (ruleDescription.getType() == RuleDescription.INCLUDE) {
         ruleElement = new Element(INCLUDE_RULE);
       } else {
         ruleElement = new Element(EXCLUDE_RULE);
       }
       ruleElement.setAttribute(RESOURCE, ruleDescription.getResource());
       ruleElement.setAttribute(CLASS, ruleDescription.getRetsClass());
       String systemNames = StringUtils.join(ruleDescription.getSystemNames().iterator(), " ");
       Element systemNamesElement = new Element(SYSTEM_NAMES);
       systemNamesElement.setText(systemNames);
       ruleElement.addContent(systemNamesElement);
       groupRulesElement.addContent(ruleElement);
     }
     securityContraints.addContent(groupRulesElement);
   }
   return securityContraints;
 }
예제 #2
0
 private static void elementToSecurityConstraints(Element element, RetsConfig config) {
   if (element == null) {
     config.setSecurityConstraints(new ArrayList());
     return;
   }
   List securityConstraints = new ArrayList();
   List children = element.getChildren(GROUP_RULES);
   for (int i = 0; i < children.size(); i++) {
     Element child = (Element) children.get(i);
     String groupName = child.getAttributeValue(GROUP);
     GroupRules groupRules = new GroupRules(groupName);
     List grandChildren = child.getChildren();
     for (int j = 0; j < grandChildren.size(); j++) {
       Element grandChild = (Element) grandChildren.get(j);
       RuleDescription ruleDescription = new RuleDescription();
       if (grandChild.getName().equals(INCLUDE_RULE)) {
         ruleDescription.setType(RuleDescription.INCLUDE);
       } else if (grandChild.getName().equals(EXCLUDE_RULE)) {
         ruleDescription.setType(RuleDescription.EXCLUDE);
       } else {
         LOG.warn("Unknown rule" + grandChild.toString());
         continue;
       }
       ruleDescription.setResource(grandChild.getAttributeValue(RESOURCE));
       ruleDescription.setRetsClass(grandChild.getAttributeValue(CLASS));
       String systemNamesText = grandChild.getChildTextNormalize(SYSTEM_NAMES);
       String[] systemNamesArray = StringUtils.split(systemNamesText, " ");
       ruleDescription.setSystemNames(Arrays.asList(systemNamesArray));
       groupRules.addRule(ruleDescription);
     }
     securityConstraints.add(groupRules);
   }
   config.setSecurityConstraints(securityConstraints);
 }
예제 #3
0
 public void addRules(GroupRules rules) {
   List allRules = rules.getRules();
   String groupName = rules.getGroupName();
   for (int i = 0; i < allRules.size(); i++) {
     RuleDescription ruleDescription = (RuleDescription) allRules.get(i);
     String tableKey = ruleDescription.getResource() + ":" + ruleDescription.getRetsClass();
     String rulesKey = groupName + ":" + tableKey;
     Set tables = (Set) mAllTables.get(tableKey);
     Set filteredTables = new HashSet();
     for (Iterator iterator = tables.iterator(); iterator.hasNext(); ) {
       Table table = (Table) iterator.next();
       if (ruleDescription.includeSystemName(table.getSystemName())) {
         filteredTables.add(table);
       }
     }
     mRules.put(rulesKey, filteredTables);
   }
 }