public override async Task <IDisplayResult> UpdateAsync(SmtpSettings section, BuildEditorContext context)
        {
            var user = _httpContextAccessor.HttpContext?.User;

            if (!await _authorizationService.AuthorizeAsync(user, Permissions.ManageEmailSettings))
            {
                return(null);
            }

            if (context.GroupId == GroupId)
            {
                var previousPassword = section.Password;
                await context.Updater.TryUpdateModelAsync(section, Prefix);

                // Restore password if the input is empty, meaning that it has not been reset.
                if (string.IsNullOrWhiteSpace(section.Password))
                {
                    section.Password = previousPassword;
                }
                else
                {
                    // encrypt the password
                    var protector = _dataProtectionProvider.CreateProtector(nameof(SmtpSettingsConfiguration));
                    section.Password = protector.Protect(section.Password);
                }

                // Reload the tenant to apply the settings
                _orchardHost.ReloadShellContext(_currentShellSettings);
            }

            return(await EditAsync(section, context));
        }
        public async Task <IActionResult> Reload(string id)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageTenants))
            {
                return(Unauthorized());
            }

            if (!IsDefaultShell())
            {
                return(Unauthorized());
            }

            var shellContext = _orchardHost
                               .ListShellContexts()
                               .OrderBy(x => x.Settings.Name)
                               .Where(x => string.Equals(x.Settings.Name, id, StringComparison.OrdinalIgnoreCase))
                               .FirstOrDefault();

            if (shellContext == null)
            {
                return(NotFound());
            }

            // Generating routes can fail while the tenant is recycled as routes can use services.
            // It could be fixed by waiting for the next request or the end of the current one
            // to actually release the tenant. Right now we render the url before recycling the tenant.

            var redirectUrl = Url.Action(nameof(Index));

            var shellSettings = shellContext.Settings;

            _orchardHost.ReloadShellContext(shellSettings);

            return(Redirect(redirectUrl));
        }
Exemple #3
0
        public override async Task <IDisplayResult> UpdateAsync(OpenIdServerSettings settings, IUpdateModel updater, string groupId)
        {
            var user = _httpContextAccessor.HttpContext?.User;

            if (user == null || !await _authorizationService.AuthorizeAsync(user, Permissions.ManageServerSettings))
            {
                return(null);
            }

            if (groupId == SettingsGroupId)
            {
                var model = new OpenIdServerSettingsViewModel();
                await updater.TryUpdateModelAsync(model, Prefix);

                settings.TestingModeEnabled          = model.TestingModeEnabled;
                settings.AccessTokenFormat           = model.AccessTokenFormat;
                settings.Authority                   = model.Authority;
                settings.CertificateStoreLocation    = model.CertificateStoreLocation;
                settings.CertificateStoreName        = model.CertificateStoreName;
                settings.CertificateThumbprint       = model.CertificateThumbprint;
                settings.EnableTokenEndpoint         = model.EnableTokenEndpoint;
                settings.EnableAuthorizationEndpoint = model.EnableAuthorizationEndpoint;
                settings.EnableLogoutEndpoint        = model.EnableLogoutEndpoint;
                settings.EnableUserInfoEndpoint      = model.EnableUserInfoEndpoint;
                settings.AllowPasswordFlow           = model.AllowPasswordFlow;
                settings.AllowClientCredentialsFlow  = model.AllowClientCredentialsFlow;
                settings.AllowAuthorizationCodeFlow  = model.AllowAuthorizationCodeFlow;
                settings.AllowRefreshTokenFlow       = model.AllowRefreshTokenFlow;
                settings.AllowImplicitFlow           = model.AllowImplicitFlow;
                settings.UseRollingTokens            = model.UseRollingTokens;

                foreach (var result in await _serverService.ValidateSettingsAsync(settings))
                {
                    if (result != ValidationResult.Success)
                    {
                        var key = result.MemberNames.FirstOrDefault() ?? string.Empty;
                        updater.ModelState.AddModelError(key, result.ErrorMessage);
                    }
                }

                // If the settings are valid, reload the current tenant.
                if (updater.ModelState.IsValid)
                {
                    _shellHost.ReloadShellContext(_shellSettings);
                }
            }

            return(Edit(settings));
        }
        public override async Task <IDisplayResult> UpdateAsync(NoCaptchaSettings section, IUpdateModel updater, string groupId)
        {
            if (groupId == GroupId)
            {
                var model = new NoCaptchaSettingsViewModel();

                if (await updater.TryUpdateModelAsync(model, Prefix))
                {
                    section.SiteKey    = model.SiteKey?.Trim();
                    section.SiteSecret = model.SiteSecret?.Trim();

                    // Reload tenant to apply settings.
                    _shellHost.ReloadShellContext(_shellSettings);
                }
            }

            return(Edit(section));
        }
Exemple #5
0
        public override async Task <IDisplayResult> UpdateAsync(OpenIdValidationSettings settings, IUpdateModel updater, string groupId)
        {
            var user = _httpContextAccessor.HttpContext?.User;

            if (user == null || !await _authorizationService.AuthorizeAsync(user, Permissions.ManageValidationSettings))
            {
                return(null);
            }

            if (groupId == SettingsGroupId)
            {
                var model = new OpenIdValidationSettingsViewModel();

                await updater.TryUpdateModelAsync(model, Prefix);

                settings.Authority = model.Authority?.Trim();
                settings.Audience  = model.Audience?.Trim();
                settings.Tenant    = model.Tenant;

                foreach (var result in await _validationService.ValidateSettingsAsync(settings))
                {
                    if (result != ValidationResult.Success)
                    {
                        var key = result.MemberNames.FirstOrDefault() ?? string.Empty;
                        updater.ModelState.AddModelError(key, result.ErrorMessage);
                    }
                }

                // If the settings are valid, reload the current tenant.
                if (updater.ModelState.IsValid)
                {
                    _shellHost.ReloadShellContext(_shellSettings);
                }
            }

            return(Edit(settings));
        }
        public override async Task <IDisplayResult> UpdateAsync(OpenIdClientSettings settings, IUpdateModel updater, string groupId)
        {
            var user = _httpContextAccessor.HttpContext?.User;

            if (user == null || !await _authorizationService.AuthorizeAsync(user, Permissions.ManageClientSettings))
            {
                return(null);
            }

            if (groupId == SettingsGroupId)
            {
                var previousClientSecret = settings.ClientSecret;
                var model = new OpenIdClientSettingsViewModel();
                await updater.TryUpdateModelAsync(model, Prefix);

                model.Scopes = model.Scopes ?? string.Empty;

                settings.DisplayName           = model.DisplayName;
                settings.Scopes                = model.Scopes.Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
                settings.Authority             = model.Authority;
                settings.CallbackPath          = model.CallbackPath;
                settings.ClientId              = model.ClientId;
                settings.SignedOutCallbackPath = model.SignedOutCallbackPath;
                settings.SignedOutRedirectUri  = model.SignedOutRedirectUri;
                settings.ResponseMode          = model.ResponseMode;

                bool useClientSecret = true;

                if (model.UseCodeFlow)
                {
                    settings.ResponseType = OpenIdConnectResponseType.Code;
                }
                else if (model.UseCodeIdTokenFlow)
                {
                    settings.ResponseType = OpenIdConnectResponseType.CodeIdToken;
                }
                else if (model.UseCodeIdTokenTokenFlow)
                {
                    settings.ResponseType = OpenIdConnectResponseType.CodeIdTokenToken;
                }
                else if (model.UseCodeTokenFlow)
                {
                    settings.ResponseType = OpenIdConnectResponseType.CodeToken;
                }
                else if (model.UseIdTokenFlow)
                {
                    settings.ResponseType = OpenIdConnectResponseType.IdToken;
                    useClientSecret       = false;
                }
                else if (model.UseIdTokenTokenFlow)
                {
                    settings.ResponseType = OpenIdConnectResponseType.IdTokenToken;
                    useClientSecret       = false;
                }
                else
                {
                    settings.ResponseType = OpenIdConnectResponseType.None;
                    useClientSecret       = false;
                }

                if (!useClientSecret)
                {
                    model.ClientSecret = previousClientSecret = null;
                }

                // Restore the client secret if the input is empty (i.e if it hasn't been reset).
                if (string.IsNullOrEmpty(model.ClientSecret))
                {
                    settings.ClientSecret = previousClientSecret;
                }
                else
                {
                    var protector = _dataProtectionProvider.CreateProtector(nameof(OpenIdClientConfiguration));
                    settings.ClientSecret = protector.Protect(model.ClientSecret);
                }

                foreach (var result in await _clientService.ValidateSettingsAsync(settings))
                {
                    if (result != ValidationResult.Success)
                    {
                        var key = result.MemberNames.FirstOrDefault() ?? string.Empty;
                        updater.ModelState.AddModelError(key, result.ErrorMessage);
                    }
                }

                // If the settings are valid, reload the current tenant.
                if (updater.ModelState.IsValid)
                {
                    _shellHost.ReloadShellContext(_shellSettings);
                }
            }

            return(Edit(settings));
        }