Skip to content
This repository was archived by the owner on Aug 1, 2021. It is now read-only.

Commit d1a4468

Browse files
Merge pull request #98 from akselarzuman/master
Sqlite support added and vulnerabilities fixed
2 parents e7d22ad + 2c06fc4 commit d1a4468

21 files changed

+3551
-343
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,4 +253,5 @@ docs/_build
253253
docs/.vscode
254254

255255
# Log files
256-
**/*log*.txt
256+
**/*log*.txt
257+
*.db

src/Backend/Jp.Infra.CrossCutting.Database/DbSettingsConfig.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Jp.Infra.Data.MySql.Configuration;
22
using Jp.Infra.Data.PostgreSQL.Configuration;
33
using Jp.Infra.Data.Sql.Configuration;
4+
using Jp.Infra.Data.Sqlite.Configuration;
45
using Microsoft.Extensions.Configuration;
56
using Microsoft.Extensions.DependencyInjection;
67

@@ -23,6 +24,9 @@ public static void ConfigureDatabase(this IServiceCollection services, IConfigur
2324
case "POSTGRESQL":
2425
services.AddIdentityPostgreSql(connString);
2526
break;
27+
case "SQLITE":
28+
services.AddIdentitySqlite(connString);
29+
break;
2630
}
2731
}
2832

@@ -41,6 +45,9 @@ public static void ConfigureIdentityServerDatabase(this IIdentityServerBuilder b
4145
case "POSTGRESQL":
4246
builder.UseIdentityServerPostgreSqlDatabase(connString);
4347
break;
48+
case "SQLITE":
49+
builder.UseIdentityServerSqlite(connString);
50+
break;
4451
}
4552
}
4653
}

src/Backend/Jp.Infra.CrossCutting.Database/Jp.Infra.CrossCutting.Database.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<ItemGroup>
1717
<ProjectReference Include="..\Jp.Infra.Data.MySql\Jp.Infra.Data.MySql.csproj" />
1818
<ProjectReference Include="..\Jp.Infra.Data.PostgreSQL\Jp.Infra.Data.PostgreSQL.csproj" />
19+
<ProjectReference Include="..\Jp.Infra.Data.Sqlite\Jp.Infra.Data.Sqlite.csproj" />
1920
<ProjectReference Include="..\Jp.Infra.Data.Sql\Jp.Infra.Data.Sql.csproj" />
2021
</ItemGroup>
2122
</Project>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using IdentityServer4.EntityFramework.Options;
2+
using Jp.Infra.CrossCutting.Identity.Context;
3+
using Jp.Infra.CrossCutting.Identity.Entities.Identity;
4+
using Jp.Infra.Data.Context;
5+
using Microsoft.AspNetCore.Identity;
6+
using Microsoft.EntityFrameworkCore;
7+
using Microsoft.Extensions.DependencyInjection;
8+
using System.Reflection;
9+
10+
namespace Jp.Infra.Data.Sqlite.Configuration
11+
{
12+
public static class IdentityConfig
13+
{
14+
public static IServiceCollection AddIdentitySqlite(this IServiceCollection services, string connectionString)
15+
{
16+
var migrationsAssembly = typeof(IdentityConfig).GetTypeInfo().Assembly.GetName().Name;
17+
18+
var operationalStoreOptions = new OperationalStoreOptions();
19+
services.AddSingleton(operationalStoreOptions);
20+
21+
var storeOptions = new ConfigurationStoreOptions();
22+
services.AddSingleton(storeOptions);
23+
24+
services.AddEntityFrameworkSqlite().AddDbContext<ApplicationIdentityContext>(options => options.UseSqlite(connectionString, sql => sql.MigrationsAssembly(migrationsAssembly)));
25+
services.AddDbContext<JpContext>(options => options.UseSqlite(connectionString, sql => sql.MigrationsAssembly(migrationsAssembly)));
26+
services.AddDbContext<EventStoreContext>(options => options.UseSqlite(connectionString, sql => sql.MigrationsAssembly(migrationsAssembly)));
27+
28+
services.AddIdentity<UserIdentity, UserIdentityRole>()
29+
.AddEntityFrameworkStores<ApplicationIdentityContext>()
30+
.AddDefaultTokenProviders();
31+
return services;
32+
}
33+
}
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using Microsoft.EntityFrameworkCore;
2+
using Microsoft.Extensions.DependencyInjection;
3+
using System.Reflection;
4+
5+
namespace Jp.Infra.Data.Sqlite.Configuration
6+
{
7+
public static class IdentityServerConfig
8+
{
9+
public static IIdentityServerBuilder UseIdentityServerSqlite(this IIdentityServerBuilder builder, string connectionString)
10+
{
11+
var migrationsAssembly = typeof(IdentityServerConfig).GetTypeInfo().Assembly.GetName().Name;
12+
13+
// this adds the config data from DB (clients, resources)
14+
builder.AddConfigurationStore(options =>
15+
{
16+
options.ConfigureDbContext = b =>
17+
b.UseSqlite(connectionString, sql => sql.MigrationsAssembly(migrationsAssembly));
18+
})
19+
// this adds the operational data from DB (codes, tokens, consents)
20+
.AddOperationalStore(options =>
21+
{
22+
options.ConfigureDbContext = b =>
23+
b.UseSqlite(connectionString, sql => sql.MigrationsAssembly(migrationsAssembly));
24+
25+
// this enables automatic token cleanup. this is optional.
26+
options.EnableTokenCleanup = true;
27+
options.TokenCleanupInterval = 15; // frequency in seconds to cleanup stale grants. 15 is useful during debugging
28+
});
29+
30+
return builder;
31+
}
32+
33+
}
34+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.4" />
9+
</ItemGroup>
10+
11+
<ItemGroup>
12+
<ProjectReference Include="..\Jp.Infra.CrossCutting.Identity\Jp.Infra.CrossCutting.Identity.csproj" />
13+
<ProjectReference Include="..\Jp.Infra.Data\Jp.Infra.Data.csproj" />
14+
</ItemGroup>
15+
16+
<ItemGroup>
17+
<Folder Include="Migrations\" />
18+
</ItemGroup>
19+
</Project>

src/Backend/Jp.Infra.Data.Sqlite/Migrations/EventStore/20190828141939_Initial.Designer.cs

Lines changed: 46 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System;
2+
using Microsoft.EntityFrameworkCore.Migrations;
3+
4+
namespace Jp.Infra.Data.Sqlite.Migrations.EventStore
5+
{
6+
public partial class Initial : Migration
7+
{
8+
protected override void Up(MigrationBuilder migrationBuilder)
9+
{
10+
migrationBuilder.CreateTable(
11+
name: "StoredEvent",
12+
columns: table => new
13+
{
14+
Id = table.Column<Guid>(nullable: false),
15+
Action = table.Column<string>(type: "varchar(100)", nullable: true),
16+
AggregateId = table.Column<string>(nullable: true),
17+
CreationDate = table.Column<DateTime>(nullable: false),
18+
Data = table.Column<string>(nullable: true),
19+
User = table.Column<string>(nullable: true)
20+
},
21+
constraints: table =>
22+
{
23+
table.PrimaryKey("PK_StoredEvent", x => x.Id);
24+
});
25+
}
26+
27+
protected override void Down(MigrationBuilder migrationBuilder)
28+
{
29+
migrationBuilder.DropTable(
30+
name: "StoredEvent");
31+
}
32+
}
33+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// <auto-generated />
2+
using System;
3+
using Jp.Infra.Data.Context;
4+
using Microsoft.EntityFrameworkCore;
5+
using Microsoft.EntityFrameworkCore.Infrastructure;
6+
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
7+
8+
namespace Jp.Infra.Data.Sqlite.Migrations.EventStore
9+
{
10+
[DbContext(typeof(EventStoreContext))]
11+
partial class EventStoreContextModelSnapshot : ModelSnapshot
12+
{
13+
protected override void BuildModel(ModelBuilder modelBuilder)
14+
{
15+
#pragma warning disable 612, 618
16+
modelBuilder
17+
.HasAnnotation("ProductVersion", "2.2.6-servicing-10079");
18+
19+
modelBuilder.Entity("Jp.Domain.Core.Events.StoredEvent", b =>
20+
{
21+
b.Property<Guid>("Id")
22+
.ValueGeneratedOnAdd();
23+
24+
b.Property<string>("AggregateId");
25+
26+
b.Property<string>("Data");
27+
28+
b.Property<string>("MessageType")
29+
.HasColumnName("Action")
30+
.HasColumnType("varchar(100)");
31+
32+
b.Property<DateTime>("Timestamp")
33+
.HasColumnName("CreationDate");
34+
35+
b.Property<string>("User");
36+
37+
b.HasKey("Id");
38+
39+
b.ToTable("StoredEvent");
40+
});
41+
#pragma warning restore 612, 618
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)