Exemplo n.º 1
0
        protected void grdAzureTenants_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            if (!this.AllowPersistedObjectUpdate)
            {
                return;
            }
            if (PersistedObject.AzureTenants == null)
            {
                return;
            }
            GridViewRow rowToDelete = grdAzureTenants.Rows[e.RowIndex];

            Guid Id = new Guid(rowToDelete.Cells[0].Text);

            PersistedObject.AzureTenants.Remove(PersistedObject.AzureTenants.Find(x => x.Id == Id));

            // Update object in database
            UpdatePersistedObject();
            AzureCPLogging.Log(
                String.Format("Removed an Azure tenant in PersistedObject {0}", Constants.AZURECPCONFIG_NAME),
                TraceSeverity.Medium,
                EventSeverity.Information,
                AzureCPLogging.Categories.Configuration);

            PopulateLdapConnectionGrid();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Add new LDAP connection to collection in persisted object
        /// </summary>
        void AddTenantConnection()
        {
            if (!this.AllowPersistedObjectUpdate)
            {
                return;
            }
            if (null == PersistedObject)
            {
                AzureCPLogging.Log(
                    String.Format("PersistedObject {0} should not be null.", Constants.AZURECPCONFIG_NAME),
                    TraceSeverity.Unexpected,
                    EventSeverity.Error,
                    AzureCPLogging.Categories.Configuration);
                return;
            }

            if (null == CurrentTrustedLoginProvider)
            {
                AzureCPLogging.Log(
                    "Trust associated with AzureCP could not be found.",
                    TraceSeverity.Unexpected,
                    EventSeverity.Error,
                    AzureCPLogging.Categories.Configuration);
                return;
            }

            if (this.TxtTenantName.Text == String.Empty || this.TxtTenantId.Text == String.Empty || this.TxtClientId.Text == String.Empty || this.TxtClientSecret.Text == String.Empty)
            {
                this.LabelErrorTestLdapConnection.Text = TextErrorAzureTenantFieldsMissing;
                return;
            }

            if (PersistedObject.AzureTenants == null)
            {
                PersistedObject.AzureTenants = new List <AzureTenant>();
            }
            this.PersistedObject.AzureTenants.Add(
                new AzureTenant
            {
                TenantName   = this.TxtTenantName.Text,
                TenantId     = this.TxtTenantId.Text,
                ClientId     = TxtClientId.Text,
                ClientSecret = this.TxtClientSecret.Text,
            });

            // Update object in database
            UpdatePersistedObject();
            AzureCPLogging.Log(
                String.Format("Added a new Azure tenant in PersistedObject {0}", Constants.AZURECPCONFIG_NAME),
                TraceSeverity.Medium,
                EventSeverity.Information,
                AzureCPLogging.Categories.Configuration);

            PopulateLdapConnectionGrid();
            this.TxtTenantId.Text   = this.TxtClientId.Text = this.TxtClientSecret.Text = String.Empty;
            this.TxtTenantName.Text = "TENANTNAME.onMicrosoft.com";
        }
Exemplo n.º 3
0
        public static AzureCPConfig GetFromConfigDB()
        {
            SPPersistedObject parent = SPFarm.Local;

            try
            {
                AzureCPConfig persistedObject = parent.GetChild <AzureCPConfig>(Constants.AZURECPCONFIG_NAME);
                return(persistedObject);
            }
            catch (Exception ex)
            {
                AzureCPLogging.Log(String.Format("Error while retrieving SPPersistedObject {0}: {1}", Constants.AZURECPCONFIG_NAME, ex.Message), TraceSeverity.Unexpected, EventSeverity.Error, AzureCPLogging.Categories.Core);
            }
            return(null);
        }
Exemplo n.º 4
0
        public static AzureCPConfig ResetPersistedObject()
        {
            AzureCPConfig persistedObject = GetFromConfigDB();

            if (persistedObject != null)
            {
                AzureCPConfig newPersistedObject = GetDefaultSettings(persistedObject);
                newPersistedObject.Update();

                AzureCPLogging.Log(
                    String.Format("Claims list of PersistedObject {0} was successfully reset to default relationship table", Constants.AZURECPCONFIG_NAME),
                    TraceSeverity.High, EventSeverity.Information, AzureCPLogging.Categories.Core);
            }
            return(null);
        }
Exemplo n.º 5
0
        public static void ResetClaimsList()
        {
            AzureCPConfig persistedObject = GetFromConfigDB();

            if (persistedObject != null)
            {
                persistedObject.AzureADObjects.Clear();
                persistedObject.AzureADObjects = GetDefaultAADClaimTypeList();
                persistedObject.Update();

                AzureCPLogging.Log(
                    String.Format("Claims list of PersistedObject {0} was successfully reset to default relationship table", Constants.AZURECPCONFIG_NAME),
                    TraceSeverity.High, EventSeverity.Information, AzureCPLogging.Categories.Core);
            }
            return;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Update global configuration of AzureCP, except LDAP connections
        /// </summary>
        protected void UpdateTrustConfiguration()
        {
            if (!this.AllowPersistedObjectUpdate)
            {
                return;
            }
            if (null == PersistedObject)
            {
                AzureCPLogging.Log(
                    String.Format("PersistedObject {0} should not be null.", Constants.AZURECPCONFIG_NAME),
                    TraceSeverity.Unexpected,
                    EventSeverity.Error,
                    AzureCPLogging.Categories.Configuration);
                return;
            }

            if (null == CurrentTrustedLoginProvider)
            {
                AzureCPLogging.Log(
                    "Trust associated with AzureCP could not be found.",
                    TraceSeverity.Unexpected,
                    EventSeverity.Error,
                    AzureCPLogging.Categories.Configuration);
                return;
            }

            // Handle identity claim type
            if (this.RbIdentityCustomGraphProperty.Checked)
            {
                IdentityClaim.GraphPropertyToDisplay = (GraphProperty)Convert.ToInt32(this.DDLGraphPropertyToDisplay.SelectedValue);
            }
            else
            {
                IdentityClaim.GraphPropertyToDisplay = GraphProperty.None;
            }

            PersistedObject.AlwaysResolveUserInput = this.ChkAlwaysResolveUserInput.Checked;
            PersistedObject.FilterExactMatchOnly   = this.ChkFilterExactMatchOnly.Checked;
            PersistedObject.AugmentAADRoles        = this.ChkAugmentAADRoles.Checked;

            UpdatePersistedObject();
            AzureCPLogging.Log(
                String.Format("Updated PersistedObject {0}", Constants.AZURECPCONFIG_NAME),
                TraceSeverity.Medium,
                EventSeverity.Information,
                AzureCPLogging.Categories.Configuration);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Create the persisted object that contains default configuration of AzureCP.
        /// It should be created only in central administration with application pool credentials
        /// because this is the only place where we are sure user has the permission to write in the config database
        /// </summary>
        public static AzureCPConfig CreatePersistedObject()
        {
            // Ensure it doesn't already exists and delete it if so
            AzureCPConfig existingConfig = AzureCPConfig.GetFromConfigDB();

            if (existingConfig != null)
            {
                DeleteAzureCPConfig();
            }

            AzureCPConfig PersistedObject = new AzureCPConfig(SPFarm.Local);

            PersistedObject.Id           = new Guid(Constants.AZURECPCONFIG_ID);
            PersistedObject.AzureTenants = new List <AzureTenant>();
            PersistedObject = GetDefaultSettings(PersistedObject);
            PersistedObject.Update();
            AzureCPLogging.Log(
                String.Format("Created PersistedObject {0} with Id {1}", PersistedObject.Name, PersistedObject.Id),
                TraceSeverity.Medium, EventSeverity.Information, AzureCPLogging.Categories.Core);

            return(PersistedObject);
        }
Exemplo n.º 8
0
        protected void UpdatePersistedObject()
        {
            if (null == PersistedObject)
            {
                AzureCPLogging.Log(
                    String.Format("PersistedObject {0} should not be null.", Constants.AZURECPCONFIG_NAME),
                    TraceSeverity.Unexpected,
                    EventSeverity.Error,
                    AzureCPLogging.Categories.Configuration);
                return;
            }

            if (null == CurrentTrustedLoginProvider)
            {
                AzureCPLogging.Log(
                    "Trust associated with AzureCP could not be found.",
                    TraceSeverity.Unexpected,
                    EventSeverity.Error,
                    AzureCPLogging.Categories.Configuration);
                return;
            }

            // Update object in database
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                this.Web.AllowUnsafeUpdates = true;
                PersistedObject.Update();
                this.Web.AllowUnsafeUpdates = false;

                AzureCPLogging.Log(
                    String.Format("Objects list of AzureCP was successfully updated in PersistedObject {0}.", Constants.AZURECPCONFIG_NAME),
                    TraceSeverity.Medium,
                    EventSeverity.Information,
                    AzureCPLogging.Categories.Configuration);
            });
            ViewState["PersistedObjectVersion"] = PersistedObject.Version;
        }