Пример #1
0
 private static IEnumerable <AuthService> GetAuthServices()
 {
     return(from KeyElement keyElement in ConsumerConfigurationSection.GetSection().Keys
            where keyElement.Type != KeyElement.KeyType.Default && !string.IsNullOrEmpty(keyElement.ConsumerName)
            group keyElement by keyElement.ConsumerName
            into keyGroup
            let consumerKey = keyGroup.FirstOrDefault(key => key.Type == KeyElement.KeyType.Key)
                              let consumerSecret = keyGroup.FirstOrDefault(key => key.Type == KeyElement.KeyType.Secret)
                                                   select ToAuthService(keyGroup.Key, consumerKey, consumerSecret));
 }
Пример #2
0
        public bool SaveAuthKeys(List <AuthKey> authKeys)
        {
            SecurityContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
            if (!SetupInfo.IsVisibleSettings(ManagementType.ThirdPartyAuthorization.ToString()))
            {
                throw new BillingException(Resource.ErrorNotAllowedOption, "ThirdPartyAuthorization");
            }

            var changed = false;

            var mapKeys = new Dictionary <string, List <KeyElement> >();

            foreach (var authKey in authKeys.Where(authKey => KeyStorage.Get(authKey.Name) != authKey.Value))
            {
                var keyElement = ConsumerConfigurationSection.GetSection().Keys.GetKey(authKey.Name);

                if (keyElement != null && Providers.ContainsKey(keyElement.ConsumerName))
                {
                    RemoveOldNumberFromTwilio(Providers[keyElement.ConsumerName]);

                    if (!string.IsNullOrEmpty(authKey.Value))
                    {
                        if (!mapKeys.ContainsKey(keyElement.ConsumerName))
                        {
                            mapKeys.Add(keyElement.ConsumerName, new List <KeyElement>());
                        }
                        mapKeys[keyElement.ConsumerName].Add(keyElement);
                    }
                }


                KeyStorage.Set(authKey.Name, authKey.Value);
                changed = true;
            }

            foreach (var providerKeys in mapKeys)
            {
                if (!Providers[providerKeys.Key].ValidateKeys())
                {
                    foreach (var providerKey in providerKeys.Value)
                    {
                        KeyStorage.Set(providerKey.Name, null);
                    }
                    throw new ArgumentException(Resource.ErrorBadKeys);
                }
            }

            if (changed)
            {
                MessageService.Send(HttpContext.Current.Request, MessageAction.AuthorizationKeysSetting);
            }

            return(changed);
        }
Пример #3
0
        private static IAssociatedTokenManager GetTokenManager(string consumerKey, string consumerSecret)
        {
            IAssociatedTokenManager tokenManager = null;
            var section = ConsumerConfigurationSection.GetSection();

            if (section != null && !string.IsNullOrEmpty(section.ConnectionString))
            {
                tokenManager = new DbTokenManager(KeyStorage.Get(consumerKey), KeyStorage.Get(consumerSecret),
                                                  "auth_tokens",
                                                  ConfigurationManager.ConnectionStrings[section.ConnectionString]);
            }
            else
            {
                //For testing return the inmemorytokenmanager
                tokenManager = new InMemoryTokenManager(consumerKey, consumerSecret);
            }

            return(tokenManager);
        }
        public ConsumerConfig(ConsumerConfigurationSection config)
        {
            Validate(config);
            this.GroupId                  = config.GroupId;
            this.ConsumerId               = config.ConsumerId;
            this.SocketTimeoutMs          = config.SocketTimeout;
            this.SocketReceiveBufferBytes = config.SocketBufferSize;
            this.FetchMessageMaxBytes     = config.FetchSize;
            this.NumConsumerFetchers      = config.NumConsumerFetchers;
            this.AutoCommitEnable         = config.AutoCommit;
            this.AutoCommitIntervalMs     = config.AutoCommitInterval;
            this.QueuedMaxMessages        = config.MaxQueuedChunks;
            this.RebalanceMaxRetries      = config.MaxRebalanceRetries;
            this.FetchMinBytes            = config.MinFetchBytes;
            this.FetchWaitMaxMs           = config.MaxFetchWaitMs;
            this.RebalanceBackoffMs       = config.RebalanceBackoffMs;
            this.RefreshLeaderBackoffMs   = config.RefreshMetadataBackoffMs;
            this.AutoOffsetReset          = config.AutoOffsetReset;
            this.ConsumerTimeoutMs        = config.ConsumerTimeoutMs;
            this.ClientId                 = config.GroupId;

            this.SetZooKeeperConfiguration(config.ZooKeeperServers);
        }
 private static void Validate(ConsumerConfigurationSection config)
 {
     ValidateClientId(config.ClientId);
     ValidateGroupId(config.GroupId);
     ValidateAutoOffsetReset(config.AutoOffsetReset);
 }
 public ConsumerConfig(XElement xmlElement)
     : this(ConsumerConfigurationSection.FromXml(xmlElement))
 {
 }