public ActionResult RepairAccess([Bind(Include = "Id, OrganizationId")] Subscription subscription, string servicePrincipalObjectId)
        {
            if (ModelState.IsValid)
            {
                AzureResourceManagerUtil.RevokeRoleFromServicePrincipalOnSubscription(servicePrincipalObjectId, subscription.Id, subscription.OrganizationId);
                AzureResourceManagerUtil.GrantRoleToServicePrincipalOnSubscription(servicePrincipalObjectId, subscription.Id, subscription.OrganizationId);
            }

            return(RedirectToAction("Index", "Home"));
        }
        public ActionResult RepairAccess([Bind(Include = "Id")] Subscription subscription)
        {
            if (ModelState.IsValid)
            {
                AzureResourceManagerUtil.RevokeRoleFromServicePrincipalOnSubscription(ConfigurationManager.AppSettings["ObjectId"], subscription.Id, ConfigurationManager.AppSettings["AADId"]);
                AzureResourceManagerUtil.GrantRoleToServicePrincipalOnSubscription(ConfigurationManager.AppSettings["ObjectId"], subscription.Id, ConfigurationManager.AppSettings["AADId"]);
            }

            return(RedirectToAction("Index", "Home"));
        }
Esempio n. 3
0
        public async Task DisconnectSubscription(string subscriptionId)
        {
            string directoryId = await resourceManagerUtility.GetDirectoryForSubscription(subscriptionId);

            string objectIdOfCloudSenseServicePrincipalInDirectory = await
                                                                     resourceManagerUtility.GetObjectIdOfServicePrincipalInDirectory(directoryId, azureADSettings.ClientId);

            await resourceManagerUtility.RevokeRoleFromServicePrincipalOnSubscription
                (objectIdOfCloudSenseServicePrincipalInDirectory, subscriptionId, directoryId);

            Subscription s = subscriptionRepository.GetByUserAndId(signedInUserService.GetSignedInUserName(), subscriptionId);

            if (s != null)
            {
                subscriptionRepository.Remove(s);
            }

            Response.Redirect(this.Url.Action("Index", "Home"));
        }
Esempio n. 4
0
        public async Task RepairSubscriptionConnection(string subscriptionId)
        {
            string directoryId = await AzureResourceManagerUtil.GetDirectoryForSubscription(subscriptionId);

            string objectIdOfCloudSenseServicePrincipalInDirectory = await
                                                                     AzureADGraphAPIUtil.GetObjectIdOfServicePrincipalInDirectory(directoryId, ConfigurationManager.AppSettings["ClientID"]);

            await AzureResourceManagerUtil.RevokeRoleFromServicePrincipalOnSubscription
                (objectIdOfCloudSenseServicePrincipalInDirectory, subscriptionId, directoryId);

            await AzureResourceManagerUtil.GrantRoleToServicePrincipalOnSubscription
                (objectIdOfCloudSenseServicePrincipalInDirectory, subscriptionId, directoryId);

            Response.Redirect(this.Url.Action("Index", "Home"));
        }
        public ActionResult Disconnect([Bind(Include = "Id, OrganizationId")] Subscription subscription, string servicePrincipalObjectId)
        {
            if (ModelState.IsValid)
            {
                AzureResourceManagerUtil.RevokeRoleFromServicePrincipalOnSubscription(servicePrincipalObjectId, subscription.Id, subscription.OrganizationId);

                Subscription s = db.Subscriptions.Find(subscription.Id);
                if (s != null)
                {
                    db.Subscriptions.Remove(s);
                    db.SaveChanges();
                }
            }

            return(RedirectToAction("Index", "Home"));
        }
        public ActionResult Disconnect([Bind(Include = "Id")] Subscription subscription)
        {
            if (ModelState.IsValid)
            {
                AzureResourceManagerUtil.RevokeRoleFromServicePrincipalOnSubscription(ConfigurationManager.AppSettings["ObjectId"],
                                                                                      subscription.Id, ConfigurationManager.AppSettings["AADId"]);

                Subscription s = db.Subscriptions.Find(subscription.Id);
                if (s != null)
                {
                    db.Subscriptions.Remove(s);
                    db.SaveChanges();
                }
            }

            return(RedirectToAction("Index", "Home"));
        }
Esempio n. 7
0
        public ActionResult RepairAccess([Bind(Include = "Id, OrganizationId")] Subscription subscription, string servicePrincipalObjectId)
        {
            if (ModelState.IsValid)
            {
                AzureResourceManagerUtil.RevokeRoleFromServicePrincipalOnSubscription(servicePrincipalObjectId, subscription.Id, subscription.OrganizationId);
                AzureResourceManagerUtil.GrantRoleToServicePrincipalOnSubscription(servicePrincipalObjectId, subscription.Id, subscription.OrganizationId);

                Subscription s = db.Subscriptions.Find(subscription.Id);
                if (s != null)
                {
                    s.AzureAccessNeedsToBeRepaired = false;
                    db.Entry(s).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                }
            }

            return(RedirectToAction("Index", "Home"));
        }
Esempio n. 8
0
        public async Task DisconnectSubscription(string subscriptionId)
        {
            string directoryId = await AzureResourceManagerUtil.GetDirectoryForSubscription(subscriptionId);

            string objectIdOfCloudSenseServicePrincipalInDirectory = await
                                                                     AzureADGraphAPIUtil.GetObjectIdOfServicePrincipalInDirectory(directoryId, ConfigurationManager.AppSettings["ClientID"]);

            await AzureResourceManagerUtil.RevokeRoleFromServicePrincipalOnSubscription
                (objectIdOfCloudSenseServicePrincipalInDirectory, subscriptionId, directoryId);

            Subscription s = db.Subscriptions.Find(subscriptionId);

            if (s != null)
            {
                db.Subscriptions.Remove(s);
                db.SaveChanges();
            }

            Response.Redirect(this.Url.Action("Index", "Home"));
        }
Esempio n. 9
0
        public ActionResult Connect([Bind(Include = "Id, OrganizationId, DisplayName")] Subscription subscription, string servicePrincipalObjectId, string displayTag)
        {
            if (ModelState.IsValid)
            {
                AzureResourceManagerUtil.RevokeRoleFromServicePrincipalOnSubscription(servicePrincipalObjectId, subscription.Id, subscription.OrganizationId);

                AzureResourceManagerUtil.GrantRoleToServicePrincipalOnSubscription(servicePrincipalObjectId, subscription.Id, subscription.OrganizationId);

                if (AzureResourceManagerUtil.ServicePrincipalHasReadAccessToSubscription(subscription.Id, subscription.OrganizationId))
                {
                    // Insert into SQL DB
                    subscription.ConnectedBy = (System.Security.Claims.ClaimsPrincipal.Current).FindFirst(ClaimTypes.Name).Value;
                    subscription.ConnectedOn = DateTime.Now;
                    subscription.AzureAccessNeedsToBeRepaired = false;
                    subscription.DisplayTag = displayTag;

                    subscription.DataGenDate   = DateTime.UtcNow;
                    subscription.DataGenStatus = DataGenStatus.Pending;

                    db.Subscriptions.Add(subscription);
                    db.SaveChanges();


                    DateTime       sdt = DateTime.Now.AddYears(-3);
                    DateTime       edt = DateTime.Now.AddDays(-1);
                    BillingRequest br  = new BillingRequest(subscription.Id, subscription.OrganizationId, sdt, edt);

                    // Insert into Azure Storage Queue
                    var storageAccount                  = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["AzureWebJobsStorage"].ToString());
                    CloudQueueClient queueClient        = storageAccount.CreateCloudQueueClient();
                    CloudQueue       subscriptionsQueue = queueClient.GetQueueReference(ConfigurationManager.AppSettings["ida:QueueBillingDataRequests"].ToString());
                    subscriptionsQueue.CreateIfNotExists();
                    var queueMessage = new CloudQueueMessage(JsonConvert.SerializeObject(br));
                    subscriptionsQueue.AddMessageAsync(queueMessage);
                }
            }

            return(RedirectToAction("Index", "Home"));
        }