コード例 #1
0
ファイル: AzureCache.cs プロジェクト: penartur/ENTech-Store
        private DataCache GetDataCache(string name)
        {
            DataCache cache = null;

            HandleBadDataCacheBug(() =>
            {
                var factorySecurity = new DataCacheSecurity(EnvironmentUtils.GetConfigSettingStr("AzureCache_Token"));

                var factoryConfig = new DataCacheFactoryConfiguration();
                factoryConfig.SecurityProperties   = factorySecurity;
                factoryConfig.AutoDiscoverProperty = new DataCacheAutoDiscoverProperty(true,
                                                                                       EnvironmentUtils.GetConfigSettingStr(
                                                                                           "AzureCache_Endpoint"));

                factoryConfig.UseLegacyProtocol      = false;
                factoryConfig.MaxConnectionsToServer = 1;
                factoryConfig.ChannelOpenTimeout     = TimeSpan.FromSeconds(3);
                factoryConfig.RequestTimeout         = TimeSpan.FromSeconds(3);

                factoryConfig.IsCompressionEnabled = true;

                var dataCacheFactory = new DataCacheFactory(factoryConfig);

                cache = dataCacheFactory.GetCache(name);
            });

            return(cache);
        }
コード例 #2
0
        private void SetSecuritySettings(DataCacheFactoryConfiguration config)
        {
            string            securityModeValue = WebConfigSettings.AzureCacheSecurityMode.ToLowerInvariant();
            string            securityAuthValue = WebConfigSettings.AzureCacheAuthorizationInfo;
            bool              useSsl            = WebConfigSettings.AzureCacheUseSsl;
            DataCacheSecurity securityProps;

            switch (securityModeValue)
            {
            case "message":

                if (securityAuthValue.Length > 0)
                {
                    SecureString secureToken = new SecureString();
                    foreach (var ch in securityAuthValue)
                    {
                        secureToken.AppendChar(ch);
                    }

                    securityProps             = new DataCacheSecurity(secureToken, useSsl);
                    config.SecurityProperties = securityProps;
                }

                break;

            case "transport":

                securityProps             = new DataCacheSecurity(DataCacheSecurityMode.Transport, DataCacheProtectionLevel.None);
                config.SecurityProperties = securityProps;

                break;
            }
        }
コード例 #3
0
        public CloudCacheService(IConfiguration configuration)
        {
            DataCacheFactoryConfiguration cacheConfig = new DataCacheFactoryConfiguration();
            cacheConfig.Servers = new[] {
                new DataCacheServerEndpoint(configuration.AzureCacheEndpoint, 22233)
            };
            SecureString key = configuration.AzureCacheKey.ToSecureString();
            DataCacheSecurity security = new DataCacheSecurity(key);
            cacheConfig.SecurityProperties = security;

            _cacheFactory = new DataCacheFactory(cacheConfig);
        }
コード例 #4
0
        public CloudCacheService(IConfiguration configuration)
        {
            DataCacheFactoryConfiguration cacheConfig = new DataCacheFactoryConfiguration();

            cacheConfig.Servers = new[] {
                new DataCacheServerEndpoint(configuration.AzureCacheEndpoint, 22233)
            };
            SecureString      key      = configuration.AzureCacheKey.ToSecureString();
            DataCacheSecurity security = new DataCacheSecurity(key);

            cacheConfig.SecurityProperties = security;

            _cacheFactory = new DataCacheFactory(cacheConfig);
        }
コード例 #5
0
 private DataCacheSecurity GetSecurityToken(Boolean SslEnabled)
 {
     DataCacheSecurity dataCacheSecurity;
     using (SecureString secureString = new SecureString())
     {
         String authenticationToken = RoleEnvironment.GetConfigurationSettingValue("AuthenticationToken");
         foreach (Char c in authenticationToken)
         {
             secureString.AppendChar(c);
         }
         secureString.MakeReadOnly();
         dataCacheSecurity = new DataCacheSecurity(secureString, SslEnabled);
     }
     return dataCacheSecurity;
 }
コード例 #6
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            if (myCache == null)
            {
                try
                {
                    DataCacheServerEndpoint[] servers = new DataCacheServerEndpoint[1];
                    servers[0] = new DataCacheServerEndpoint(txtCacheServer.Text, int.Parse(txtPort.Text));
                    DataCacheFactoryConfiguration factoryConfig = new DataCacheFactoryConfiguration();
                    factoryConfig.Servers = servers;


                    if (!(checkBoxSecurity.Checked))
                    {
                        DataCacheSecurity security = new DataCacheSecurity(DataCacheSecurityMode.None, DataCacheProtectionLevel.None);
                        factoryConfig.SecurityProperties = security;
                    }

                    //You must set the security authentication account type to DomainAccount on the client side
                    //when the caching service identity is a domain account. The default type is SystemAccount.
                    if (checkBoxDomainAcc.Checked)
                    {
                        factoryConfig.DataCacheServiceAccountType = DataCacheServiceAccountType.DomainAccount;
                    }

                    if (checkBoxLocalCache.Checked)
                    {
                        //TimeSpan localTimeout = new TimeSpan(0, 1, 0);
                        TimeSpan localTimeout = TimeSpan.FromSeconds(Convert.ToDouble(txtTimeout.Text));
                        DataCacheLocalCacheProperties localCacheConfig = new DataCacheLocalCacheProperties(10000,
                                                                                                           localTimeout, DataCacheLocalCacheInvalidationPolicy.TimeoutBased);
                        factoryConfig.LocalCacheProperties = localCacheConfig;
                    }


                    myCacheFactory = new DataCacheFactory(factoryConfig);
                    myCache        = myCacheFactory.GetCache(txtCacheName.Text);

                    //this.Text = "AppFabric Test Client has connected to Cache Cluster...";
                    UpdateStatus("You have connected to the Cache Cluster.");
                    lblConnectionStatus.Text = "CONNECTED";
                }
                catch (Exception ex)
                {
                    HandleException(ex);
                }
            }
        }
コード例 #7
0
        private DataCacheFactoryConfiguration GetDataCacheConfiguration(string endpointString, string accessKey)
        {
            // Setup the DataCacheFactory configuration.
            DataCacheFactoryConfiguration factoryConfig = new DataCacheFactoryConfiguration();

            factoryConfig.AutoDiscoverProperty = new DataCacheAutoDiscoverProperty(true, GetAzureCacheEndpointFromString(endpointString));

            // Setup DataCacheSecurity configuration.
            using (SecureString secureACSKey = CreateSecureString(accessKey))
            {
                DataCacheSecurity factorySecurity = new DataCacheSecurity(secureACSKey, false);
                factoryConfig.SecurityProperties = factorySecurity;
            }

            return(factoryConfig);
        }
コード例 #8
0
ファイル: AzureCache.cs プロジェクト: hugebdu/MapReduce.JS
        public AzureCache()
        {
            var token = new System.Security.SecureString();
            foreach (var c in AuthenticationToken.ToCharArray())
            {
                token.AppendChar(c);
            }

            var securityProperties = new DataCacheSecurity(token);

            var factory = new DataCacheFactory(new DataCacheFactoryConfiguration()
            {
                SecurityProperties = securityProperties,
                Servers = new List<DataCacheServerEndpoint> { new DataCacheServerEndpoint(CacheHost, CachePort) }
            });
            
            this._cacheClient = factory.GetDefaultCache();
        }
コード例 #9
0
        private void SetSecuritySettings(CacheConfig config, DataCacheFactoryConfiguration factoryConfig)
        {
            // If appfabric service is running as a domain account the client must specify
            // http://blogs.msdn.com/b/distributedservices/archive/2012/10/29/authenticationexception-in-appfabric-1-1-caching-for-windows-server.aspx
            if (config.ProviderSpecificValues.ContainsKey(AppFabricConstants.CONFIG_UseDomainServiceAccount))
            {
                bool useDomainServiceAccount;
                var  converted = bool.TryParse(config.ProviderSpecificValues[AppFabricConstants.CONFIG_UseDomainServiceAccount] ?? "false", out useDomainServiceAccount);
                if (converted && useDomainServiceAccount)
                {
                    _logger.WriteInfoMessage("Setting AppFabric DataCacheServiceAccountType to DomainAccount.");
                    factoryConfig.DataCacheServiceAccountType = DataCacheServiceAccountType.DomainAccount;
                }
            }

            string securityModeValue = null;

            // Set the security mode if required
            if (config.ProviderSpecificValues.ContainsKey(AppFabricConstants.CONFIG_SecurityModeKey))
            {
                securityModeValue = config.ProviderSpecificValues[AppFabricConstants.CONFIG_SecurityModeKey];
                _logger.WriteInfoMessage(string.Format("Setting AppFabric security mode:[{0}]", securityModeValue));
            }

            // Set the authorization info/value if required
            string securityAuthValue = null;

            if (config.ProviderSpecificValues.ContainsKey(AppFabricConstants.CONFIG_SecurityMessageAuthorisationKey))
            {
                securityAuthValue = config.ProviderSpecificValues[AppFabricConstants.CONFIG_SecurityMessageAuthorisationKey];
                _logger.WriteInfoMessage("Setting AppFabric security Authorisation value using supplied key");
            }

            string useSslValue = null;

            if (config.ProviderSpecificValues.ContainsKey(AppFabricConstants.CONFIG_UseSslKey))
            {
                useSslValue = config.ProviderSpecificValues[AppFabricConstants.CONFIG_UseSslKey];
                _logger.WriteInfoMessage(string.Format("AppFabric Use Ssl: [{0}]", useSslValue));
            }

            string protectionLevelValue = null;

            if (config.ProviderSpecificValues.ContainsKey(AppFabricConstants.CONFIG_ProtectionLevelKey))
            {
                protectionLevelValue = config.ProviderSpecificValues[AppFabricConstants.CONFIG_ProtectionLevelKey];
                _logger.WriteInfoMessage(string.Format("AppFabric Protection Mode: [{0}]", protectionLevelValue));
            }

            var normalisedSecurityMode    = string.IsNullOrWhiteSpace(securityModeValue) ? string.Empty : securityModeValue.ToLowerInvariant();
            var normalisedSslValue        = string.IsNullOrWhiteSpace(useSslValue) ? string.Empty : useSslValue.ToLowerInvariant();
            var normalisedProtectionLevel = string.IsNullOrWhiteSpace(protectionLevelValue) ? string.Empty : protectionLevelValue.ToLowerInvariant();

            if (!string.IsNullOrWhiteSpace(normalisedSecurityMode) && normalisedSecurityMode != AppFabricConstants.CONFIG_SecurityMode_None)
            {
                if (normalisedSecurityMode == AppFabricConstants.CONFIG_SecurityMode_Message)
                {
                    var secureToken = new SecureString();
                    foreach (var ch in securityAuthValue)
                    {
                        secureToken.AppendChar(ch);
                    }
                    bool useSsl = false;
                    if (normalisedSslValue == CacheConstants.ConfigValueTrueText || normalisedSslValue == CacheConstants.ConfigValueTrueNumeric)
                    {
                        useSsl = true;
                    }
                    DataCacheSecurity securityProps = new DataCacheSecurity(secureToken, useSsl);
                    factoryConfig.SecurityProperties = securityProps;
                }

                var actualProtectionLevel = DataCacheProtectionLevel.None;
                if (!string.IsNullOrWhiteSpace(normalisedProtectionLevel))
                {
                    if (normalisedProtectionLevel == AppFabricConstants.CONFIG_ProtectionLevel_Sign)
                    {
                        actualProtectionLevel = DataCacheProtectionLevel.Sign;
                    }
                    else if (normalisedProtectionLevel == AppFabricConstants.CONFIG_ProtectionLevel_EncryptAndSign)
                    {
                        actualProtectionLevel = DataCacheProtectionLevel.EncryptAndSign;
                    }
                }

                _logger.WriteInfoMessage(string.Format("AppFabric Protection Level:[{0}]", actualProtectionLevel));

                if (normalisedSecurityMode == AppFabricConstants.CONFIG_SecurityMode_Transport)
                {
                    DataCacheSecurity securityProps = new DataCacheSecurity(DataCacheSecurityMode.Transport, actualProtectionLevel);
                    factoryConfig.SecurityProperties = securityProps;
                }

                if (normalisedSecurityMode == AppFabricConstants.CONFIG_SecurityMode_None)
                {
                    DataCacheSecurity securityProps = new DataCacheSecurity(DataCacheSecurityMode.None, actualProtectionLevel);
                    factoryConfig.SecurityProperties = securityProps;
                }
            }
        }
コード例 #10
0
 internal DataCacheSecurity(DataCacheSecurity other)
 {
     ProtectionLevel = other.ProtectionLevel;
     SecurityMode    = other.SecurityMode;
 }
コード例 #11
0
        private void SetSecuritySettings(DataCacheFactoryConfiguration config)
        {
            string securityModeValue = WebConfigSettings.AzureCacheSecurityMode.ToLowerInvariant();
            string securityAuthValue = WebConfigSettings.AzureCacheAuthorizationInfo;
            bool useSsl = WebConfigSettings.AzureCacheUseSsl;
            DataCacheSecurity securityProps;

            switch (securityModeValue)
            {
                case "message":

                    if (securityAuthValue.Length > 0)
                    {
                        SecureString secureToken = new SecureString();
                        foreach (var ch in securityAuthValue)
                        {
                            secureToken.AppendChar(ch);
                        }

                        securityProps = new DataCacheSecurity(secureToken, useSsl);
                        config.SecurityProperties = securityProps;
                    }

                    break;

                case "transport":

                    securityProps = new DataCacheSecurity(DataCacheSecurityMode.Transport,DataCacheProtectionLevel.None);
                    config.SecurityProperties = securityProps;

                    break;

            }
        }