Ejemplo n.º 1
0
        public static IEnumerable <object> ProvidersJsonModel(WindowsAuthenticationSection section)
        {
            Dictionary <string, bool> providers = new Dictionary <string, bool>();

            foreach (string provider in section.Providers)
            {
                providers.Add(provider, true);
            }
            foreach (string provider in ProvidersUtil.GetAvailableProvidersList())
            {
                if (!providers.ContainsKey(provider))
                {
                    providers.Add(provider, false);
                }
            }

            return(providers.Select(kvp =>
                                    new {
                name = kvp.Key,
                enabled = kvp.Value
            }
                                    ));
        }
Ejemplo n.º 2
0
        public static void UpdateSettings(dynamic model, Site site, string path, string configPath = null)
        {
            if (model == null)
            {
                throw new ApiArgumentException("model");
            }

            var section = GetSection(site, path, configPath);

            try {
                DynamicHelper.If <bool>((object)model.enabled, v => section.Enabled = v);
                DynamicHelper.If <bool>((object)model.use_kernel_mode, v => section.UseKernelMode = v);
                DynamicHelper.If <TokenChecking>((object)model.token_checking, v => section.TokenCheckingAttribute = v);

                if (model.providers != null)
                {
                    if (!(model.providers is JArray))
                    {
                        throw new ApiArgumentException("providers");
                    }

                    IEnumerable <dynamic> providers = model.providers;
                    var enabledProviders            = section.Providers;
                    var availableProviders          = ProvidersUtil.GetAvailableProvidersList();

                    foreach (dynamic provider in providers)
                    {
                        if (!(provider is JObject))
                        {
                            throw new ApiArgumentException("provider");
                        }
                        if (string.IsNullOrEmpty(DynamicHelper.Value(provider.name)))
                        {
                            throw new ApiArgumentException("provider.name");
                        }
                        if (DynamicHelper.To <bool>(provider.enabled) == null)
                        {
                            throw new ApiArgumentException("provider.enabled");
                        }

                        string name            = DynamicHelper.Value(provider.name);
                        bool   providerEnabled = DynamicHelper.To <bool>(provider.enabled);

                        if (providerEnabled && !enabledProviders.Contains(name))
                        {
                            // Make sure the provider is available to be added to enabled providers
                            if (!availableProviders.Contains(name))
                            {
                                throw new NotFoundException($"provider: {name}");
                            }

                            enabledProviders.Add(name);
                        }
                        else if (!providerEnabled && enabledProviders.Contains(name))
                        {
                            enabledProviders.Remove(name);
                        }
                    }

                    section.Providers = enabledProviders;
                }

                if (model.metadata != null)
                {
                    DynamicHelper.If <OverrideMode>((object)model.metadata.override_mode, v => {
                        section.OverrideMode = v;
                    });
                }
            }
            catch (FileLoadException e) {
                throw new LockedException(section.SectionPath, e);
            }
            catch (DirectoryNotFoundException e) {
                throw new ConfigScopeNotFoundException(e);
            }
        }