Example #1
0
 public RoleController(RoleManager <ApplicationRole> roleMager,
                       IConfigurationDbContext configDbContext, ApplicationDbContext appDbContext)
 {
     _roleMager       = roleMager;
     _configDbContext = configDbContext;
     _appDbContext    = appDbContext;
 }
Example #2
0
        private static void EnsureSeedData(IConfigurationDbContext context)
        {
            foreach (var client in Clients.Get().ToList())
            {
                var dbRecords = context.Clients(client.ClientId).ToList();
                if (dbRecords.Count == 0)
                {
                    context.AddClient(client.ToEntity());
                }
            }

            foreach (var resource in Resources.GetIdentityResources().ToList())
            {
                var dbRecords = context.IdentityResources(resource.Name).ToList();
                if (dbRecords.Count == 0)
                {
                    context.AddIdentityResource(resource.ToEntity());
                }
            }

            foreach (var resource in Resources.GetApiResources().ToList())
            {
                var dbRecords = context.ApiResources(resource.Name).ToList();
                if (dbRecords.Count == 0)
                {
                    context.AddApiResource(resource.ToEntity());
                }
            }
        }
 public CorsPolicyService(IConfigurationDbContext context, ILogger<CorsPolicyService> logger)
 {
     if (context == null) throw new ArgumentNullException(nameof(context));
     
     _context = context;
     _logger = logger;
 }
Example #4
0
 public ApplicationResourceStore(IConfigurationDbContext context, IDbContextFactory <ConfigurationDbContext> factory)
 {
     var a = factory.Create(new DbContextFactoryOptions
     {
         EnvironmentName = "Dev"
     });
 }
        /// <summary>
        /// Add services to the application and configure service provider
        /// </summary>
        /// <param name="services">Collection of service descriptors</param>
        /// <param name="configuration">Configuration of the application</param>
        /// <returns>Configured service provider</returns>
        public static IServiceProvider ConfigureApplicationServices(this IServiceCollection services, IConfiguration configuration)
        {
            //add NopConfig configuration parameters
            services.ConfigureStartupConfig <NopConfig>(configuration.GetSection("Nop"));
            //add hosting configuration parameters
            services.ConfigureStartupConfig <HostingConfig>(configuration.GetSection("Hosting"));
            //add accessor to HttpContext
            services.AddHttpContextAccessor();

            //create, initialize and configure the engine
            var engine = EngineContext.Create();

            engine.Initialize(services);
            var serviceProvider = engine.ConfigureServices(services, configuration);

            if (DataSettingsManager.DatabaseIsInstalled)
            {
                //implement schedule tasks
                //database is already installed, so start scheduled tasks
                TaskManager.Instance.Initialize();
                TaskManager.Instance.Start();

                //log application start
                EngineContext.Current.Resolve <ILogger>().Information("Application started", null, null);

                IConfigurationDbContext context = EngineContext.Current.Resolve <IConfigurationDbContext>();
                context.CheckConflict();
                context.AddTemporal();
                context.AddChangeTracking(EngineContext.Current.Resolve <NopConfig>());
            }

            return(serviceProvider);
        }
Example #6
0
 public CreateModel(
     ApplicationDbContext context,
     IConfigurationDbContext identityConfig)
 {
     _context        = context;
     _identityConfig = identityConfig;
 }
Example #7
0
        private static void InitCustomSeedData(IConfigurationDbContext context)
        {
            if (!context.Clients.Any())
            {
                foreach (var client in PasswordInitConfig.GetClients())
                {
                    context.Clients.Add(client.ToEntity());
                }
                context.SaveChanges();
            }
            if (!context.ApiResources.Any())
            {
                foreach (var api in PasswordInitConfig.GetApiResources())
                {
                    context.ApiResources.Add(api.ToEntity());
                }
                context.SaveChanges();
            }

            //if (!context.IdentityResources.Any())
            //{
            //    foreach (var id in PasswordInitConfig.GetIdentityResources())
            //        context.IdentityResources.Add(id.ToEntity());
            //    context.SaveChanges();
            //}

            //init User
        }
        public ConfigBasedStoreInitializer(
            EntityFrameworkOptions options,
            ApplicationOptions appOptions,
            ILogger <ConfigBasedStoreInitializer> logger,
            MigrationDbContext migrationDbContext,
            IConfigurationDbContext configurationDbContext,
            IPersistedGrantDbContext persistedGrantDbContext,
            IUserAccountDbContext userAccountDbContext,
            IHostingEnvironment environment,
            IServiceProvider serviceProvider)
        {
            this._options                 = options;
            this._appOptions              = appOptions;
            this._logger                  = logger;
            this._migrationDbContext      = migrationDbContext;
            this._configurationDbContext  = configurationDbContext;
            this._persistedGrantDbContext = persistedGrantDbContext;
            this._userAccountDbContext    = userAccountDbContext;
            this._environment             = environment;

            this._serviceProvider = serviceProvider ??
                                    throw new ArgumentNullException(nameof(serviceProvider));

            this._logger.LogDebug("ConfigBasedStoreInitializer initialized");
        }
Example #9
0
        public async Task <Client> UpdateClientAsync(IConfigurationDbContext _configurationContext)
        {
            var updateClient = await _configurationContext.Clients.Include(a => a.AllowedScopes).Include(a => a.RedirectUris).Include(a => a.PostLogoutRedirectUris).Include(a => a.AllowedGrantTypes).Where(a => a.Id == id).FirstOrDefaultAsync();

            var newClientModel = new Client
            {
                ClientName             = ClientName,
                RedirectUris           = RedirectUris.Select(a => a.Trim()).ToList(),
                PostLogoutRedirectUris = PostLogoutRedirectUris.Select(a => a.Trim()).ToList(),
                AllowedScopes          = AllowedScopes
            }.ToEntity();

            updateClient.ClientName = newClientModel.ClientName;
            updateClient.RedirectUris.Clear();
            updateClient.RedirectUris = newClientModel.RedirectUris;

            updateClient.PostLogoutRedirectUris.Clear();
            updateClient.PostLogoutRedirectUris = newClientModel.PostLogoutRedirectUris;

            updateClient.AllowedScopes.Clear();
            updateClient.AllowedScopes = newClientModel.AllowedScopes;

            try
            {
                _configurationContext.Clients.Update(updateClient);

                await _configurationContext.SaveChangesAsync();

                return(updateClient.ToModel());
            }
            catch (Exception)
            {
                return(null);
            }
        }
Example #10
0
 public ClientQueries(
     IConfigurationDbContext context
     )
 {
     if (context == null) throw new ArgumentNullException(nameof(context));
     this.context = context;
 }
Example #11
0
        private static void EnsureSeedData(IConfigurationDbContext context)
        {
            //if (!context.Clients.Any())
            //{
            Log.Debug("Clients being populated");
            foreach (var client in Config.Clients.ToList())
            {
                Client foundClient = context.Clients.FirstOrDefault(c => c.ClientId == client.ClientId);
                if (foundClient != null)
                {
                    context.Clients.Remove(foundClient);
                }
                context.Clients.Add(client.ToEntity());
            }
            context.SaveChanges();
            //}
            //else
            //{
            //    Log.Debug("Clients already populated");
            //}

            //if (!context.IdentityResources.Any())
            //{
            Log.Debug("IdentityResources being populated");
            foreach (var resource in Config.Ids.ToList())
            {
                var foundIR = context.IdentityResources.FirstOrDefault(i => i.Name == resource.Name);
                if (foundIR != null)
                {
                    context.IdentityResources.Remove(foundIR);
                }
                context.IdentityResources.Add(resource.ToEntity());
            }
            context.SaveChanges();
            //}
            //else
            //{
            //    Log.Debug("IdentityResources already populated");
            //}

            //if (!context.ApiResources.Any())
            //{
            Log.Debug("ApiResources being populated");
            foreach (IdentityServer4.Models.ApiResource resource in Config.Apis.ToList())
            {
                ApiResource foundApiResource = context.ApiResources.FirstOrDefault(a => a.Name == resource.Name);
                if (foundApiResource != null)
                {
                    context.ApiResources.Remove(foundApiResource);
                }

                context.ApiResources.Add(resource.ToEntity());
            }
            context.SaveChanges();
            //}
            //else
            //{
            //    Log.Debug("ApiResources already populated");
            //}
        }
Example #12
0
 public DeepLinksViewComponent(
     ApplicationDbContext context,
     IConfigurationDbContext identityConfig)
 {
     _context        = context;
     _identityConfig = identityConfig;
 }
Example #13
0
        /// <summary>
        /// Determines whether origin is allowed.
        /// </summary>
        /// <param name="origin">The origin.</param>
        /// <returns></returns>
        public Task <bool> IsOriginAllowedAsync(string origin)
        {
            // Doing this here and not in the ctor
            // because: https://github.com/aspnet/CORS/issues/105
            IConfigurationDbContext dbContext = context.HttpContext
                                                .RequestServices.GetRequiredService <IConfigurationDbContext>();

            IEnumerable <string> origins = dbContext.Clients
                                           .SelectMany(x => x.AllowedCorsOrigins.Select(y => y.Origin))
                                           .ToList();

            IEnumerable <string> distinctOrigins = origins
                                                   .Where(x => x != null)
                                                   .Distinct();

            bool isAllowed = distinctOrigins
                             .Contains(origin, StringComparer.OrdinalIgnoreCase);

            logger.LogDebug(
                "Origin {origin} is allowed: {originAllowed}",
                origin,
                isAllowed);

            return(Task.FromResult(isAllowed));
        }
Example #14
0
        private void SeedIdentityServerConfigData(IConfigurationDbContext context)
        {
            if (!context.Clients.Any())
            {
                var clientUrls = Startup.Configuration["ClientUrls"];

                foreach (var client in Config.GetClients(clientUrls).ToList())
                {
                    context.Clients.Add(client.ToEntity());
                }
                context.SaveChanges();
            }

            if (!context.IdentityResources.Any())
            {
                foreach (var resource in Config.GetIdentityResources().ToList())
                {
                    context.IdentityResources.Add(resource.ToEntity());
                }
                context.SaveChanges();
            }

            if (!context.ApiResources.Any())
            {
                foreach (var resource in Config.GetApiResources().ToList())
                {
                    context.ApiResources.Add(resource.ToEntity());
                }
                context.SaveChanges();
            }
        }
        internal async Task <Client> CreateImplicitClientAsync(IConfigurationDbContext _configurationContext)
        {
            var newClient = new Client
            {
                ClientId               = ClientId,
                ClientName             = ClientName,
                AllowedGrantTypes      = GrantTypes.Implicit,
                RedirectUris           = RedirectUris.Select(a => a.Trim()).ToList(),
                PostLogoutRedirectUris = PostLogoutRedirectUris.Select(a => a.Trim()).ToList(),
                AllowedScopes          = AllowedScopes
            };

            try
            {
                _configurationContext.Clients.Add(newClient.ToEntity());

                await _configurationContext.SaveChangesAsync();

                return(newClient);
            }
            catch (Exception)
            {
                return(null);
            }
        }
        private static void EnsureSeedData(IConfigurationDbContext context)
        {
            if (!context.Clients.Any())
            {
                foreach (var client in Config.GetClients().ToList())
                {
                    context.AddClient(client.ToEntity());
                }
            }

            if (!context.IdentityResources.Any())
            {
                foreach (var resource in Config.GetIdentityResources().ToList())
                {
                    context.AddIdentityResource(resource.ToEntity());
                }
            }

            if (!context.ApiResources.Any())
            {
                foreach (var resource in Config.GetApiResources().ToList())
                {
                    context.AddApiResource(resource.ToEntity());
                }
            }
        }
Example #17
0
        private static void EnsureSeedData(IConfigurationDbContext context)
        {
            Console.WriteLine("Seeding database...");

            context.Clients.RemoveRange(context.Clients);
            context.IdentityResources.RemoveRange(context.IdentityResources);
            context.ApiResources.RemoveRange(context.ApiResources);

            Console.WriteLine("Clients being populated");
            foreach (var client in Config.GetClients())
            {
                context.Clients.Add(client.ToEntity());
            }

            Console.WriteLine("IdentityResources being populated");
            foreach (var resource in Config.GetIdentityResources())
            {
                context.IdentityResources.Add(resource.ToEntity());
            }

            Console.WriteLine("ApiResources being populated");
            foreach (var resource in Config.GetApis())
            {
                context.ApiResources.Add(resource.ToEntity());
            }
            context.SaveChanges();

            Console.WriteLine("Done seeding database.");
            Console.WriteLine();
        }
        private static void EnsureSeedData(IConfigurationDbContext context)
        {
            if (!context.Clients.Any())
            {
                foreach (var client in Clients.Get().ToList())
                {
                    context.Clients.Add(client.ToEntity());
                }
                context.SaveChanges();
            }

            if (!context.IdentityResources.Any())
            {
                foreach (var resource in Resources.GetIdentityResources().ToList())
                {
                    context.IdentityResources.Add(resource.ToEntity());
                }
                context.SaveChanges();
            }

            if (!context.ApiResources.Any())
            {
                foreach (var resource in Resources.GetApiResources().ToList())
                {
                    context.ApiResources.Add(resource.ToEntity());
                }
                context.SaveChanges();
            }
        }
Example #19
0
 public EditModel(
     ApplicationDbContext context,
     IConfigurationDbContext identityContext)
 {
     _context         = context;
     _identityContext = identityContext;
 }
        private static async Task EnsureSeedData(IConfigurationDbContext context)
        {
            Console.WriteLine("Seeding database...");

            if (!(await context.Clients.GetSnapshotAsync()).Any())
            {
                Console.WriteLine("Clients being populated");
                foreach (var client in Clients.Get())
                {
                    await context.Clients.AddAsync(client.ToEntity());
                }
            }
            else
            {
                Console.WriteLine("Clients already populated");
            }

            if (!(await context.IdentityResources.GetSnapshotAsync()).Any())
            {
                Console.WriteLine("IdentityResources being populated");
                foreach (var resource in Resources.IdentityResources)
                {
                    await context.IdentityResources.AddAsync(resource.ToEntity());
                }
            }
            else
            {
                Console.WriteLine("IdentityResources already populated");
            }

            if (!(await context.ApiResources.GetSnapshotAsync()).Any())
            {
                Console.WriteLine("ApiResources being populated");
                foreach (var resource in Resources.ApiResources)
                {
                    await context.ApiResources.AddAsync(resource.ToEntity());
                }
            }
            else
            {
                Console.WriteLine("ApiResources already populated");
            }

            if (!(await context.ApiScopes.GetSnapshotAsync()).Any())
            {
                Console.WriteLine("Scopes being populated");
                foreach (var resource in Resources.ApiScopes)
                {
                    await context.ApiScopes.AddAsync(resource.ToEntity());
                }
            }
            else
            {
                Console.WriteLine("Scopes already populated");
            }

            Console.WriteLine("Done seeding database.");
            Console.WriteLine();
        }
Example #21
0
        public CorsPolicyService(IConfigurationDbContext context, ILogger <CorsPolicyService> logger)
        {
            Guard.ForNull(context, nameof(context));
            Guard.ForNull(logger, nameof(logger));

            _context = context;
            _logger  = logger;
        }
 public ClientStore(IConfigurationDbContext context)
 {
     if (context == null)
     {
         throw new ArgumentNullException(nameof(context));
     }
     this.context = context;
 }
Example #23
0
 public CorsPolicyService(IConfigurationDbContext context)
 {
     if (context == null)
     {
         throw new ArgumentNullException(nameof(context));
     }
     this.context = context;
 }
Example #24
0
        public ClientStore(IConfigurationDbContext context, ILogger <ClientStore> logger)
        {
            Guard.ForNull(context, nameof(context));
            Guard.ForNull(logger, nameof(logger));

            _context = context;
            _logger  = logger;
        }
        public ResourceStore(IConfigurationDbContext context, ILogger logger)
        {
            Guard.ForNull(context, nameof(context));
            Guard.ForNull(logger, nameof(logger));

            _context = context;
            _logger  = logger;
        }
Example #26
0
 //  private readonly UserStore<ApplicationUser> _userStore;
 public UserController(UserManager <ApplicationUser> userManager, IConfigurationDbContext configDbContext,
                       IPersistedGrantDbContext persistedDbContext, RoleManager <ApplicationRole> roleMager)
 {
     _userManager        = userManager;
     _configDbContext    = configDbContext;
     _persistedDbContext = persistedDbContext;
     _roleMager          = roleMager;
 }
Example #27
0
 public ScopeCommands(
     IConfigurationDbContext context
     )
 {
     if(context == null) throw new ArgumentNullException(nameof(context));
     this.context = context;
    
 }
 public DeepLinksModel(
     ApplicationDbContext context,
     IConfigurationDbContext identityContext,
     ILogger <DeepLinksModel> logger)
 {
     _context         = context;
     _identityContext = identityContext;
     _logger          = logger;
 }
Example #29
0
        private static void EnsureSeedData(IConfigurationDbContext context)
        {
            if (!context.Clients.Any())
            {
                Log.Debug("Users being populated");
                foreach (var client in Config.Clients.ToList())
                {
                    context.Clients.Add(client.ToEntity());
                }
                context.SaveChanges();
            }
            else
            {
                Log.Debug("Users already populated");
            }
            if (!context.Clients.Any())
            {
                Log.Debug("Clients being populated");
                foreach (var client in Config.Clients.ToList())
                {
                    context.Clients.Add(client.ToEntity());
                }
                context.SaveChanges();
            }
            else
            {
                Log.Debug("Clients already populated");
            }

            if (!context.IdentityResources.Any())
            {
                Log.Debug("IdentityResources being populated");
                foreach (var resource in Config.Ids.ToList())
                {
                    context.IdentityResources.Add(resource.ToEntity());
                }
                context.SaveChanges();
            }
            else
            {
                Log.Debug("IdentityResources already populated");
            }

            if (!context.ApiResources.Any())
            {
                Log.Debug("ApiResources being populated");
                foreach (var resource in Config.Apis.ToList())
                {
                    context.ApiResources.Add(resource.ToEntity());
                }
                context.SaveChanges();
            }
            else
            {
                Log.Debug("ApiResources already populated");
            }
        }
Example #30
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ClientStore"/> class.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="logger">The logger.</param>
        /// <exception cref="ArgumentNullException">context</exception>
        public ClientStore(
            IConfigurationDbContext context,
            ILogger <ClientStore> logger)
        {
            this._context = context ?? throw
                                new ArgumentNullException(nameof(context));

            this._logger = logger;
        }
 public OidcLaunchModel(
     ApplicationDbContext context,
     IConfigurationDbContext identityContext,
     ILogger <OidcLaunchModel> logger)
 {
     _context         = context;
     _identityContext = identityContext;
     _logger          = logger;
 }
Example #32
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ResourceStore"/> class.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="logger">The logger.</param>
        /// <exception cref="ArgumentNullException">context</exception>
        public ResourceStore(
            IConfigurationDbContext context,
            ILogger <ResourceStore> logger)
        {
            _context = context ?? throw
                           new ArgumentNullException(nameof(context));

            _logger = logger;
        }
Example #33
0
 public ClientStore(
     IHttpContextAccessor contextAccessor,
     IConfigurationDbContext context
     )
 {
     if (context == null) throw new ArgumentNullException(nameof(context));
     _contextAccessor = contextAccessor;
     this.context = context;
 }
 public CorsPolicyService(IConfigurationDbContext context)
 {
     if (context == null) throw new ArgumentNullException(nameof(context));
     this.context = context;
 }