private void AzureLoginButtonClick(object sender)
 {
     try
     {
         IntegrationAccountContext iaContext = new IntegrationAccountContext();
         var authresult = iaContext.GetAccessTokenFromAAD();
         AuthenticationResult integrationAccountResult = authresult[AuthenticationAccessToken.IntegrationAccount];
         AuthenticationResult keyVaultResult           = authresult[AuthenticationAccessToken.KeyVault];
         this.ApplicationContext.SetProperty("IntegrationAccountAuthorization", integrationAccountResult);
         this.ApplicationContext.SetProperty("KeyVaultAuthorization", keyVaultResult);
         string iaToken = integrationAccountResult?.AccessToken;
         string kvToken = keyVaultResult?.AccessToken;
         statusBarViewModel.Clear();
         try
         {
             HttpResponseMessage response = iaContext.SendSyncGetRequestToIA(UrlHelper.GetSubscriptionsUrl(), integrationAccountResult);
             var reponseObj = JObject.Parse(response.Content.ReadAsStringAsync().Result);
             if (reponseObj.GetValue("value") != null)
             {
                 UserSubscriptions = JsonConvert.DeserializeObject <ObservableCollection <Subscription.RootObject> >(reponseObj["value"].ToString());
                 if (userSubscriptions.Count != 0)
                 {
                     SubscriptionVisible   = true;
                     IsLoginButttonEnabled = false;
                 }
                 else
                 {
                     TraceProvider.WriteLine("No Subscriptions are available for the user. Please login as different user");
                     statusBarViewModel.ShowError("No Subscriptions are available for the user. Please login as different user");
                     IsLoginButttonEnabled = true;
                     SubscriptionVisible   = false;
                 }
             }
             else
             {
                 TraceProvider.WriteLine("No Subscriptions are available for the user. Please login as different user");
                 statusBarViewModel.ShowError("No Subscriptions are available for the user. Please login as different user");
                 IsLoginButttonEnabled = true;
                 SubscriptionVisible   = false;
             }
         }
         catch (Exception ex)
         {
             TraceProvider.WriteLine(string.Format("Error reading user subscriptions from Portal. Reason: {0}{1}", ExceptionHelper.GetExceptionMessage(ex), "Please Login again or as different user."));
             statusBarViewModel.ShowError(string.Format("Error reading user subscriptions from Portal. Reason: {0}{1}", ExceptionHelper.GetExceptionMessage(ex), "Please Login again or as different user."));
             IsLoginButttonEnabled = true;
             SubscriptionVisible   = false;
         }
     }
     catch (Exception ex)
     {
         TraceProvider.WriteLine(string.Format("Error getting the Access Tokens. Reason: {0}", ExceptionHelper.GetExceptionMessage(ex)));
         statusBarViewModel.ShowError(string.Format("Error getting the Access Tokens. Reason: {0}", ExceptionHelper.GetExceptionMessage(ex)));
         IsLoginButttonEnabled = true;
         SubscriptionVisible   = false;
     }
 }
        private void ResourceGroupSelectionChanged()
        {
            IntegrationAccountContext iaContext = new IntegrationAccountContext();
            var authResult = this.ApplicationContext.GetProperty("IntegrationAccountAuthorization") as AuthenticationResult;

            statusBarViewModel.Clear();
            try
            {
                HttpResponseMessage IAresponse = iaContext.SendSyncGetRequestToIA(UrlHelper.GetIntegrationAccountsUrl(SelectedSubscription.SubscriptionId, SelectedResourceGroup.Name), authResult);
                var IAreponseObj = JObject.Parse(IAresponse.Content.ReadAsStringAsync().Result);
                HttpResponseMessage KVresponse = iaContext.SendSyncGetRequestToIA(UrlHelper.GetKeyVaultsUrl(SelectedSubscription.SubscriptionId, SelectedResourceGroup.Name), authResult);
                var KVreponseObj = JObject.Parse(KVresponse.Content.ReadAsStringAsync().Result);
                if (IAreponseObj.GetValue("value") != null && KVreponseObj.GetValue("value") != null)
                {
                    UserIntegrationAccounts = JsonConvert.DeserializeObject <ObservableCollection <IntegrationAccount.RootObject> >(IAreponseObj["value"].ToString());
                    UserKeyVaults           = JsonConvert.DeserializeObject <ObservableCollection <KeyVault.RootObject> >(KVreponseObj["value"].ToString());
                    if (UserIntegrationAccounts.Count != 0)
                    {
                        IsLoginButttonEnabled = false;
                    }
                    else
                    {
                        TraceProvider.WriteLine("No Integration Accounts are available for the user. Please login as different user or select a different ResourceGroup/Subscription");
                        statusBarViewModel.ShowError("No Integration Accounts are available for the user. Please login as different user or select a different ResourceGroup/Subscription");
                        IsLoginButttonEnabled = true;
                    }
                    if (UserKeyVaults.Count == 0)
                    {
                        TraceProvider.WriteLine("No Key Vaults are available for the user in the current RG. If you wish to migrate any Private cerificate to IA, please login as different user or select a different ResourceGroup/Subscription");
                        statusBarViewModel.ShowError("No Key Vaults are available for the user in the current RG. If you wish to migrate any Private cerificate to IA, please login as different user or select a different ResourceGroup/Subscription");
                        IsLoginButttonEnabled = true;
                    }
                }
                else
                {
                    TraceProvider.WriteLine("No Integration Accounts are available for the user. Please login as different user or select a different ResourceGroup/Subscription");
                    statusBarViewModel.ShowError("No Integration Accounts are available for the user. Please login as different user or select a different ResourceGroup/Subscription");
                    IsLoginButttonEnabled = true;
                }
            }
            catch (Exception ex)
            {
                TraceProvider.WriteLine(string.Format("Error reading user IA's from Portal. Reason: {0}{1}", ExceptionHelper.GetExceptionMessage(ex), "Please Login again or as different user."));
                statusBarViewModel.ShowError(string.Format("Error reading user IA's  from Portal. Reason: {0}{1}", ExceptionHelper.GetExceptionMessage(ex), "Please Login again or as different user."));
                IsLoginButttonEnabled = true;
            }
        }
Exemple #3
0
        public async Task <HttpResponseMessage> MigrateToCloudIA(string filePath, string name, TEntity item, IntegrationAccountDetails iaDetails, AuthenticationResult authResult)
        {
            try
            {
                IntegrationAccountContext sclient = new IntegrationAccountContext();
                var x = await sclient.LAIntegrationFromFile(UrlHelper.GetCertificateUrl(name, iaDetails), filePath, authResult);

                return(x);
            }
            catch (Exception ex)
            {
                SetStatus(item, MigrationStatus.Failed, string.Format("Certificate Migration Failed. Reason:{0}", ExceptionHelper.GetExceptionMessage(ex)));
                TraceProvider.WriteLine(string.Format("Certificate Migration Failed. Reason:{0}", ExceptionHelper.GetExceptionMessage(ex)));
                TraceProvider.WriteLine();
                throw ex;
            }
        }
        public async Task <HttpResponseMessage> MigrateToCloudIA(string filePath, string name, SchemaMigrationItemViewModel serverSchemaItem, IntegrationAccountDetails iaDetails, AuthenticationResult authResult)
        {
            try
            {
                IntegrationAccountContext sclient = new IntegrationAccountContext();
                var x = await sclient.LAIntegrationFromFile(UrlHelper.GetSchemaUrl(name, iaDetails), filePath, authResult);

                return(x);
            }
            catch (Exception ex)
            {
                serverSchemaItem.ExportStatus     = MigrationStatus.Failed;
                serverSchemaItem.ExportStatusText = ex.Message;
                TraceProvider.WriteLine(string.Format("Schema Migration Failed. Reason:{0}", ExceptionHelper.GetExceptionMessage(ex)));
                TraceProvider.WriteLine();
                throw ex;
            }
        }
        public async Task <bool> CheckIfArtifactExists(string migrationItem, string migrationEntity, IntegrationAccountDetails iaDetails, AuthenticationResult authResult)
        {
            IntegrationAccountContext sclient  = new IntegrationAccountContext();
            HttpResponseMessage       response = new HttpResponseMessage();

            try
            {
                if (migrationEntity == "Agreement")
                {
                    response = sclient.GetArtifactsFromIA(UrlHelper.GetAgreementUrl(migrationItem, iaDetails), authResult);
                }
                if (migrationEntity == "Partner")
                {
                    response = sclient.GetArtifactsFromIA(UrlHelper.GetPartnerUrl(migrationItem, iaDetails), authResult);
                }
                if (migrationEntity == "Certificate")
                {
                    response = sclient.GetArtifactsFromIA(UrlHelper.GetCertificateUrl(migrationItem, iaDetails), authResult);
                }
                if (migrationEntity == "Schema")
                {
                    response = sclient.GetArtifactsFromIA(UrlHelper.GetSchemaUrl(migrationItem, iaDetails), authResult);
                }
                if (migrationEntity == "Map")
                {
                    response = sclient.GetArtifactsFromIA(UrlHelper.GetMapUrl(migrationItem, iaDetails), authResult);
                }
                if (!response.IsSuccessStatusCode)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }
Exemple #6
0
        public async Task <bool> CheckIfCertificateExists(string migrationItem, IntegrationAccountDetails iaDetails, AuthenticationResult authResult)
        {
            IntegrationAccountContext sclient  = new IntegrationAccountContext();
            HttpResponseMessage       response = new HttpResponseMessage();

            try
            {
                response = sclient.GetArtifactsFromIA(UrlHelper.GetCertificateUrl(migrationItem, iaDetails), authResult);
                if (!response.IsSuccessStatusCode)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }
        private void SubscriptionSelectionChanged()
        {
            IntegrationAccountContext iaContext = new IntegrationAccountContext();
            var authResult = this.ApplicationContext.GetProperty("IntegrationAccountAuthorization") as AuthenticationResult;

            statusBarViewModel.Clear();
            try
            {
                HttpResponseMessage response = iaContext.SendSyncGetRequestToIA(UrlHelper.GetResourceGroupsUrl(SelectedSubscription.SubscriptionId), authResult);
                var reponseObj = JObject.Parse(response.Content.ReadAsStringAsync().Result);
                if (reponseObj.GetValue("value") != null)
                {
                    UserResourceGroups = JsonConvert.DeserializeObject <ObservableCollection <ResourceGroup.RootObject> >(reponseObj["value"].ToString());
                    if (userResourceGroups.Count != 0)
                    {
                        IsLoginButttonEnabled = false;
                    }
                    else
                    {
                        TraceProvider.WriteLine("No Resource Groups are available for the user. Please login as different user or select different Subscription");
                        statusBarViewModel.ShowError("No Resource Groups are available for the user. Please login as different user or select different Subscription");
                        IsLoginButttonEnabled = true;
                    }
                }
                else
                {
                    TraceProvider.WriteLine("No Resource Groups are available for the user. Please login as different user or select different Subscription");
                    statusBarViewModel.ShowError("No Resource Groups are available for the user. Please login as different user or select different Subscription");
                    IsLoginButttonEnabled = true;
                }
            }
            catch (Exception ex)
            {
                TraceProvider.WriteLine(string.Format("Error reading user RG's from Portal. Reason: {0}{1}", ExceptionHelper.GetExceptionMessage(ex), "Please Login again or as different user."));
                statusBarViewModel.ShowError(string.Format("Error reading user RG's from Portal. Reason: {0}{1}", ExceptionHelper.GetExceptionMessage(ex), "Please Login again or as different user."));
                IsLoginButttonEnabled = true;
            }
        }
Exemple #8
0
        public void CheckIfCertificateIsprivate(TEntity item, string certificateName, IntegrationAccountDetails iaDetails)
        {
            try
            {
                string filepath    = FileOperations.GetCertificateJsonFilePath(certificateName);
                string content     = File.ReadAllText(filepath);
                var    certificate = JsonConvert.DeserializeObject <JsonCertificate.Rootobject>(content);
                if (certificate.properties.key != null)
                {
                    string keyvaultname = iaDetails.KeyVaultName;
                    if (string.IsNullOrEmpty(keyvaultname))
                    {
                        throw new Exception("Couldn't find the name of the Key Vault to upload the Private key for the Private Certificate. Make sure you selected a Key Vault at the Integration Account Details Screen");
                    }
                    string certName                      = FileOperations.GetFileName(certificateName);
                    string keyvaultfilepath              = FileOperations.GetKeyVaultJsonFilePath(certName + "Privatekey");
                    IntegrationAccountContext sclient    = new IntegrationAccountContext();
                    AuthenticationResult      authresult = thisApplicationContext.GetProperty("KeyVaultAuthorization") as AuthenticationResult;
                    string kid = sclient.UploadCertificatePrivateKeyToKeyVault(StringOperations.RemoveAllSpecialCharacters(certName) + "Privatekey", keyvaultname, keyvaultfilepath, authresult);
                    certificate.properties.key.keyName     = StringOperations.RemoveAllSpecialCharacters(certName) + "Privatekey";
                    certificate.properties.key.keyVersion  = kid;
                    certificate.properties.key.keyVault.id = string.Format(ConfigurationManager.AppSettings["KeyVaultResourceIdTemplate"], iaDetails.SubscriptionId, iaDetails.ResourceGroupName, keyvaultname);
                    //certificate.properties.key.keyVault.name = certName + "Privatekey";

                    string fileName = FileOperations.GetCertificateJsonFilePath(certName);
                    string partnerJsonFileContent = JsonConvert.SerializeObject(certificate);
                    File.WriteAllText(fileName, partnerJsonFileContent);
                }
            }
            catch (Exception ex)
            {
                SetStatus(item, MigrationStatus.Failed, string.Format("Certificate Migration Failed. Reason:{0}", ExceptionHelper.GetExceptionMessage(ex)));
                TraceProvider.WriteLine(string.Format("Certificate Migration Failed. Reason:{0}", ExceptionHelper.GetExceptionMessage(ex)));
                TraceProvider.WriteLine();
                throw ex;
            }
        }
        public async Task <HttpResponseMessage> MigrateToCloudIAPartner(string filePath, string name, PartnerMigrationItemViewModel serverPartnerItem, IntegrationAccountDetails iaDetails, AuthenticationResult authResult)
        {
            try
            {
                IntegrationAccountContext sclient = new IntegrationAccountContext();
                try
                {
                    List <KeyValuePair <string, string> > partnerIdentities = new List <KeyValuePair <string, string> >();
                    var    partnerInIA      = sclient.GetArtifactsFromIA(UrlHelper.GetPartnerUrl(name, iaDetails), authResult);
                    string responseAsString = await partnerInIA.Content.ReadAsStringAsync();

                    JObject responseAsJObject = JsonConvert.DeserializeObject <JObject>(responseAsString);
                    var     partner           = responseAsJObject;
                    if (partner["properties"] != null && partner["properties"]["content"] != null && partner["properties"]["content"]["b2b"] != null && partner["properties"]["content"]["b2b"]["businessIdentities"] != null)
                    {
                        foreach (var identity in partner["properties"]["content"]["b2b"]["businessIdentities"])
                        {
                            if (identity["qualifier"] != null && identity["value"] != null)
                            {
                                KeyValuePair <string, string> kvpair = new KeyValuePair <string, string>(identity["qualifier"].ToString(), identity["value"].ToString());
                                if (!partnerIdentities.Contains(kvpair))
                                {
                                    partnerIdentities.Add(kvpair);
                                }
                            }
                        }
                    }
                    var partnersFromLocalFile = File.ReadAllText(filePath);
                    var partnerContent        = JsonConvert.DeserializeObject <JsonPartner.Rootobject>(partnersFromLocalFile);
                    var partnerIdentityDict   = partnerContent.properties.content.b2b.businessIdentities.ToDictionary(xc => new KeyValuePair <string, string>(xc.qualifier, xc.value), xc => xc.value);
                    var partnerIdentityList   = partnerContent.properties.content.b2b.businessIdentities.ToList();
                    foreach (var identity in partnerIdentities)
                    {
                        if (!partnerIdentityDict.ContainsKey(identity))
                        {
                            partnerIdentityDict.Add(identity, identity.Value);
                            partnerIdentityList.Add(new JsonPartner.Businessidentity {
                                qualifier = identity.Key, value = identity.Value
                            });
                        }
                    }
                    partnerContent.properties.content.b2b.businessIdentities = partnerIdentityList.ToArray();
                    var finalcontent = JsonConvert.SerializeObject(partnerContent);
                    File.WriteAllText(filePath, finalcontent);
                }
                catch (Exception)
                {
                    //do nothing
                }
                var x = await sclient.LAIntegrationFromFile(UrlHelper.GetPartnerUrl(name, iaDetails), filePath, authResult);

                return(x);
            }
            catch (Exception ex)
            {
                serverPartnerItem.ExportStatus     = MigrationStatus.Failed;
                serverPartnerItem.ExportStatusText = ex.Message;
                TraceProvider.WriteLine(string.Format("Partner Migration Failed. Reason:{0}", ExceptionHelper.GetExceptionMessage(ex)));
                TraceProvider.WriteLine();
                throw ex;
            }
        }