protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location);
                LblTitle.Text = String.Format("AzureCP v{0} - <a href=\"https://github.com/Yvand/AzureCP\" target=\"_blank\">GitHub.com/Yvand/AzureCP</a>", fvi.FileVersion);
            }

            // Get trust currently associated with AzureCP, if any
            CurrentTrustedLoginProvider = AzureCP.GetSPTrustAssociatedWithCP(AzureCP._ProviderInternalName);
            if (null == CurrentTrustedLoginProvider)
            {
                // Claim provider is currently not associated with any trust.
                // Display a message in the page and disable controls
                this.LabelErrorMessage.Text     = TextErrorNoTrustAssociation;
                this.BtnOK.Enabled              = this.BtnOKTop.Enabled = this.BtnAddLdapConnection.Enabled = this.BtnTestAzureTenantConnection.Enabled = false;
                this.AllowPersistedObjectUpdate = false;
                return;
            }

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                // Get SPPersisted Object and create it if it doesn't exist
                PersistedObject = AzureCPConfig.GetFromConfigDB();
                if (PersistedObject == null)
                {
                    this.Web.AllowUnsafeUpdates = true;
                    PersistedObject             = AzureCPConfig.CreatePersistedObject();
                    this.Web.AllowUnsafeUpdates = false;
                }
            });

            this.IdentityClaim = PersistedObject.AzureADObjects.Find(x => String.Equals(CurrentTrustedLoginProvider.IdentityClaimTypeInformation.MappedClaimType, x.ClaimType, StringComparison.InvariantCultureIgnoreCase) && !x.CreateAsIdentityClaim);
            if (null == this.IdentityClaim)
            {
                // Identity claim type is missing in the attributes list
                this.LabelErrorMessage.Text = String.Format(this.TextErrorNoIdentityClaimType, CurrentTrustedLoginProvider.DisplayName, CurrentTrustedLoginProvider.IdentityClaimTypeInformation.MappedClaimType);
                this.BtnOK.Enabled          = this.BtnOKTop.Enabled = this.BtnAddLdapConnection.Enabled = this.BtnTestAzureTenantConnection.Enabled = false;
                return;
            }

            if (ViewState["PersistedObjectVersion"] == null)
            {
                ViewState.Add("PersistedObjectVersion", PersistedObject.Version);
            }
            if ((long)ViewState["PersistedObjectVersion"] != PersistedObject.Version)
            {
                // PersistedObject changed since last time. Should not allow any update
                this.LabelErrorMessage.Text     = TextErrorPersistedObjectStale;
                this.AllowPersistedObjectUpdate = false;
                return;
            }

            if (!this.IsPostBack)
            {
                PopulateFields();
            }
        }
        private void RemovePersistedObject()
        {
            var PersistedObject = AzureCPConfig.GetFromConfigDB();

            if (PersistedObject != null)
            {
                PersistedObject.Delete();
            }
        }
Beispiel #3
0
        public static void DeleteAzureCPConfig()
        {
            AzureCPConfig azureCPConfig = AzureCPConfig.GetFromConfigDB();

            if (azureCPConfig != null)
            {
                azureCPConfig.Delete();
            }
        }
Beispiel #4
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);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            // Get trust currently associated with AzureCP, if any
            CurrentTrustedLoginProvider = AzureCP.GetSPTrustAssociatedWithCP(AzureCP._ProviderInternalName);
            if (null == CurrentTrustedLoginProvider)
            {
                // Claim provider is currently not associated with any trust.
                // Display a message in the page and disable controls
                this.LabelErrorMessage.Text   = TextErrorNoTrustAssociation;
                this.HideAllContent           = true;
                this.BtnCreateNewItem.Visible = false;
                return;
            }

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                // Get SPPersisted Object and create it if it doesn't exist
                PersistedObject = AzureCPConfig.GetFromConfigDB();
                if (PersistedObject == null)
                {
                    this.Web.AllowUnsafeUpdates = true;
                    PersistedObject             = AzureCPConfig.CreatePersistedObject();
                    this.Web.AllowUnsafeUpdates = false;
                }
            });

            if (ViewState["PersistedObjectVersion"] == null)
            {
                ViewState.Add("PersistedObjectVersion", PersistedObject.Version);
            }
            if ((long)ViewState["PersistedObjectVersion"] != PersistedObject.Version)
            {
                // PersistedObject changed since last time. Should not allow any update
                this.LabelErrorMessage.Text     = TextErrorPersistedObjectStale;
                this.AllowPersistedObjectUpdate = false;
                return;
            }
            TrustName = CurrentTrustedLoginProvider.Name;

            if (!this.IsPostBack)
            {
                New_DdlPermissionMetadata.Items.Add(String.Empty);
                foreach (object field in typeof(PeopleEditorEntityDataKeys).GetFields())
                {
                    New_DdlPermissionMetadata.Items.Add(((System.Reflection.FieldInfo)field).Name);
                }

                New_DdlGraphProperty.Items.Add(String.Empty);
                New_DdlGraphPropertyToDisplay.Items.Add(String.Empty);
                foreach (object field in typeof(GraphProperty).GetFields())
                {
                    string prop = ((System.Reflection.FieldInfo)field).Name;
                    if (AzureCP.GetGraphPropertyValue(new User(), prop) == null)
                    {
                        continue;
                    }
                    //if (AzureCP.GetGraphPropertyValue(new Group(), prop) == null) continue;
                    //if (AzureCP.GetGraphPropertyValue(new Role(), prop) == null) continue;

                    New_DdlGraphProperty.Items.Add(prop);
                    New_DdlGraphPropertyToDisplay.Items.Add(prop);
                }
            }

            BuildAttributesListTable(this.IsPostBack);
        }