Exemplo n.º 1
0
        public List <ADGroup> GetOrganizationGroups(string filter)
        {
            string tenantId  = ClaimsPrincipal.Current.TenantId();
            var    orgGroups = AzureADGraphApiUtil.GetAllGroupsForOrganization(tenantId, filter);

            return(orgGroups);
        }
Exemplo n.º 2
0
        private static Organization GetOrganization(string orgId)
        {
            var organization = AzureADGraphApiUtil.GetOrganizationDetails(orgId);
            var spid         = AzureADGraphApiUtil.GetObjectIdOfServicePrincipalInOrganization(orgId, Config.ClientId);

            organization.ObjectIdOfCloudSenseServicePrincipal = spid;
            return(organization);
        }
Exemplo n.º 3
0
        public async Task <UserSubscriptionInfo> GetUserDetails()
        {
            var subscriptionInfo = new UserSubscriptionInfo();

            subscriptionInfo.UserName = ClaimsPrincipal.Current.Identity.Name;
            var tenantId             = ClaimsPrincipal.Current.TenantId();
            var signedInUserUniqueId = ClaimsPrincipal.Current.SignedInUserName();

            var org = await this.coreRepository.GetOrganization(tenantId);

            subscriptionInfo.Organization = org;

            var userGroups = AzureADGraphApiUtil.GetUserGroups(signedInUserUniqueId, org.Id);

            subscriptionInfo.CanCreate = userGroups.Any(x => x.Id == org.CreateProductGroup);
            subscriptionInfo.CanDeploy = userGroups.Any(x => x.Id == org.DeployGroup);
            subscriptionInfo.CanAdmin  = userGroups.Any(x => x.Id == org.AdminGroup);

            return(subscriptionInfo);
        }
Exemplo n.º 4
0
        public async Task <Organization> Get()
        {
            var tenantId     = ClaimsPrincipal.Current.TenantId();
            var organization = await this.coreRepository.GetOrganization(tenantId);

            organization.OrganizationADGroups = AzureADGraphApiUtil.GetAllGroupsForOrganization(tenantId);

            try
            {
                if (organization.AdminGroupName == null || organization.CreateProductGroupName == null)
                {
                    organization.AdminGroupName = organization.OrganizationADGroups.Where(x => x.Id == organization.AdminGroup).SingleOrDefault()?.Name;

                    organization.CreateProductGroupName = organization.OrganizationADGroups.Where(x => x.Id == organization.CreateProductGroup).SingleOrDefault()?.Name;
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.Message);
                Trace.TraceError($"AdminGroupName or CreateProductGroupName not found in the organisation : { organization.Id}");
            }

            return(organization);
        }
Exemplo n.º 5
0
        public async Task <UserSubscriptionInfo> GetUserDetailsFull()
        {
            var subscriptionInfo = new UserSubscriptionInfo();

            subscriptionInfo.UserName             = ClaimsPrincipal.Current.Identity.Name;
            subscriptionInfo.FirstName            = ClaimsPrincipal.Current.FirstName();
            subscriptionInfo.LastName             = ClaimsPrincipal.Current.LastName();
            subscriptionInfo.DefaultAdGroup       = Config.DefaultAdGroup;
            subscriptionInfo.DefaultResourceGroup = Config.DefaultResourceGroup;
            string tenantId             = ClaimsPrincipal.Current.TenantId();
            string signedInUserUniqueId = ClaimsPrincipal.Current.SignedInUserName();

            var userGroupsRoles = AzureADGraphApiUtil.GetUserGroups(signedInUserUniqueId, tenantId);

            subscriptionInfo.IsGlobalAdministrator = AzureADGraphApiUtil.IsGlobalAdministrator(userGroupsRoles);

            var org   = GetOrganization(tenantId);
            var dbOrg = await this.coreRepository.GetOrganization(tenantId);

            List <Subscription> dbSubscriptions = null;

            if (dbOrg != null)
            {
                org.DeployGroup        = dbOrg.DeployGroup;
                org.CreateProductGroup = dbOrg.CreateProductGroup;
                org.AdminGroup         = dbOrg.AdminGroup;
                //var userGroups = AzureADGraphApiUtil.GetUserGroups(signedInUserUniqueId, org.Id);
                subscriptionInfo.CanCreate = userGroupsRoles.Any(x => x.Id == dbOrg.CreateProductGroup);
                subscriptionInfo.CanDeploy = userGroupsRoles.Any(x => x.Id == dbOrg.DeployGroup);
                subscriptionInfo.CanAdmin  = userGroupsRoles.Any(x => x.Id == dbOrg.AdminGroup);
                dbSubscriptions            = this.coreRepository.GetSubscriptionListByOrgId(tenantId);

                if (dbSubscriptions != null && dbSubscriptions.Count > 0)
                {
                    subscriptionInfo.IsActivatedByAdmin = (dbSubscriptions.Any(x => x.IsConnected));
                }
            }

            subscriptionInfo.Organization = org;

            var orgGroups = AzureADGraphApiUtil.GetAllGroupsForOrganization(org.Id);

            subscriptionInfo.OrganizationADGroups = orgGroups;
            var subscriptions = AzureResourceManagerUtil.GetUserSubscriptions(org.Id);

            if (subscriptions != null)
            {
                foreach (var subscription in subscriptions)
                {
                    var userDetailVM = new UserDetailsViewModel();
                    userDetailVM.CanCreate = subscriptionInfo.CanCreate;
                    userDetailVM.CanDeploy = subscriptionInfo.CanDeploy;
                    userDetailVM.CanAdmin  = subscriptionInfo.CanAdmin;
                    userDetailVM.Name      = subscriptionInfo.UserName;

                    userDetailVM.IsAdminOfSubscription = AzureResourceManagerUtil.UserCanManageAccessForSubscription(subscription.Id);
                    userDetailVM.SubscriptionName      = subscription.DisplayName;
                    userDetailVM.SubscriptionId        = subscription.Id;
                    userDetailVM.OrganizationId        = org.Id;
                    userDetailVM.ServicePrincipalId    = org.ObjectIdOfCloudSenseServicePrincipal;
                    userDetailVM.OrganizationName      = org.DisplayName;

                    Subscription dbSubscription = null;
                    if (dbSubscriptions != null && dbSubscriptions.Count > 0)
                    {
                        dbSubscription = dbSubscriptions.FirstOrDefault(x => x.Id == subscription.Id) ?? null;
                    }

                    if (dbSubscription != null)
                    {
                        userDetailVM.SubscriptionIsConnected = dbSubscription.IsConnected;// true;
                        userDetailVM.IsEnrolled = dbSubscription.IsEnrolled;
                        userDetailVM.SubscriptionNeedsRepair = !AzureResourceManagerUtil.ServicePrincipalHasReadAccessToSubscription(dbSubscription.Id);
                        if (userDetailVM.SubscriptionIsConnected)
                        {
                            string organizationId = dbSubscription.OrganizationId;
                            string storageName    = dbSubscription.StorageName;
                            try
                            {
                                string storageKey = await AzureResourceManagerUtil.GetStorageAccountKeysArm(dbSubscription.Id, dbSubscription.StorageName);

                                CacheDetails(userDetailVM, storageKey, storageName, organizationId, signedInUserUniqueId);
                            }
                            catch (Exception ex)
                            {
                                Trace.TraceError(ex.Message);
                                Trace.TraceError($"Storage account: {storageName} was not found!");
                                userDetailVM.SubscriptionIsConnected = false;
                                userDetailVM.IsEnrolled = false;
                            }
                        }
                    }
                    subscriptionInfo.Subscriptions.Add(userDetailVM);
                }
            }
            return(subscriptionInfo);
        }