mirror of https://github.com/abpframework/abp.git
13 changed files with 346 additions and 0 deletions
@ -0,0 +1,22 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<Import Project="..\..\common.props" /> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>netstandard2.0</TargetFramework> |
|||
<AssemblyName>Volo.Abp.IdentityServer.MongoDB</AssemblyName> |
|||
<PackageId>Volo.Abp.IdentityServer.MongoDB</PackageId> |
|||
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback> |
|||
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> |
|||
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> |
|||
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> |
|||
<RootNamespace /> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\Volo.Abp.IdentityServer.Domain\Volo.Abp.IdentityServer.Domain.csproj" /> |
|||
|
|||
<ProjectReference Include="..\..\..\..\..\abp\framework\src\Volo.Abp.MongoDB\Volo.Abp.MongoDB.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,37 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
using IdentityServer4.Models; |
|||
using MongoDB.Bson.Serialization; |
|||
using Volo.Abp.Threading; |
|||
|
|||
namespace Volo.Abp.IdentityServer.MongoDB |
|||
{ |
|||
public class AbpIdentityServerBsonClassMap |
|||
{ |
|||
private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner(); |
|||
|
|||
public static void Configure() |
|||
{ |
|||
OneTimeRunner.Run(() => |
|||
{ |
|||
BsonClassMap.RegisterClassMap<ApiResource>(map => |
|||
{ |
|||
map.AutoMap(); |
|||
}); |
|||
BsonClassMap.RegisterClassMap<Client>(map => |
|||
{ |
|||
map.AutoMap(); |
|||
}); |
|||
BsonClassMap.RegisterClassMap<IdentityResource>(map => |
|||
{ |
|||
map.AutoMap(); |
|||
}); |
|||
BsonClassMap.RegisterClassMap<PersistedGrant>(map => |
|||
{ |
|||
map.AutoMap(); |
|||
}); |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,34 @@ |
|||
using MongoDB.Driver; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.IdentityServer.ApiResources; |
|||
using Volo.Abp.IdentityServer.Clients; |
|||
using Volo.Abp.IdentityServer.Grants; |
|||
using Volo.Abp.MongoDB; |
|||
using IdentityResource = Volo.Abp.IdentityServer.IdentityResources.IdentityResource; |
|||
|
|||
namespace Volo.Abp.IdentityServer.MongoDB |
|||
{ |
|||
[ConnectionStringName("AbpIdentityServer")] |
|||
public class AbpIdentityServerMongoDbContext : AbpMongoDbContext, IAbpIdentityServerMongoDbContext |
|||
{ |
|||
public static string CollectionPrefix { get; set; } = AbpIdentityServerConsts.DefaultDbTablePrefix; |
|||
|
|||
public IMongoCollection<ApiResource> ApiResources => Collection<ApiResource>(); |
|||
|
|||
public IMongoCollection<Client> Clients => Collection<Client>(); |
|||
|
|||
public IMongoCollection<IdentityResource> IdentityResources => Collection<IdentityResource>(); |
|||
|
|||
public IMongoCollection<PersistedGrant> PersistedGrants => Collection<PersistedGrant>(); |
|||
|
|||
protected override void CreateModel(IMongoModelBuilder modelBuilder) |
|||
{ |
|||
base.CreateModel(modelBuilder); |
|||
|
|||
modelBuilder.ConfigureIdentityServer(options => |
|||
{ |
|||
options.CollectionPrefix = CollectionPrefix; |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,42 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
using IdentityServer4.Models; |
|||
using Volo.Abp.MongoDB; |
|||
|
|||
namespace Volo.Abp.IdentityServer.MongoDB |
|||
{ |
|||
public static class AbpIdentityServerMongoDbContextExtensions |
|||
{ |
|||
public static void ConfigureIdentityServer( |
|||
this IMongoModelBuilder builder, |
|||
Action<IdentityServerMongoModelBuilderConfigurationOptions> optionsAction = null) |
|||
{ |
|||
Check.NotNull(builder, nameof(builder)); |
|||
|
|||
var options = new IdentityServerMongoModelBuilderConfigurationOptions(); |
|||
|
|||
optionsAction?.Invoke(options); |
|||
|
|||
builder.Entity<ApiResource>(b => |
|||
{ |
|||
b.CollectionName = options.CollectionPrefix + "ApiResources"; |
|||
}); |
|||
|
|||
builder.Entity<Client>(b => |
|||
{ |
|||
b.CollectionName = options.CollectionPrefix + "Clients"; |
|||
}); |
|||
|
|||
builder.Entity<IdentityResource>(b => |
|||
{ |
|||
b.CollectionName = options.CollectionPrefix + "IdentityResources"; |
|||
}); |
|||
|
|||
builder.Entity<PersistedGrant>(b => |
|||
{ |
|||
b.CollectionName = options.CollectionPrefix + "PersistedGrants"; |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,30 @@ |
|||
using IdentityServer4.Models; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Volo.Abp.Modularity; |
|||
using Volo.Abp.MongoDB; |
|||
using ApiResource = Volo.Abp.IdentityServer.ApiResources.ApiResource; |
|||
using Client = Volo.Abp.IdentityServer.Clients.Client; |
|||
using IdentityResource = Volo.Abp.IdentityServer.IdentityResources.IdentityResource; |
|||
|
|||
namespace Volo.Abp.IdentityServer.MongoDB |
|||
{ |
|||
[DependsOn( |
|||
typeof(AbpIdentityServerDomainModule), |
|||
typeof(AbpMongoDbModule) |
|||
)] |
|||
public class AbpIdentityServerMongoDbModule : AbpModule |
|||
{ |
|||
public override void ConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
AbpIdentityServerBsonClassMap.Configure(); |
|||
|
|||
context.Services.AddMongoDbContext<AbpIdentityServerMongoDbContext>(options => |
|||
{ |
|||
options.AddRepository<ApiResource, MongoApiResourceRepository>(); |
|||
options.AddRepository<IdentityResource, MongoIdentityResourceRepository>(); |
|||
options.AddRepository<Client, MongoClientRepository>(); |
|||
options.AddRepository<PersistedGrant, MongoPersistedGrantRepository>(); |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,22 @@ |
|||
using MongoDB.Driver; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.IdentityServer.Clients; |
|||
using Volo.Abp.IdentityServer.Grants; |
|||
using Volo.Abp.IdentityServer.IdentityResources; |
|||
using Volo.Abp.MongoDB; |
|||
using ApiResource = Volo.Abp.IdentityServer.ApiResources.ApiResource; |
|||
|
|||
namespace Volo.Abp.IdentityServer.MongoDB |
|||
{ |
|||
[ConnectionStringName("AbpIdentityServer")] |
|||
public interface IAbpIdentityServerMongoDbContext : IAbpMongoDbContext |
|||
{ |
|||
IMongoCollection<ApiResource> ApiResources { get; } |
|||
|
|||
IMongoCollection<Client> Clients { get; } |
|||
|
|||
IMongoCollection<IdentityResource> IdentityResources { get; } |
|||
|
|||
IMongoCollection<PersistedGrant> PersistedGrants { get; } |
|||
} |
|||
} |
|||
@ -0,0 +1,15 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
using Volo.Abp.MongoDB; |
|||
|
|||
namespace Volo.Abp.IdentityServer.MongoDB |
|||
{ |
|||
public class IdentityServerMongoModelBuilderConfigurationOptions : MongoModelBuilderConfigurationOptions |
|||
{ |
|||
public IdentityServerMongoModelBuilderConfigurationOptions() |
|||
: base(AbpIdentityServerConsts.DefaultDbTablePrefix) |
|||
{ |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,36 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using MongoDB.Driver; |
|||
using MongoDB.Driver.Linq; |
|||
using Volo.Abp.Domain.Repositories.MongoDB; |
|||
using Volo.Abp.IdentityServer.ApiResources; |
|||
using Volo.Abp.MongoDB; |
|||
|
|||
namespace Volo.Abp.IdentityServer.MongoDB |
|||
{ |
|||
public class MongoApiResourceRepository : MongoDbRepository<IAbpIdentityServerMongoDbContext, ApiResource, Guid>, IApiResourceRepository |
|||
{ |
|||
public MongoApiResourceRepository(IMongoDbContextProvider<IAbpIdentityServerMongoDbContext> dbContextProvider) : base(dbContextProvider) |
|||
{ |
|||
} |
|||
|
|||
public virtual async Task<ApiResource> FindByNameAsync(string name, bool includeDetails = true, CancellationToken cancellationToken = default) |
|||
{ |
|||
return await GetMongoQueryable() |
|||
.Where(ar=>ar.Name == name) |
|||
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<List<ApiResource>> GetListByScopesAsync(string[] scopeNames, bool includeDetails = false, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return await GetMongoQueryable() |
|||
.Where(ar=>ar.Scopes.Any(x=> scopeNames.Contains(x.Name))) |
|||
.ToListAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,22 @@ |
|||
using System; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using MongoDB.Driver.Linq; |
|||
using Volo.Abp.Domain.Repositories.MongoDB; |
|||
using Volo.Abp.IdentityServer.Clients; |
|||
using Volo.Abp.MongoDB; |
|||
|
|||
namespace Volo.Abp.IdentityServer.MongoDB |
|||
{ |
|||
public class MongoClientRepository : MongoDbRepository<IAbpIdentityServerMongoDbContext, Client, Guid>, IClientRepository |
|||
{ |
|||
public MongoClientRepository(IMongoDbContextProvider<IAbpIdentityServerMongoDbContext> dbContextProvider) : base(dbContextProvider) |
|||
{ |
|||
} |
|||
|
|||
public async Task<Client> FindByCliendIdAsync(string clientId, bool includeDetails = true, CancellationToken cancellationToken = default) |
|||
{ |
|||
return await GetMongoQueryable().FirstOrDefaultAsync(x => x.ClientId == clientId, GetCancellationToken(cancellationToken)); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,29 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using MongoDB.Driver; |
|||
using MongoDB.Driver.Linq; |
|||
using Volo.Abp.Domain.Repositories.MongoDB; |
|||
using Volo.Abp.IdentityServer.IdentityResources; |
|||
using Volo.Abp.MongoDB; |
|||
|
|||
namespace Volo.Abp.IdentityServer.MongoDB |
|||
{ |
|||
public class MongoIdentityResourceRepository : MongoDbRepository<IAbpIdentityServerMongoDbContext, IdentityResource, Guid>, IIdentityResourceRepository |
|||
{ |
|||
public MongoIdentityResourceRepository(IMongoDbContextProvider<IAbpIdentityServerMongoDbContext> dbContextProvider) : base(dbContextProvider) |
|||
{ |
|||
} |
|||
|
|||
public async Task<List<IdentityResource>> GetListByScopesAsync(string[] scopeNames, bool includeDetails = false, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return await GetMongoQueryable() |
|||
.Where(ar => scopeNames.Any(s=>s == ar.Name)) |
|||
.ToListAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,49 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using MongoDB.Driver; |
|||
using MongoDB.Driver.Linq; |
|||
using Volo.Abp.Domain.Repositories.MongoDB; |
|||
using Volo.Abp.IdentityServer.Grants; |
|||
using Volo.Abp.MongoDB; |
|||
|
|||
namespace Volo.Abp.IdentityServer.MongoDB |
|||
{ |
|||
public class MongoPersistedGrantRepository : MongoDbRepository<IAbpIdentityServerMongoDbContext, PersistedGrant, Guid>, IPersistentGrantRepository |
|||
{ |
|||
public MongoPersistedGrantRepository(IMongoDbContextProvider<IAbpIdentityServerMongoDbContext> dbContextProvider) : base(dbContextProvider) |
|||
{ |
|||
} |
|||
|
|||
public async Task<PersistedGrant> FindByKeyAsync(string key, CancellationToken cancellationToken = default) |
|||
{ |
|||
|
|||
return await GetMongoQueryable() |
|||
.FirstOrDefaultAsync(x => x.Key == key, GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public async Task<List<PersistedGrant>> GetListBySubjectIdAsync(string subjectId, CancellationToken cancellationToken = default) |
|||
{ |
|||
return await GetMongoQueryable() |
|||
.Where(x => x.SubjectId == subjectId) |
|||
.ToListAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public async Task DeleteAsync(string subjectId, string clientId, CancellationToken cancellationToken = default) |
|||
{ |
|||
await DeleteAsync( |
|||
x => x.SubjectId == subjectId && x.ClientId == clientId, |
|||
cancellationToken: GetCancellationToken(cancellationToken) |
|||
); |
|||
} |
|||
|
|||
public async Task DeleteAsync(string subjectId, string clientId, string type, CancellationToken cancellationToken = default) |
|||
{ |
|||
await DeleteAsync( |
|||
x => x.SubjectId == subjectId && x.ClientId == clientId && x.Type == type, |
|||
cancellationToken: GetCancellationToken(cancellationToken) |
|||
); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue