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(); } }
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); }