Merge branch 'master' into Remove-logger-factory-configuration-from-Startup

pull/827/head
Halil İbrahim Kalkan 7 years ago committed by GitHub
commit 9143f01ea6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -140,6 +140,8 @@ namespace Volo.AbpWebSite
var app = context.GetApplicationBuilder();
var env = context.GetEnvironment();
app.UseCorrelationId();
app.UseAbpRequestLocalization();
if (env.IsDevelopment())

@ -0,0 +1,28 @@
using Serilog.Core;
using Serilog.Events;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Tracing;
namespace Volo.AbpWebSite
{
//This is for trial for now
public class CorrelationIdLogEventEnricher : ILogEventEnricher, ITransientDependency
{
private readonly ICorrelationIdProvider _correlationIdProvider;
public CorrelationIdLogEventEnricher(ICorrelationIdProvider correlationIdProvider)
{
_correlationIdProvider = correlationIdProvider;
}
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
{
logEvent.AddOrUpdateProperty(
new LogEventProperty(
"CorrelationId",
new ScalarValue("CorrId:" + _correlationIdProvider.Get())
)
);
}
}
}

@ -8,7 +8,7 @@ namespace Volo.Abp.AspNetCore.Threading
[Dependency(ReplaceServices = true)]
public class HttpContextCancellationTokenProvider : ICancellationTokenProvider, ITransientDependency
{
public CancellationToken Token => _httpContextAccessor.HttpContext?.RequestAborted ?? default;
public CancellationToken Token => _httpContextAccessor.HttpContext?.RequestAborted ?? CancellationToken.None;
private readonly IHttpContextAccessor _httpContextAccessor;

@ -27,18 +27,21 @@ namespace Volo.Abp.AspNetCore.Tracing
return CreateNewCorrelationId();
}
lock (HttpContextAccessor.HttpContext.Request.Headers)
{
string correlationId = HttpContextAccessor.HttpContext.Request.Headers[Options.HttpHeaderName];
string correlationId = HttpContextAccessor.HttpContext.Request.Headers[Options.HttpHeaderName];
if (correlationId.IsNullOrEmpty())
if (correlationId.IsNullOrEmpty())
{
lock (HttpContextAccessor.HttpContext.Request.Headers)
{
correlationId = CreateNewCorrelationId();
HttpContextAccessor.HttpContext.Request.Headers[Options.HttpHeaderName] = correlationId;
if (correlationId.IsNullOrEmpty())
{
correlationId = CreateNewCorrelationId();
HttpContextAccessor.HttpContext.Request.Headers[Options.HttpHeaderName] = correlationId;
}
}
return correlationId;
}
return correlationId;
}
protected virtual string CreateNewCorrelationId()

@ -9,5 +9,7 @@ namespace Volo.Abp.Authorization.Permissions
PermissionGroupDefinition GetGroupOrNull(string name);
PermissionGroupDefinition AddGroup([NotNull] string name, ILocalizableString displayName = null);
void RemoveGroup(string name);
}
}

@ -36,5 +36,16 @@ namespace Volo.Abp.Authorization.Permissions
return Groups[name];
}
public virtual void RemoveGroup(string name)
{
Check.NotNull(name, nameof(name));
if (!Groups.ContainsKey(name))
{
throw new AbpException($"Not found permission group with name: {name}");
}
Groups.Remove(name);
}
}
}

@ -15,5 +15,20 @@ namespace Volo.Abp.Caching
Name = name;
}
public static string GetCacheName(Type cacheItemType)
{
var cacheNameAttribute = cacheItemType
.GetCustomAttributes(true)
.OfType<CacheNameAttribute>()
.FirstOrDefault();
if (cacheNameAttribute != null)
{
return cacheNameAttribute.Name;
}
return cacheItemType.FullName.RemovePostFix("CacheItem");
}
}
}

@ -127,7 +127,7 @@ namespace Volo.Abp.Caching
return value;
}
using (AsyncLock.Lock())
using (AsyncLock.Lock(CancellationTokenProvider.Token))
{
value = Get(key, hideErrors);
if (value != null)
@ -326,13 +326,7 @@ namespace Volo.Abp.Caching
protected virtual void SetDefaultOptions()
{
//CacheName
var cacheNameAttribute = typeof(TCacheItem)
.GetCustomAttributes(true)
.OfType<CacheNameAttribute>()
.FirstOrDefault();
CacheName = cacheNameAttribute != null ? cacheNameAttribute.Name : typeof(TCacheItem).FullName;
CacheName = CacheNameAttribute.GetCacheName(typeof(TCacheItem));
//IgnoreMultiTenancy
IgnoreMultiTenancy = typeof(TCacheItem).IsDefined(typeof(IgnoreMultiTenancyAttribute), true);

@ -6,7 +6,7 @@ namespace Volo.Abp.Threading
{
public static NullCancellationTokenProvider Instance { get; } = new NullCancellationTokenProvider();
public CancellationToken Token { get; } = default;
public CancellationToken Token { get; } = CancellationToken.None;
private NullCancellationTokenProvider()
{

@ -50,7 +50,7 @@ namespace Volo.Abp.Authorization
[Fact]
public void Should_Permission_Definition_GetGroup()
{
_permissionDefinitionManager.GetGroups().Count.ShouldBe(2);
_permissionDefinitionManager.GetGroups().Count.ShouldBe(1);
}
}
}

@ -13,6 +13,8 @@ namespace Volo.Abp.Authorization.TestServices
}
PermissionGroupDefinition group = context.AddGroup("TestGroup");
group.AddPermission("MyAuthorizedService1");
context.RemoveGroup("TestGetGroup");
}
}
}

@ -14,7 +14,7 @@ namespace Volo.Docs.Admin
CreateMap<EditModel.EditGithubProjectViewModel, UpdateProjectDto>().Ignore(x => x.ExtraProperties);
CreateMap<ProjectDto, EditModel.EditGithubProjectViewModel > ()
.Ignore(x => x.GitHubAccessToken).Ignore(x => x.GitHubRootUrl);
.Ignore(x => x.GitHubAccessToken).Ignore(x => x.GitHubRootUrl).Ignore(x => x.GitHubUserAgent);
}
}
}

@ -60,6 +60,7 @@ namespace Volo.Docs.Admin.Pages.Docs.Admin.Projects
dto.ExtraProperties = new Dictionary<string, object>
{
{nameof(GithubProject.GitHubRootUrl), GithubProject.GitHubRootUrl},
{nameof(GithubProject.GitHubUserAgent), GithubProject.GitHubUserAgent},
{nameof(GithubProject.GitHubAccessToken), GithubProject.GitHubAccessToken}
};
@ -109,6 +110,10 @@ namespace Volo.Docs.Admin.Pages.Docs.Admin.Projects
[DisplayOrder(10001)]
[StringLength(512)]
public string GitHubAccessToken { get; set; }
[DisplayOrder(10002)]
[StringLength(64)]
public string GitHubUserAgent { get; set; }
}
}
}

@ -62,6 +62,7 @@ namespace Volo.Docs.Admin.Pages.Docs.Admin.Projects
dto.ExtraProperties = new Dictionary<string, object>
{
{nameof(GithubProject.GitHubRootUrl), GithubProject.GitHubRootUrl},
{nameof(GithubProject.GitHubUserAgent), GithubProject.GitHubUserAgent},
{nameof(GithubProject.GitHubAccessToken), GithubProject.GitHubAccessToken}
};
@ -74,6 +75,7 @@ namespace Volo.Docs.Admin.Pages.Docs.Admin.Projects
GithubProject.GitHubAccessToken = (string) dto.ExtraProperties[nameof(GithubProject.GitHubAccessToken)];
GithubProject.GitHubRootUrl = (string) dto.ExtraProperties[nameof(GithubProject.GitHubRootUrl)];
GithubProject.GitHubUserAgent = (string) dto.ExtraProperties[nameof(GithubProject.GitHubUserAgent)];
}
public abstract class EditProjectViewModelBase
@ -116,6 +118,11 @@ namespace Volo.Docs.Admin.Pages.Docs.Admin.Projects
[DisplayOrder(10001)]
[StringLength(512)]
public string GitHubAccessToken { get; set; }
[DisplayOrder(10002)]
[StringLength(64)]
public string GitHubUserAgent { get; set; }
}
}
}

@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.Logging;
using Volo.Abp.Application.Services;
using Volo.Abp.Caching;
using Volo.Docs.Projects;
@ -94,9 +95,10 @@ namespace Volo.Docs.Documents
cacheKey,
async () =>
{
Logger.LogInformation($"Not found in the cache. Requesting {documentName} from the store...");
var store = _documentStoreFactory.Create(project.DocumentStoreType);
var document = await store.GetDocumentAsync(project, documentName, version);
Logger.LogInformation($"Document retrieved: {documentName}");
return CreateDocumentWithDetailsDto(project, document);
},
() => new DistributedCacheEntryOptions

@ -50,7 +50,8 @@ namespace Volo.Docs.GitHub.Documents
Format = project.Format,
LocalDirectory = localDirectory,
FileName = fileName,
Contributors = !isNavigationDocument ? await GetContributors(commitHistoryUrl, token, userAgent): new List<DocumentContributor>(),
Contributors = new List<DocumentContributor>(),
//Contributors = !isNavigationDocument ? await GetContributors(commitHistoryUrl, token, userAgent): new List<DocumentContributor>(),
Version = version,
Content = await DownloadWebContentAsStringAsync(rawDocumentUrl, token, userAgent)
};

@ -45,7 +45,7 @@
<nav class="navbar navbar-logo">
@if (!Model.Project.Name.IsNullOrWhiteSpace())
{
<a class="navbar-brand w-100" href="@Model.CreateLink(Model.LatestVersionInfo, Model.GetSpecificVersionOrLatest())">
<a class="navbar-brand w-100" href="@Model.CreateVersionLink(Model.LatestVersionInfo, Model.GetSpecificVersionOrLatest())">
<span id="ProjectName">@Model.Project.Name</span><br>
<strong class="display-block">
@L["Documents"]
@ -72,12 +72,21 @@
</div>
<div class="docs-tree-list">
<div class="docs-filter">
<input class="form-control" type="search" placeholder="Filter topics" aria-label="Filter">
<span class="my-2 filter-icon my-sm-0">
<i class="fa fa-filter"></i>
</span>
</div>
@if (Model.ProjectSelectItems.Any())
{
<div class="docs-version">
<div class="version-select">
<div class="input-group">
<div class="input-group-prepend">
<label class="input-group-text">@L["Project"]</label>
</div>
<select asp-items="Model.ProjectSelectItems" class="form-control" onchange="window.location.replace(this.value)"></select>
</div>
</div>
</div>
}
@if (Model.VersionSelectItems.Any())
{
@ -88,12 +97,19 @@
<label class="input-group-text">@L["Version"]</label>
</div>
<select asp-items="Model.VersionSelectItems" class="form-control" onchange="window.location.replace(this.value)"></select>
<select asp-items="Model.VersionSelectItems" class="form-control" onchange="if (this.value) { window.location.replace(this.value) }"></select>
</div>
</div>
</div>
}
<div class="docs-filter">
<input class="form-control" type="search" placeholder="Filter topics" aria-label="Filter">
<span class="my-2 filter-icon my-sm-0">
<i class="fa fa-filter"></i>
</span>
</div>
@if (Model.Navigation == null || Model.Navigation.Content.IsNullOrEmpty())
{
<div class="text-muted p-3">

@ -31,6 +31,8 @@ namespace Volo.Docs.Pages.Documents.Project
public List<SelectListItem> VersionSelectItems { get; private set; }
public List<SelectListItem> ProjectSelectItems { get; private set; }
public NavigationWithDetailsDto Navigation { get; private set; }
public VersionInfoViewModel LatestVersionInfo { get; private set; }
@ -52,6 +54,7 @@ namespace Volo.Docs.Pages.Documents.Project
public async Task OnGetAsync()
{
await SetProjectAsync();
await SetProjectsAsync();
await SetVersionAsync();
await SetDocumentAsync();
await SetNavigationAsync();
@ -62,6 +65,18 @@ namespace Volo.Docs.Pages.Documents.Project
Project = await _projectAppService.GetAsync(ProjectName);
}
private async Task SetProjectsAsync()
{
var projects = await _projectAppService.GetListAsync();
ProjectSelectItems = projects.Items.Select(p => new SelectListItem
{
Text = p.Name,
Value = p.Id != Project.Id ? "/documents/" + p.ShortName + "/" + DocsAppConsts.Latest : null,
Selected = p.Id == Project.Id
}).ToList();
}
private async Task SetVersionAsync()
{
//TODO: Needs refactoring
@ -101,7 +116,7 @@ namespace Volo.Docs.Pages.Documents.Project
VersionSelectItems = versions.Select(v => new SelectListItem
{
Text = v.DisplayText,
Value = CreateLink(LatestVersionInfo, v.Version, DocumentName),
Value = CreateVersionLink(LatestVersionInfo, v.Version, DocumentName),
Selected = v.IsSelected
}).ToList();
}
@ -128,7 +143,7 @@ namespace Volo.Docs.Pages.Documents.Project
Navigation.ConvertItems();
}
public string CreateLink(VersionInfoViewModel latestVersion, string version, string documentName = null)
public string CreateVersionLink(VersionInfoViewModel latestVersion, string version, string documentName = null)
{
if (latestVersion == null || latestVersion.Version == version)
{

@ -1,5 +1,4 @@
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Identity.Localization;
using Volo.Abp.Identity.Localization;
using Volo.Abp.Localization;
using Volo.Abp.Modularity;
using Volo.Abp.Users;

@ -7,15 +7,19 @@ using Volo.Abp.EventBus.Distributed;
using Volo.Abp.Identity.Localization;
using Volo.Abp.Localization;
using Volo.Abp.Modularity;
using Volo.Abp.SettingManagement;
using Volo.Abp.Settings;
using Volo.Abp.Users;
using Volo.Abp.VirtualFileSystem;
namespace Volo.Abp.Identity
{
[DependsOn(typeof(AbpDddDomainModule))]
[DependsOn(typeof(AbpIdentityDomainSharedModule))]
[DependsOn(typeof(AbpUsersDomainModule))]
[DependsOn(
typeof(AbpDddDomainModule),
typeof(AbpIdentityDomainSharedModule),
typeof(AbpUsersDomainModule),
typeof(AbpSettingManagementDomainModule)
)]
public class AbpIdentityDomainModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)

@ -14,7 +14,6 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Core\Volo.Abp.Core.csproj" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Localization\Volo.Abp.Localization.csproj" />
</ItemGroup>

@ -1,13 +1,14 @@
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.IdentityServer.Localization;
using Volo.Abp.IdentityServer.Localization;
using Volo.Abp.Localization;
using Volo.Abp.Modularity;
namespace Volo.Abp.IdentityServer
{
[DependsOn(
typeof(AbpLocalizationModule)
)]
public class AbpIdentityServerDomainSharedModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
Configure<AbpLocalizationOptions>(options =>

@ -8,15 +8,15 @@
public const int ClientNameMaxLength = 200;
public const int ClientUriMaxLength = 2000;
public const int ClientUriMaxLength = 300;
public const int LogoUriMaxLength = 2000;
public const int LogoUriMaxLength = 300;
public const int DescriptionMaxLength = 1000;
public const int FrontChannelLogoutUriMaxLength = 2000;
public const int FrontChannelLogoutUriMaxLength = 300;
public const int BackChannelLogoutUriMaxLength = 2000;
public const int BackChannelLogoutUriMaxLength = 300;
public const int ClientClaimsPrefixMaxLength = 200;

@ -2,7 +2,7 @@
{
public class ClientPropertyConsts
{
public const int KeyMaxLength = 250;
public const int ValueMaxLength = 2000;
public const int KeyMaxLength = 64;
public const int ValueMaxLength = 128;
}
}

@ -2,6 +2,6 @@
{
public class ClientRedirectUriConsts
{
public const int RedirectUriMaxLength = 2000;
public const int RedirectUriMaxLength = 200;
}
}

@ -0,0 +1,57 @@
using IdentityServer4.Services;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using System;
using System.Linq;
using System.Threading.Tasks;
using Volo.Abp.Caching;
using Volo.Abp.DependencyInjection;
using Volo.Abp.IdentityServer.Clients;
namespace Volo.Abp.IdentityServer
{
public class AbpCorsPolicyService : ICorsPolicyService
{
public ILogger<AbpCorsPolicyService> Logger { get; set; }
protected IHybridServiceScopeFactory HybridServiceScopeFactory { get; }
protected IDistributedCache<AllowedCorsOriginsCacheItem> Cache { get; }
public AbpCorsPolicyService(
IDistributedCache<AllowedCorsOriginsCacheItem> cache,
IHybridServiceScopeFactory hybridServiceScopeFactory)
{
Cache = cache;
HybridServiceScopeFactory = hybridServiceScopeFactory;
Logger = NullLogger<AbpCorsPolicyService>.Instance;
}
public async Task<bool> IsOriginAllowedAsync(string origin)
{
var cacheItem = await Cache.GetOrAddAsync(AllowedCorsOriginsCacheItem.AllOrigins, CreateCacheItemAsync);
var isAllowed = cacheItem.AllowedOrigins.Contains(origin, StringComparer.OrdinalIgnoreCase);
if (!isAllowed)
{
Logger.LogWarning($"Origin is not allowed: {origin}");
}
return isAllowed;
}
protected virtual async Task<AllowedCorsOriginsCacheItem> CreateCacheItemAsync()
{
// doing this here and not in the ctor because: https://github.com/aspnet/AspNetCore/issues/2377
using (var scope = HybridServiceScopeFactory.CreateScope())
{
var clientRepository = scope.ServiceProvider.GetRequiredService<IClientRepository>();
return new AllowedCorsOriginsCacheItem
{
AllowedOrigins = (await clientRepository.GetAllDistinctAllowedCorsOriginsAsync()).ToArray()
};
}
}
}
}

@ -12,7 +12,6 @@ namespace Volo.Abp.IdentityServer
{
[DependsOn(
typeof(AbpIdentityServerDomainSharedModule),
typeof(AbpDddDomainModule),
typeof(AbpAutoMapperModule),
typeof(AbpIdentityDomainModule),
typeof(AbpSecurityModule)

@ -0,0 +1,9 @@
namespace Volo.Abp.IdentityServer
{
public class AllowedCorsOriginsCacheItem
{
public const string AllOrigins = "AllOrigins";
public string[] AllowedOrigins { get; set; }
}
}

@ -0,0 +1,24 @@
using System.Threading.Tasks;
using Volo.Abp.Caching;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Entities.Events;
using Volo.Abp.EventBus;
using Volo.Abp.IdentityServer.Clients;
namespace Volo.Abp.IdentityServer
{
public class AllowedCorsOriginsCacheItemInvalidator : ILocalEventHandler<EntityChangedEventData<Client>>, ITransientDependency
{
protected IDistributedCache<AllowedCorsOriginsCacheItem> Cache { get; }
public AllowedCorsOriginsCacheItemInvalidator(IDistributedCache<AllowedCorsOriginsCacheItem> cache)
{
Cache = cache;
}
public async Task HandleEventAsync(EntityChangedEventData<Client> eventData)
{
await Cache.RemoveAsync(AllowedCorsOriginsCacheItem.AllOrigins);
}
}
}

@ -32,7 +32,5 @@ namespace Volo.Abp.IdentityServer.ApiResources
bool includeDetails = false,
CancellationToken cancellationToken = default
);
Task<long> GetTotalCount();
}
}

@ -23,6 +23,6 @@ namespace Volo.Abp.IdentityServer.Clients
CancellationToken cancellationToken = default
);
Task<long> GetTotalCount();
Task<List<string>> GetAllDistinctAllowedCorsOriginsAsync(CancellationToken cancellationToken = default);
}
}

@ -27,7 +27,5 @@ namespace Volo.Abp.IdentityServer.IdentityResources
bool includeDetails = true,
CancellationToken cancellationToken = default
);
Task<long> GetTotalCountAsync();
}
}

@ -13,7 +13,8 @@ namespace Volo.Abp.IdentityServer
return builder
.AddClientStore<ClientStore>()
.AddResourceStore<ResourceStore>();
.AddResourceStore<ResourceStore>()
.AddCorsPolicyService<AbpCorsPolicyService>();
}
}
}

@ -61,11 +61,6 @@ namespace Volo.Abp.IdentityServer.ApiResources
.ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<long> GetTotalCount()
{
return await DbSet.CountAsync();
}
public override async Task DeleteAsync(Guid id, bool autoSave = false, CancellationToken cancellationToken = default)
{
var scopeClaims = DbContext.Set<ApiScopeClaim>().Where(sc => sc.ApiResourceId == id);

@ -37,9 +37,13 @@ namespace Volo.Abp.IdentityServer.Clients
.ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<long> GetTotalCount()
public async Task<List<string>> GetAllDistinctAllowedCorsOriginsAsync(CancellationToken cancellationToken = default)
{
return await DbSet.CountAsync();
return await DbSet
.AsNoTracking()
.SelectMany(x => x.AllowedCorsOrigins.Select(y => y.Origin))
.Distinct()
.ToListAsync(GetCancellationToken(cancellationToken));
}
public override IQueryable<Client> WithDetails()

@ -56,10 +56,5 @@ namespace Volo.Abp.IdentityServer.IdentityResources
.Where(x => x.Name == name)
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<long> GetTotalCountAsync()
{
return await DbSet.CountAsync();
}
}
}

@ -14,16 +14,26 @@ namespace Volo.Abp.IdentityServer.MongoDB
{
public class MongoClientRepository : MongoDbRepository<IAbpIdentityServerMongoDbContext, Client, Guid>, IClientRepository
{
public MongoClientRepository(IMongoDbContextProvider<IAbpIdentityServerMongoDbContext> dbContextProvider) : base(dbContextProvider)
public MongoClientRepository(
IMongoDbContextProvider<IAbpIdentityServerMongoDbContext> dbContextProvider
) : base(
dbContextProvider)
{
}
public virtual async Task<Client> FindByCliendIdAsync(string clientId, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<Client> FindByCliendIdAsync(
string clientId,
bool includeDetails = true,
CancellationToken cancellationToken = default)
{
return await GetMongoQueryable().FirstOrDefaultAsync(x => x.ClientId == clientId, GetCancellationToken(cancellationToken));
}
public virtual async Task<List<Client>> GetListAsync(string sorting, int skipCount, int maxResultCount, bool includeDetails = false,
public virtual async Task<List<Client>> GetListAsync(
string sorting,
int skipCount,
int maxResultCount,
bool includeDetails = false,
CancellationToken cancellationToken = default)
{
return await GetMongoQueryable()
@ -33,6 +43,16 @@ namespace Volo.Abp.IdentityServer.MongoDB
.ToListAsync(GetCancellationToken(cancellationToken));
}
public async Task<List<string>> GetAllDistinctAllowedCorsOriginsAsync(
CancellationToken cancellationToken = default)
{
return await GetMongoQueryable()
.SelectMany(x => x.AllowedCorsOrigins)
.Select(y => y.Origin)
.Distinct()
.ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<long> GetTotalCount()
{
return await GetCountAsync();

@ -0,0 +1,10 @@
namespace Volo.Abp.IdentityServer
{
public class AbpIdentityServerDomainTestBase : AbpIntegratedTest<AbpIdentityServerDomainTestModule>
{
protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options)
{
options.UseAutofac();
}
}
}

@ -0,0 +1,41 @@
using System.Threading.Tasks;
using IdentityServer4.Services;
using Shouldly;
using Volo.Abp.IdentityServer.Clients;
using Xunit;
namespace Volo.Abp.IdentityServer
{
public class CorsPolicyService_Tests : AbpIdentityServerDomainTestBase
{
private readonly ICorsPolicyService _corsPolicyService;
private readonly IClientRepository _clientRepository;
public CorsPolicyService_Tests()
{
_corsPolicyService = GetRequiredService<ICorsPolicyService>();
_clientRepository = GetRequiredService<IClientRepository>();
}
[Fact]
public async Task IsOriginAllowedAsync()
{
(await _corsPolicyService.IsOriginAllowedAsync("https://client1-origin.com")).ShouldBeTrue();
(await _corsPolicyService.IsOriginAllowedAsync("https://unknown-origin.com")).ShouldBeFalse();
}
[Fact]
public async Task IsOriginAllowedAsync_Should_Invalidate_Cache_On_Update()
{
//It does not exists before
(await _corsPolicyService.IsOriginAllowedAsync("https://new-origin.com")).ShouldBeFalse();
var client1 = await _clientRepository.FindByCliendIdAsync("ClientId1");
client1.AddCorsOrigin("https://new-origin.com");
await _clientRepository.UpdateAsync(client1);
//It does exists now
(await _corsPolicyService.IsOriginAllowedAsync("https://new-origin.com")).ShouldBeTrue();
}
}
}

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>netcoreapp2.2</TargetFramework>
<AssemblyName>Volo.Abp.IdentityServer.EntityFrameworkCore.Tests</AssemblyName>
<PackageId>Volo.Abp.IdentityServer.EntityFrameworkCore.Tests</PackageId>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
@ -15,9 +15,7 @@
<ProjectReference Include="..\..\src\Volo.Abp.IdentityServer.EntityFrameworkCore\Volo.Abp.IdentityServer.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\..\..\..\modules\identity\src\Volo.Abp.Identity.EntityFrameworkCore\Volo.Abp.Identity.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Autofac\Volo.Abp.Autofac.csproj" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.TestBase\Volo.Abp.TestBase.csproj" />
<ProjectReference Include="..\Volo.Abp.IdentityServer.TestBase\Volo.Abp.IdentityServer.TestBase.csproj" />
</ItemGroup>
<ItemGroup>

@ -10,9 +10,12 @@ using Volo.Abp.Uow;
namespace Volo.Abp.IdentityServer
{
[DependsOn(typeof(AbpAutofacModule))]
[DependsOn(typeof(AbpIdentityServerEntityFrameworkCoreModule))]
[DependsOn(typeof(AbpIdentityEntityFrameworkCoreModule))]
[DependsOn(
typeof(AbpAutofacModule),
typeof(AbpIdentityEntityFrameworkCoreModule),
typeof(AbpIdentityServerEntityFrameworkCoreModule),
typeof(AbpIdentityServerTestBaseModule)
)]
public class AbpIdentityServerTestEntityFrameworkCoreModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)

@ -0,0 +1,7 @@
namespace Volo.Abp.IdentityServer
{
public class ClientRepository_Tests : ClientRepository_Tests<AbpIdentityServerTestEntityFrameworkCoreModule>
{
}
}

@ -81,10 +81,8 @@ namespace Volo.Abp.IdentityServer.Clients
//Assert
resources.ShouldNotBe(null);
resources.ApiResources.Count.ShouldBe(1);
resources.ApiResources.First().Name.ShouldBe("Test-ApiResource-Name-1");
resources.IdentityResources.First().Name.ShouldBe("Test-Identity-Resource-Name-1");
resources.IdentityResources.First().Required.ShouldBe(true);
resources.ApiResources.Count.ShouldBeGreaterThan(0);
resources.ApiResources.Any(r => r.Name == "Test-ApiResource-Name-1").ShouldBeTrue();
}
}
}

@ -0,0 +1,7 @@
namespace Volo.Abp.IdentityServer
{
public class IdentityResourceRepository_Tests : IdentityResourceRepository_Tests<AbpIdentityServerTestEntityFrameworkCoreModule>
{
}
}

@ -1,5 +1,4 @@
using Microsoft.Extensions.DependencyInjection;
using Mongo2Go;
using Mongo2Go;
using Volo.Abp.Data;
using Volo.Abp.IdentityServer.MongoDB;
using Volo.Abp.Modularity;

@ -90,7 +90,7 @@ namespace Volo.Abp.IdentityServer
FrontChannelLogoutUri = nameof(Client.FrontChannelLogoutUri)
};
client.AddCorsOrigin(nameof(ClientCorsOrigin.Origin));
client.AddCorsOrigin("https://client1-origin.com");
client.AddClaim(nameof(ClientClaim.Value), nameof(ClientClaim.Type));
client.AddGrantType(nameof(ClientGrantType.GrantType));
client.AddIdentityProviderRestriction(nameof(ClientIdPRestriction.Provider));

@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
@ -15,7 +13,7 @@ namespace Volo.Abp.IdentityServer
{
protected IClientRepository clientRepository { get; }
public ClientRepository_Tests()
protected ClientRepository_Tests()
{
clientRepository = ServiceProvider.GetRequiredService<IClientRepository>();
}
@ -25,5 +23,12 @@ namespace Volo.Abp.IdentityServer
{
(await clientRepository.FindByCliendIdAsync("ClientId2")).ShouldNotBeNull();
}
[Fact]
public async Task GetAllDistinctAllowedCorsOriginsAsync()
{
var origins = await clientRepository.GetAllDistinctAllowedCorsOriginsAsync();
origins.Any().ShouldBeTrue();
}
}
}

@ -12,52 +12,28 @@
<abp-modal size="Large">
<abp-modal-header title="@(L["Permissions"].Value) - @Model.EntityDisplayName"></abp-modal-header>
<abp-modal-header title="@(L["Permissions"].Value) - @Model.EntityDisplayName">
</abp-modal-header>
<abp-modal-body>
<input asp-for="@Model.ProviderKey" />
<input asp-for="@Model.ProviderName" />
<abp-row h-align="End">
<div class="btn-group btn-group-toggle" data-toggle="buttons">
<label class="btn btn-light btn-sm @(Model.ShowOnlyProviderPermissons? "":"active")">
<input type="radio" value="0" name="ShowOnlyProviderPermissonsToggle" autocomplete="off"
@(Model.ShowOnlyProviderPermissons ? "" : "checked") /> @L["All"]
</label>
<label id="ShowOnlyProviderPermissonsLabel" class="btn btn-light btn-sm @(!Model.ShowOnlyProviderPermissons? "":"active")">
<input type="radio" value="1" name="ShowOnlyProviderPermissonsToggle" id="ShowOnlyProviderPermissonsInput" autocomplete="off"
@(!Model.ShowOnlyProviderPermissons ? "" : "checked") /> @L["OnlyProviderPermissons"]
</label>
</div>
</abp-row>
<abp-tabs tab-style="PillVertical" vertical-header-size="_4">
@for (var i = 0; i < Model.Groups.Count; i++)
{
var hideTabOnProviderToggle = true;
@for (var j = 0; j < Model.Groups[i].Permissions.Count; j++)
{
if (!(!Model.Groups[i].Permissions[j].AllowedProviders?.Any() ?? true))
{
hideTabOnProviderToggle = false;
break;
}
}
<abp-tab header-class="@(hideTabOnProviderToggle?"hideTabOnProviderToggle":"")" title="@Model.Groups[i].DisplayName" name="v-pills-tab-@Model.Groups[i].GetNormalizedGroupName()">
<abp-tab title="@Model.Groups[i].DisplayName" name="v-pills-tab-@Model.Groups[i].GetNormalizedGroupName()">
<h2>@Model.Groups[i].DisplayName</h2>
@for (var j = 0; j < Model.Groups[i].Permissions.Count; j++)
{
var hidePermissonOnProviderToggle = !Model.Groups[i].Permissions[j].AllowedProviders?.Any() ?? true;
<div class="@(hidePermissonOnProviderToggle?"hidePermissonOnProviderToggle":"")">
<abp-input asp-for="@Model.Groups[i].Permissions[j].IsGranted"
label="@Model.Groups[i].Permissions[j].GetShownName(Model.ProviderName)"
disabled="@Model.Groups[i].Permissions[j].IsDisabled(Model.ProviderName)"
group-data-permission-name="@Model.Groups[i].Permissions[j].Name"
group-data-parent-name="@(Model.Groups[i].Permissions[j].ParentName ?? "")"
group-style="margin-left: @(Model.Groups[i].Permissions[j].Depth * 20)px" />
<input asp-for="@Model.Groups[i].Permissions[j].Name" />
</div>
<abp-input asp-for="@Model.Groups[i].Permissions[j].IsGranted"
label="@Model.Groups[i].Permissions[j].GetShownName(Model.ProviderName)"
disabled="@Model.Groups[i].Permissions[j].IsDisabled(Model.ProviderName)"
group-data-permission-name="@Model.Groups[i].Permissions[j].Name"
group-data-parent-name="@(Model.Groups[i].Permissions[j].ParentName ?? "")"
group-style="margin-left: @(Model.Groups[i].Permissions[j].Depth * 20)px" />
<input asp-for="@Model.Groups[i].Permissions[j].Name" />
}
</abp-tab>
}

@ -20,9 +20,6 @@ namespace Volo.Abp.PermissionManagement.Web.Pages.AbpPermissionManagement
[BindProperty(SupportsGet = true)]
public string ProviderKey { get; set; }
[BindProperty(SupportsGet = true)]
public bool ShowOnlyProviderPermissons { get; set; } = false;
[BindProperty]
public List<PermissionGroupViewModel> Groups { get; set; }

@ -4,12 +4,12 @@
abp.modals.PermissionManagement = function () {
function checkParents($tab, $checkBox) {
var parentName = $checkBox.closest('.form-check').attr('data-parent-name');
var parentName = $checkBox.closest('.custom-checkbox').attr('data-parent-name');
if (!parentName) {
return;
}
$tab.find('.form-check')
$tab.find('.custom-checkbox')
.filter('[data-permission-name="' + parentName + '"]')
.find('input[type="checkbox"]')
.each(function() {
@ -20,12 +20,12 @@
}
function uncheckChildren($tab, $checkBox) {
var permissionName = $checkBox.closest('.form-check').attr('data-permission-name');
var permissionName = $checkBox.closest('.custom-checkbox').attr('data-permission-name');
if (!permissionName) {
return;
}
$tab.find('.form-check')
$tab.find('.custom-checkbox')
.filter('[data-parent-name="' + permissionName + '"]')
.find('input[type="checkbox"]')
.each(function () {
@ -35,17 +35,6 @@
});
}
function togglePermissions(radioButton) {
if (radioButton.val() == '1') {
$('.hidePermissonOnProviderToggle').slideUp();
$('.hideTabOnProviderToggle').slideUp();
}
else {
$('.hidePermissonOnProviderToggle').slideDown();
$('.hideTabOnProviderToggle').slideDown();
}
}
this.initDom = function($el) {
$el.find('.tab-pane').each(function () {
var $tab = $(this);
@ -60,18 +49,6 @@
});
});
});
var radioButton = $('input:radio[name="ShowOnlyProviderPermissonsToggle"]');
if ($('#ShowOnlyProviderPermissonsLabel').hasClass('active')) {
$('.hidePermissonOnProviderToggle').slideUp();
$('.hideTabOnProviderToggle').slideUp();
}
radioButton.change(
function () {
togglePermissions($(this));
});
};
};
})(jQuery);
Loading…
Cancel
Save