Browse Source

Add some methods.

pull/4578/head
maliming 6 years ago
parent
commit
b6676dc54c
  1. 3
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Localization/Resources/en.json
  2. 3
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Localization/Resources/zh-Hans.json
  3. 20
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiScopes/IApiScopeeRepository.cs
  4. 20
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityResource.cs
  5. 14
      modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ApiResources/ApiResourceRepository.cs
  6. 45
      modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ApiScopes/ApiScopeRepository.cs
  7. 2
      modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoApiResourceRepository.cs
  8. 22
      modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoApiScopeRepository.cs

3
modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Localization/Resources/en.json

@ -3,10 +3,11 @@
"texts": {
"Volo.IdentityServer:DuplicateIdentityResourceName": "Identity Resource name already exist: {Name}",
"Volo.IdentityServer:DuplicateApiResourceName": "Api Resource name already exist: {Name}",
"Volo.IdentityServer:DuplicateApiScopeName": "Api Scope name already exist: {Name}",
"Volo.IdentityServer:DuplicateClientId": "ClientId already exist: {ClientId}",
"UserLockedOut": "The user account has been locked out due to invalid login attempts. Please wait a while and try again.",
"InvalidUserNameOrPassword": "Invalid username or password!",
"LoginIsNotAllowed": "You are not allowed to login! You need to confirm your email/phone number.",
"InvalidUsername": "Invalid username or password!"
}
}
}

3
modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Localization/Resources/zh-Hans.json

@ -3,10 +3,11 @@
"texts": {
"Volo.IdentityServer:DuplicateIdentityResourceName": "Identity资源名称已存在: {Name}",
"Volo.IdentityServer:DuplicateApiResourceName": "Api资源名称已存在: {Name}",
"Volo.IdentityServer:DuplicateApiScopeName": "Api Scope已存在: {Name}",
"Volo.IdentityServer:DuplicateClientId": "ClientId已经存在: {ClientId}",
"UserLockedOut": "登录失败,用户账户已被锁定.请稍后再试.",
"InvalidUserNameOrPassword": "用户名或密码错误!",
"LoginIsNotAllowed": "无法登录!你需要验证邮箱地址/手机号.",
"InvalidUsername": "用户名或密码错误!"
}
}
}

20
modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiScopes/IApiScopeeRepository.cs

@ -1,11 +1,12 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;
namespace Volo.Abp.IdentityServer.ApiScopes
{
public interface IApiScopeRepository : IBasicRepository<ApiScope>
public interface IApiScopeRepository : IBasicRepository<ApiScope, Guid>
{
Task<ApiScope> GetByNameAsync(
string scopeName,
@ -18,5 +19,20 @@ namespace Volo.Abp.IdentityServer.ApiScopes
bool includeDetails = false,
CancellationToken cancellationToken = default
);
Task<List<ApiScope>> GetListAsync(
string sorting,
int skipCount,
int maxResultCount,
string filter = null,
bool includeDetails = false,
CancellationToken cancellationToken = default
);
Task<bool> CheckNameExistAsync(
string name,
Guid? expectedId = null,
CancellationToken cancellationToken = default
);
}
}

20
modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityResource.cs

@ -89,5 +89,25 @@ namespace Volo.Abp.IdentityServer.IdentityResources
{
return UserClaims.FirstOrDefault(c => c.Type == type);
}
public virtual void AddProperty([NotNull] string key, string value)
{
Properties.Add(new IdentityResourceProperty(Id, key, value));
}
public virtual void RemoveAllProperties()
{
Properties.Clear();
}
public virtual void RemoveProperty(string key)
{
Properties.RemoveAll(r => r.Key == key);
}
public virtual IdentityResourceProperty FindProperty(string key)
{
return Properties.FirstOrDefault(r => r.Key == key);
}
}
}

14
modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ApiResources/ApiResourceRepository.cs

@ -68,7 +68,7 @@ namespace Volo.Abp.IdentityServer.ApiResources
public virtual async Task<bool> CheckNameExistAsync(string name, Guid? expectedId = null, CancellationToken cancellationToken = default)
{
return await DbSet.AnyAsync(ar => ar.Id != expectedId && ar.Name == name, cancellationToken: cancellationToken);
return await DbSet.AnyAsync(ar => ar.Id != expectedId && ar.Name == name, GetCancellationToken(cancellationToken));
}
public override async Task DeleteAsync(Guid id, bool autoSave = false, CancellationToken cancellationToken = default)
@ -85,6 +85,18 @@ namespace Volo.Abp.IdentityServer.ApiResources
DbContext.Set<ApiResourceScope>().Remove(scope);
}
var resourceSecrets = DbContext.Set<ApiResourceSecret>().Where(s => s.ApiResourceId == id);
foreach (var secret in resourceSecrets)
{
DbContext.Set<ApiResourceSecret>().Remove(secret);
}
var apiResourceProperties = DbContext.Set<ApiResourceProperty>().Where(s => s.ApiResourceId == id);
foreach (var property in apiResourceProperties)
{
DbContext.Set<ApiResourceProperty>().Remove(property);
}
await base.DeleteAsync(id, autoSave, cancellationToken);
}

45
modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ApiScopes/ApiScopeRepository.cs

@ -1,5 +1,7 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
@ -9,7 +11,7 @@ using Volo.Abp.IdentityServer.EntityFrameworkCore;
namespace Volo.Abp.IdentityServer.ApiScopes
{
public class ApiScopeRepository : EfCoreRepository<IIdentityServerDbContext, ApiScope>, IApiScopeRepository
public class ApiScopeRepository : EfCoreRepository<IIdentityServerDbContext, ApiScope, Guid>, IApiScopeRepository
{
public ApiScopeRepository(IDbContextProvider<IIdentityServerDbContext> dbContextProvider) : base(
dbContextProvider)
@ -30,5 +32,44 @@ namespace Volo.Abp.IdentityServer.ApiScopes
return await query.ToListAsync(GetCancellationToken(cancellationToken));
}
public async Task<List<ApiScope>> GetListAsync(string sorting, int skipCount, int maxResultCount, string filter = null, bool includeDetails = false, CancellationToken cancellationToken = default)
{
return await DbSet
.IncludeDetails(includeDetails)
.WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Name.Contains(filter) ||
x.Description.Contains(filter) ||
x.DisplayName.Contains(filter))
.OrderBy(sorting ?? "name desc")
.PageBy(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken));
}
public async Task<bool> CheckNameExistAsync(string name, Guid? expectedId = null, CancellationToken cancellationToken = default)
{
return await DbSet.AnyAsync(x => x.Id != expectedId && x.Name == name, GetCancellationToken(cancellationToken));
}
public override async Task DeleteAsync(Guid id, bool autoSave = false, CancellationToken cancellationToken = new CancellationToken())
{
var scopeClaims = DbContext.Set<ApiScopeClaim>().Where(sc => sc.ApiScopeId == id);
foreach (var claim in scopeClaims)
{
DbContext.Set<ApiScopeClaim>().Remove(claim);
}
var scopeProperties = DbContext.Set<ApiScopeProperty>().Where(s => s.ApiScopeId == id);
foreach (var property in scopeProperties)
{
DbContext.Set<ApiScopeProperty>().Remove(property);
}
await base.DeleteAsync(id, autoSave, cancellationToken);
}
public override IQueryable<ApiScope> WithDetails()
{
return GetQueryable().IncludeDetails();
}
}
}

2
modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoApiResourceRepository.cs

@ -63,7 +63,7 @@ namespace Volo.Abp.IdentityServer.MongoDB
public virtual async Task<bool> CheckNameExistAsync(string name, Guid? expectedId = null, CancellationToken cancellationToken = default)
{
return await GetMongoQueryable().AnyAsync(ar => ar.Id != expectedId && ar.Name == name, cancellationToken: cancellationToken);
return await GetMongoQueryable().AnyAsync(ar => ar.Id != expectedId && ar.Name == name, GetCancellationToken(cancellationToken));
}
}
}

22
modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoApiScopeRepository.cs

@ -1,12 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Linq;
using MongoDB.Driver;
using MongoDB.Driver.Linq;
using Volo.Abp.Domain.Repositories.MongoDB;
using Volo.Abp.IdentityServer.ApiScopes;
using System.Linq.Dynamic.Core;
using Volo.Abp.MongoDB;
namespace Volo.Abp.IdentityServer.MongoDB
@ -33,5 +34,24 @@ namespace Volo.Abp.IdentityServer.MongoDB
return await query.ToListAsync(GetCancellationToken(cancellationToken));
}
public async Task<List<ApiScope>> GetListAsync(string sorting, int skipCount, int maxResultCount, string filter = null, bool includeDetails = false,
CancellationToken cancellationToken = default)
{
return await GetMongoQueryable()
.WhereIf(!filter.IsNullOrWhiteSpace(),
x => x.Name.Contains(filter) ||
x.Description.Contains(filter) ||
x.DisplayName.Contains(filter))
.OrderBy(sorting ?? nameof(ApiScope.Name))
.As<IMongoQueryable<ApiScope>>()
.PageBy<ApiScope, IMongoQueryable<ApiScope>>(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken));
}
public async Task<bool> CheckNameExistAsync(string name, Guid? expectedId = null, CancellationToken cancellationToken = default)
{
return await GetMongoQueryable().AnyAsync(x => x.Id != expectedId && x.Name == name, GetCancellationToken(cancellationToken));
}
}
}

Loading…
Cancel
Save