@Override
    public String invoke() throws AmbariException {
      String clusterName = getClusterName(properties);
      String alias = getAlias(properties);

      CredentialStoreType credentialStoreType = properties.containsKey(CREDENTIAL_TYPE_PROPERTY_ID)
          ? getCredentialStoreType(properties)
          : credentialStoreService.getCredentialStoreType(clusterName, alias);

      validateForCreateOrModify(credentialStoreType);

      Credential credential = credentialStoreService.getCredential(clusterName, alias);
      if (credential instanceof PrincipalKeyCredential) {
        PrincipalKeyCredential principalKeyCredential = (PrincipalKeyCredential) credential;

        Map<String, Object> credentialProperties = new HashMap<>();

        // Make sure the credential to update is removed from the persisted or temporary store... the
        // updated data may change the persistence type.
        credentialStoreService.removeCredential(clusterName, alias);

        if (properties.containsKey(CREDENTIAL_PRINCIPAL_PROPERTY_ID)) {
          credentialProperties.put(CREDENTIAL_PRINCIPAL_PROPERTY_ID, properties.get(CREDENTIAL_PRINCIPAL_PROPERTY_ID));
        } else {
          credentialProperties.put(CREDENTIAL_PRINCIPAL_PROPERTY_ID, principalKeyCredential.getPrincipal());
        }

        if (properties.containsKey(CREDENTIAL_KEY_PROPERTY_ID)) {
          credentialProperties.put(CREDENTIAL_KEY_PROPERTY_ID, properties.get(CREDENTIAL_KEY_PROPERTY_ID));
        } else {
          char[] credentialKey = principalKeyCredential.getKey();
          if (credentialKey != null) {
            credentialProperties.put(CREDENTIAL_KEY_PROPERTY_ID, String.valueOf(credentialKey));
          }
        }

        credentialStoreService.setCredential(clusterName, alias, createCredential(credentialProperties), credentialStoreType);
        return alias;
      } else {
        return null;
      }
    }
ModifyResourcesCommand implements a Command that performs the steps to update existing credential
resources.
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/CredentialResourceProvider.java