Esempio n. 1
0
  private void loadIdentity(final IaasProvider iaas, final OMElement iaasElt) {

    Iterator<?> it =
        iaasElt.getChildrenWithName(new QName(CloudControllerConstants.IDENTITY_ELEMENT));

    if (it.hasNext()) {
      OMElement identityElt = (OMElement) it.next();

      // retrieve the value using secure vault
      SecretResolver secretResolver = SecretResolverFactory.create(documentElement, false);
      String alias =
          identityElt.getAttributeValue(new QName(CloudControllerConstants.ALIAS_ATTRIBUTE));

      // retrieve the secured password
      if (secretResolver != null
          && secretResolver.isInitialized()
          && secretResolver.isTokenProtected(alias)) {

        iaas.setIdentity(secretResolver.resolve(alias));
      }

      // if we still cannot find a value, we try to assign the value which
      // is specified
      // in the element, if any
      if (iaas.getIdentity() == null) {
        log.warn(
            "Unable to find a value for "
                + CloudControllerConstants.IDENTITY_ELEMENT
                + " element from Secure Vault."
                + "Hence we will try to assign the plain text value (if specified).");
        iaas.setIdentity(identityElt.getText());
      }
    }

    if (it.hasNext()) {
      log.warn(
          xmlSource
              + " contains more than one "
              + CloudControllerConstants.IDENTITY_ELEMENT
              + " elements!"
              + " Elements other than the first will be neglected.");
    }

    if (iaas.getIdentity() == null) {
      String msg =
          "Essential '"
              + CloudControllerConstants.IDENTITY_ELEMENT
              + "' element"
              + " has not specified in "
              + xmlSource;
      handleException(msg);
    }
  }