Exemplo n.º 1
0
        /// <summary>
        /// Generate default clients, identity and api resources
        /// </summary>
        private static async Task EnsureSeedIdentityServerData(ApplicationSsoContext context, IConfiguration configuration)
        {
            if (!context.Clients.Any())
            {
                foreach (var client in Clients.GetAdminClient(configuration).ToList())
                {
                    await context.Clients.AddAsync(client.ToEntity());
                }

                await context.SaveChangesAsync();
            }

            if (!context.IdentityResources.Any())
            {
                var identityResources = ClientResources.GetIdentityResources().ToList();

                foreach (var resource in identityResources)
                {
                    await context.IdentityResources.AddAsync(resource.ToEntity());
                }

                await context.SaveChangesAsync();
            }

            if (!context.ApiResources.Any())
            {
                foreach (var resource in ClientResources.GetApiResources().ToList())
                {
                    await context.ApiResources.AddAsync(resource.ToEntity());
                }

                await context.SaveChangesAsync();
            }
        }
Exemplo n.º 2
0
        public async Task ShouldNotTruncateSensitiveDataWhenUserIsAdmin()
        {
            var anotherSetting = GlobalSettingsFaker.GenerateSetting(key: "Smtp:Password", sensitive: true).Generate();

            _database.GlobalConfigurationSettings.Add(anotherSetting);
            await _database.SaveChangesAsync();

            var data = await _globalAppService.GetPrivateSettings();

            data.Smtp.Password.Should().NotContain("Sensitive Data");
        }
Exemplo n.º 3
0
        private static async Task EnsureSeedGlobalConfigurationData(ApplicationSsoContext context,
                                                                    IConfiguration configuration, IWebHostEnvironment env)
        {
            if (!context.GlobalConfigurationSettings.Any())
            {
                await context.GlobalConfigurationSettings.AddAsync(new GlobalConfigurationSettings("Smtp:Server", configuration.GetSection("EmailConfiguration:SmtpServer").Value, false, false));

                await context.GlobalConfigurationSettings.AddAsync(new GlobalConfigurationSettings("Smtp:Port", configuration.GetSection("EmailConfiguration:SmtpPort").Value, false, false));

                await context.GlobalConfigurationSettings.AddAsync(new GlobalConfigurationSettings("Smtp:UseSsl", configuration.GetSection("EmailConfiguration:UseSsl").Value, false, false));

                await context.GlobalConfigurationSettings.AddAsync(new GlobalConfigurationSettings("Smtp:Username", configuration.GetSection("EmailConfiguration:SmtpUsername").Value, true, false));

                await context.GlobalConfigurationSettings.AddAsync(new GlobalConfigurationSettings("Smtp:Password", configuration.GetSection("EmailConfiguration:SmtpPassword").Value, true, false));

                await context.GlobalConfigurationSettings.AddAsync(new GlobalConfigurationSettings("SendEmail", configuration.GetSection("EmailConfiguration:SendEmail").Value, false, false));

                await context.SaveChangesAsync();
            }

            if (!context.Emails.Any())
            {
                var newUserEmail       = File.ReadAllText(Path.Combine(env.ContentRootPath, @"Assets/templates/new-user-email.html"));
                var resetPasswordEmail = File.ReadAllText(Path.Combine(env.ContentRootPath, @"Assets/templates/reset-password-email.html"));
                var template           = File.ReadAllText(Path.Combine(env.ContentRootPath, @"Assets/templates/default-template.html"));

                await context.Emails.AddAsync(new Email(newUserEmail, "Welcome to JP Project - Confirm your e-mail", new Sender("*****@*****.**", "JP Team"), EmailType.NewUser, null));

                await context.Emails.AddAsync(new Email(newUserEmail, "Welcome to JP Project - Confirm your e-mail", new Sender("*****@*****.**", "JP Team"), EmailType.NewUserWithoutPassword, null));

                await context.Emails.AddAsync(new Email(resetPasswordEmail, "JP Project - Reset Password", new Sender("*****@*****.**", "JP Team"), EmailType.RecoverPassword, null));

                await context.Templates.AddRangeAsync(new Template(template, "JP Team", "default-template", Users.GetEmail(configuration)));

                await context.SaveChangesAsync();
            }
        }
Exemplo n.º 4
0
        public async Task <bool> Commit()
        {
            var linesModified = await _context.SaveChangesAsync();

            return(linesModified > 0);
        }