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

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

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

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

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

        iaas.setCredential(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.getCredential() == null) {
        log.warn(
            "Unable to find a value for "
                + CloudControllerConstants.CREDENTIAL_ELEMENT
                + " element from Secure Vault."
                + "Hence we will try to assign the plain text value (if specified).");
        iaas.setCredential(credentialElt.getText());
      }
    }

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

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