cloudscribe.Core.Web.Components.SiteDataProtector.Protect C# (CSharp) Method

Protect() public method

public Protect ( ISiteSettings site ) : void
site ISiteSettings
return void
        public void Protect(ISiteSettings site)
        {
            if (site == null) { throw new ArgumentNullException("you must pass in an implementation of ISiteSettings"); }
            if (site.IsDataProtected) { return; }
            if (dataProtector == null) { return; }

            var countOfProtectedItems = 0;

            if (site.FacebookAppSecret.Length > 0)
            {
                try
                {
                    site.FacebookAppSecret = dataProtector.PersistentProtect(site.FacebookAppSecret);
                    countOfProtectedItems += 1;
                }
                catch (System.Security.Cryptography.CryptographicException ex)
                {
                    log.LogError("data protection error", ex);
                }

            }

            if (site.GoogleClientSecret.Length > 0)
            {
                try
                {
                    site.GoogleClientSecret = dataProtector.PersistentProtect(site.GoogleClientSecret);
                    countOfProtectedItems += 1;
                }
                catch (System.Security.Cryptography.CryptographicException ex)
                {
                    log.LogError("data protection error", ex);
                }

            }

            if (site.MicrosoftClientSecret.Length > 0)
            {
                try
                {
                    site.MicrosoftClientSecret = dataProtector.PersistentProtect(site.MicrosoftClientSecret);
                    countOfProtectedItems += 1;
                }
                catch (System.Security.Cryptography.CryptographicException ex)
                {
                    log.LogError("data protection error", ex);
                }

            }

            if (site.TwitterConsumerSecret.Length > 0)
            {
                try
                {
                    site.TwitterConsumerSecret = dataProtector.PersistentProtect(site.TwitterConsumerSecret);
                    countOfProtectedItems += 1;
                }
                catch (System.Security.Cryptography.CryptographicException ex)
                {
                    log.LogError("data protection error", ex);
                }

            }

            if (site.SmtpPassword.Length > 0)
            {
                try
                {
                    site.SmtpPassword = dataProtector.PersistentProtect(site.SmtpPassword);
                    countOfProtectedItems += 1;
                }
                catch (System.Security.Cryptography.CryptographicException ex)
                {
                    log.LogError("data protection error", ex);
                }

            }

            if (site.OidConnectAppSecret.Length > 0)
            {
                try
                {
                    site.OidConnectAppSecret = dataProtector.PersistentProtect(site.OidConnectAppSecret);
                    countOfProtectedItems += 1;
                }
                catch (System.Security.Cryptography.CryptographicException ex)
                {
                    log.LogError("data protection error", ex);
                }

            }

            if (site.DkimPrivateKey.Length > 0)
            {
                try
                {
                    site.DkimPrivateKey = dataProtector.PersistentProtect(site.DkimPrivateKey);
                    countOfProtectedItems += 1;
                }
                catch (System.Security.Cryptography.CryptographicException ex)
                {
                    log.LogError("data protection error", ex);
                }

            }

            if (site.SmsSecureToken.Length > 0)
            {
                try
                {
                    site.SmsSecureToken = dataProtector.PersistentProtect(site.SmsSecureToken);
                    countOfProtectedItems += 1;
                }
                catch (System.Security.Cryptography.CryptographicException ex)
                {
                    log.LogError("data protection error", ex);
                }

            }

            site.IsDataProtected = countOfProtectedItems > 0;

            
        }

Usage Example

Ejemplo n.º 1
0
        public async Task Update(ISiteSettings site)
        {
            await eventHandlers.HandleSitePreUpdate(site.Id).ConfigureAwait(false);

            dataProtector.Protect(site);
            if (site.Id == Guid.Empty)
            {
                site.Id = Guid.NewGuid();
                await commands.Update(site, CancellationToken.None);
            }
            else
            {
                await commands.Update(site, CancellationToken.None);
            }
            if (multiTenantOptions.Mode == MultiTenantMode.FolderName)
            {
                if (string.IsNullOrEmpty(site.SiteFolderName))
                {
                    cacheHelper.ClearCache("root");
                }
                else
                {
                    cacheHelper.ClearCache(site.SiteFolderName);
                }
            }
            else
            {
                if (_context != null && !string.IsNullOrEmpty(_context.Request.Host.Value))
                {
                    cacheHelper.ClearCache(_context.Request.Host.Value);
                }
            }

            await eventHandlers.HandleSiteUpdated(site).ConfigureAwait(false);
        }
All Usage Examples Of cloudscribe.Core.Web.Components.SiteDataProtector::Protect