コード例 #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();
        }
コード例 #2
0
 public override void FeatureUpgrading(SPFeatureReceiverProperties properties, string upgradeActionName, IDictionary <string, string> parameters)
 {
     SPSecurity.RunWithElevatedPrivileges(delegate()
     {
         //this.RemovePersistedObject();
         AzureCPLogging svc = AzureCPLogging.Local;
     });
 }
コード例 #3
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";
        }
コード例 #4
0
 private void ExecBaseFeatureActivated(Microsoft.SharePoint.SPFeatureReceiverProperties properties)
 {
     // Wrapper function for base FeatureActivated.
     // Used because base keywork can lead to unverifiable code inside lambda expression
     base.FeatureActivated(properties);
     SPSecurity.RunWithElevatedPrivileges(delegate()
     {
         AzureCPLogging svc = AzureCPLogging.Local;
     });
 }
コード例 #5
0
 public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
 {
     SPSecurity.RunWithElevatedPrivileges(delegate()
     {
         base.RemoveClaimProvider(AzureCP._ProviderInternalName);
         //var trust = LDAPCP.GetSPTrustAssociatedWithCP(LDAPCP._ProviderInternalName);
         //if (trust != null)
         //{
         //    trust.ClaimProviderName = null;
         //    trust.Update();
         //}
         this.RemovePersistedObject();
         AzureCPLogging.Unregister();
     });
 }
コード例 #6
0
ファイル: AzureCPConfig.cs プロジェクト: kouweizhong/AzureCP
        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);
        }
コード例 #7
0
ファイル: AzureCPConfig.cs プロジェクト: kouweizhong/AzureCP
        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);
        }
コード例 #8
0
ファイル: AzureCPConfig.cs プロジェクト: kouweizhong/AzureCP
        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;
        }
コード例 #9
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);
        }
コード例 #10
0
ファイル: AzureCPConfig.cs プロジェクト: kouweizhong/AzureCP
        /// <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);
        }
コード例 #11
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;
        }
コード例 #12
0
        protected void ValidateAzureTenantConnection()
        {
            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;
            }

            ActiveDirectoryClient activeDirectoryClient;

            try
            {
                string tenantName   = this.TxtTenantName.Text;
                string tenantId     = this.TxtTenantId.Text;
                string clientId     = this.TxtClientId.Text;
                string clientSecret = this.TxtClientSecret.Text;

                // Get access token
                activeDirectoryClient = AuthenticationHelper.GetActiveDirectoryClientAsApplication(tenantName, tenantId, clientId, clientSecret);
                // Get information on tenant
                ITenantDetail tenant = activeDirectoryClient.TenantDetails
                                       .Where(tDetail => tDetail.ObjectId.Equals(tenantId))
                                       .ExecuteAsync()
                                       .Result.CurrentPage.FirstOrDefault();
                if (tenant != null)
                {
                    this.LabelTestTenantConnectionOK.Text  = TextConnectionSuccessful;
                    this.LabelTestTenantConnectionOK.Text += "<br>" + tenant.DisplayName;
                }
                else
                {
                    this.LabelErrorTestLdapConnection.Text = TextErrorTestAzureADConnectionTenantNotFound = "Tenant was not found.";
                }
                activeDirectoryClient = null;
            }
            catch (AuthenticationException ex)
            {
                //You should implement retry and back-off logic per the guidance given here:http://msdn.microsoft.com/en-us/library/dn168916.aspx
                //InnerException Message will contain the HTTP error status codes mentioned in the link above
                this.LabelErrorTestLdapConnection.Text = String.Format(TextErrorTestAzureADConnection, ex.Message);
                if (ex.InnerException != null)
                {
                    this.LabelErrorTestLdapConnection.Text += String.Format("<br>Error detail: {0}", ex.InnerException.Message);
                }
                AzureCPLogging.LogException("AzureCP", "while testing connectivity", AzureCPLogging.Categories.Configuration, ex);
            }
            catch (Exception ex)
            {
                //You should implement retry and back-off logic per the guidance given here:http://msdn.microsoft.com/en-us/library/dn168916.aspx
                //InnerException Message will contain the HTTP error status codes mentioned in the link above
                this.LabelErrorTestLdapConnection.Text = String.Format(TextErrorTestAzureADConnection, ex.Message);
                if (ex.InnerException != null)
                {
                    this.LabelErrorTestLdapConnection.Text += String.Format("<br>Error detail: {0}", ex.InnerException.Message);
                }
                AzureCPLogging.LogException("AzureCP", "while testing connectivity", AzureCPLogging.Categories.Configuration, ex);
            }

            //try
            //{

            //    // get OAuth AccessToken using Client Credentials
            //    string tenantName = this.TxtTenantName.Text;
            //    string authString = "https://login.windows.net/" + tenantName;

            //    AuthenticationContext authenticationContext = new AuthenticationContext(authString, false);

            //    // Config for OAuth client credentials
            //    string clientId = this.TxtClientId.Text;
            //    string clientSecret = this.TxtClientSecret.Text;
            //    ClientCredential clientCred = new ClientCredential(clientId, clientSecret);
            //    string resource = "https://graph.windows.net";

            //    AuthenticationResult authenticationResult = authenticationContext.AcquireToken(resource, clientCred);
            //    string accessToken = authenticationResult.AccessToken;

            //    GraphConnection graphConnection;
            //    Guid ClientRequestId = Guid.NewGuid();
            //    GraphSettings graphSettings = new GraphSettings();
            //    graphSettings.ApiVersion = "2013-11-08";
            //    graphSettings.GraphDomainName = "graph.windows.net";
            //    graphConnection = new GraphConnection(accessToken, ClientRequestId, graphSettings);

            //    this.LabelTestTenantConnectionOK.Text = TextConnectionSuccessful;
            //}
            //catch (Exception ex)
            //{
            //    this.LabelErrorTestLdapConnection.Text = String.Format(TextErrorTestAzureADConnection, ex.Message);
            //}
        }
コード例 #13
0
ファイル: AzureCPLogging.cs プロジェクト: Yvand/AzureCP
 public static void LogException(string ProviderInternalName, string faultyAction, AzureCPLogging.Categories category, Exception ex)
 {
     try
     {
         string message = "[{0}] Unexpected error {1}: {2}: {3}, Callstack: {4}";
         if (ex is AggregateException)
         {
             var aggEx = ex as AggregateException;
             foreach (var innerEx in aggEx.InnerExceptions)
             {
                 if (innerEx.InnerException != null)
                     message = String.Format(message, ProviderInternalName, faultyAction, innerEx.InnerException.GetType().FullName, innerEx.InnerException.Message, innerEx.InnerException.StackTrace);
                 else
                     message = String.Format(message, ProviderInternalName, faultyAction, innerEx.GetType().FullName, innerEx.Message, innerEx.StackTrace);
                 WriteTrace(category, TraceSeverity.Unexpected, message);
             }
         }
         else
         {
             if (ex.InnerException != null)
                 message = String.Format(message, ProviderInternalName, faultyAction, ex.InnerException.GetType().FullName, ex.InnerException.Message, ex.InnerException.StackTrace);
             else
                 message = String.Format(message, ProviderInternalName, faultyAction, ex.GetType().FullName, ex.Message, ex.StackTrace);
             WriteTrace(category, TraceSeverity.Unexpected, message);
         }
     }
     catch
     {   // Don't want to do anything if logging goes wrong, just ignore and continue
     }
 }
コード例 #14
0
ファイル: AzureCPLogging.cs プロジェクト: Yvand/AzureCP
 public static void Log(string message, TraceSeverity traceSeverity, EventSeverity eventSeverity, AzureCPLogging.Categories category)
 {
     try
     {
         WriteTrace(category, traceSeverity, message);
         //LdapcpLoggingService.WriteEvent(LdapcpLoggingService.Categories.LDAPCP, eventSeverity, message);
     }
     catch
     {   // Don't want to do anything if logging goes wrong, just ignore and continue
     }
 }