/**
   * Update the map-elements in the datasource that are below <i>parent</i>.
   *
   * @param parent Parent element to add / update
   * @param configuration configuration that holds the properties
   * @param mapName the name of the map-property in the configuration that holds the elements
   * @param propertyElementName the name of the element to write below <i>parent</i>
   */
  private static void updateMap(
      Element parent, Configuration configuration, String mapName, String propertyElementName) {
    PropertyMap map = configuration.getMap(mapName);
    // Wrap in ArrayList to avoid ConcurrentModificationException when adding or removing children
    // while iterating.
    List<Element> mapElements = new ArrayList<Element>(parent.getChildren(propertyElementName));

    if ((map == null) || map.getMap().isEmpty()) {
      if (!mapElements.isEmpty()) {
        parent.removeChildren(propertyElementName);
      }

      return;
    }

    Map<String, Element> elements = new HashMap<String, Element>();
    for (Element el : mapElements) {
      elements.put(el.getAttributeValue("name"), el);
      if (map.get(el.getAttributeValue("name")) == null) {
        parent.removeContent(el);
      }
    }

    for (Property prop : map.getMap().values()) {
      Element element = elements.get(prop.getName());
      if (element == null) {
        element = new Element(propertyElementName);
        element.setAttribute("name", prop.getName());
        parent.addContent(element);
      }

      element.setText(((PropertySimple) prop).getStringValue());
    }
  }
Exemplo n.º 2
0
  @Override
  public CreateResourceReport createResource(CreateResourceReport report) {

    if (report.getPackageDetails() != null) { // Content deployment
      return deployContent(report);
    } else {
      report.setStatus(CreateResourceStatus.INVALID_CONFIGURATION);
      Address createAddress = new Address(address);
      createAddress.add(
          report.getPluginConfiguration().getSimpleValue("path", ""),
          report.getUserSpecifiedResourceName());
      Operation op = new Operation("add", createAddress);
      for (Property prop : report.getResourceConfiguration().getProperties()) {
        if (prop instanceof PropertySimple) {
          PropertySimple ps = (PropertySimple) prop;
          String value = ps.getStringValue();
          op.addAdditionalProperty(prop.getName(), value);
        }
        // TODO more types
      }
      Result result = getASConnection().execute(op);
      if (result.isSuccess()) {
        report.setStatus(CreateResourceStatus.SUCCESS);
        report.setResourceKey(address.getPath());
        report.setResourceName(report.getUserSpecifiedResourceName());
      } else {
        report.setStatus(CreateResourceStatus.FAILURE);
        report.setErrorMessage(result.getFailureDescription());
      }
    }
    return report;
  }
Exemplo n.º 3
0
 public static void convertConfigurationToManagedProperties(
     Map<String, ManagedProperty> managedProperties,
     Configuration configuration,
     ResourceType resourceType,
     Map<String, PropertySimple> customProps) {
   ConfigurationDefinition configDefinition = resourceType.getResourceConfigurationDefinition();
   Set<String> missingManagedPropertyNames = new HashSet<String>();
   for (Property property : configuration.getProperties()) {
     String propertyName = property.getName();
     ManagedProperty managedProperty = managedProperties.get(propertyName);
     PropertyDefinition propertyDefinition = configDefinition.get(propertyName);
     if (managedProperty == null) {
       // NOTE: We expect the Profile Service to always return templates that contain *all*
       // ManagedProperties
       //       that are defined for the ComponentType, so this is considered an error. We could
       // build a
       //       ManagedProperty from scratch based on only a PropertyDefinition anyway, since a
       // propDef could
       //       map to multiple different types of MetaValues (e.g. a PropertyList could
       // potentially map to
       //       either an ArrayValue or a CollectionValue).
       missingManagedPropertyNames.add(propertyName);
     } else {
       populateManagedPropertyFromProperty(
           property, propertyDefinition, managedProperty, customProps.get(propertyName));
     }
     if (!missingManagedPropertyNames.isEmpty())
       throw new IllegalStateException(
           "***** The following properties are defined in this plugin's "
               + "descriptor but have no corresponding ManagedProperties: "
               + missingManagedPropertyNames);
   }
   return;
 }
  public void configurationMembersSwappedAndKeptPositions() {
    Configuration testConfig = getFreshConfig();

    // keep track of the order of the properies in the original map
    PropertyMap originalMap =
        (PropertyMap) testConfig.getList("topLevelListOfMaps").getList().get(0);
    List<Property> originalMapPropertiesInOrder =
        new ArrayList<Property>(originalMap.getMap().values());

    PasswordObfuscationUtility.obfuscatePasswords(DEFINITION, testConfig);

    PropertyList list = testConfig.getList("topLevelListOfMaps");

    PropertyMap map = (PropertyMap) list.getList().get(0);

    Assert.assertTrue(
        map.get("password") instanceof ObfuscatedPropertySimple,
        "The password in the map failed to be swapped to obfuscated form");

    // now check that the positions in the map actually didn't change
    List<Property> mapPropertiesInOrder = new ArrayList<Property>(map.getMap().values());

    Assert.assertEquals(
        mapPropertiesInOrder.size(),
        originalMapPropertiesInOrder.size(),
        "Different number of properties in the map after obfuscation");

    for (int i = 0; i < mapPropertiesInOrder.size(); ++i) {
      Property originalProp = originalMapPropertiesInOrder.get(i);
      Property prop = mapPropertiesInOrder.get(i);

      Assert.assertEquals(
          prop.getName(),
          originalProp.getName(),
          "Properties seem to be mixed up after obfuscation");
    }
  }