Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/Bss.Platform.Api.Documentation/DependencyInjection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Options;
using Microsoft.OpenApi.Models;

using Swashbuckle.AspNetCore.SwaggerGen;
Expand Down Expand Up @@ -76,7 +77,14 @@ public static IApplicationBuilder UsePlatformApiDocumentation(
x =>
{
x.RoutePrefix = path;
x.SwaggerEndpoint($"/{path}/api/swagger.json", "api");
var opts = app.ApplicationServices.GetRequiredService<IOptions<SwaggerGenOptions>>()
.Value
.SwaggerGeneratorOptions.SwaggerDocs;

foreach (var doc in opts)
{
x.SwaggerEndpoint($"/{path}/{doc.Key}/swagger.json", doc.Value.Title ?? doc.Key);
}
});
}
}
30 changes: 29 additions & 1 deletion src/Bss.Platform.Events/DependencyInjection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
using DotNetCore.CAP;
using DotNetCore.CAP.Internal;

using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.DependencyInjection;

using Savorboard.CAP.InMemoryMessageQueue;
Expand Down Expand Up @@ -53,7 +55,15 @@ public static IServiceCollection AddPlatformIntegrationEvents<TEventProcessor>(
o.Schema = eventsOptions.SqlServer.Schema;
});

x.UseDashboard(o => o.PathMatch = eventsOptions.DashboardPath);
x.UseDashboard(o =>
{
o.PathMatch = eventsOptions.DashboardPath;
if (eventsOptions.AuthorizationPredicate is { } authPredicate)
{
o.AllowAnonymousExplicit = false;
o.AuthorizationPolicy = AddDashboardAuthorizationPolicy(services, authPredicate);
}
});

if (!eventsOptions.MessageQueue.Enable)
{
Expand All @@ -77,4 +87,22 @@ public static IServiceCollection AddPlatformIntegrationEvents<TEventProcessor>(

return services;
}

private static string AddDashboardAuthorizationPolicy(IServiceCollection services, Func<HttpContext, Task<bool>> authPredicate)
{
const string policyName = "bss-platform-dashboard-auth";
services.AddAuthorizationBuilder()
.AddPolicy(
policyName,
policy => policy.RequireAssertion(ctx =>
{
var httpContext = ctx.Resource as HttpContext
?? (ctx.Resource as AuthorizationFilterContext)?.HttpContext
?? throw new("Can't authorize, http context is not available");

return authPredicate(httpContext);
}));

return policyName;
}
}
10 changes: 10 additions & 0 deletions src/Bss.Platform.Events/Models/IntegrationEventsOptions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Microsoft.AspNetCore.Http;

namespace Bss.Platform.Events.Models;

public class IntegrationEventsOptions
Expand All @@ -11,6 +13,14 @@ public class IntegrationEventsOptions
public IntegrationEventsSqlServerOptions SqlServer { get; set; } = default!;

public IntegrationEventsMessageQueueOptions MessageQueue { get; set; } = default!;

/// <summary>
/// Any condition to check that a user should get access to events dashboard
/// </summary>
/// <example>
/// AuthorizationPolicyPredicate = (httpContext) => httpContext.RequestServices.GetRequiredService&lt;ICurrentUser&gt;().IsAdminAsync()
/// </example>
public Func<HttpContext, Task<bool>>? AuthorizationPredicate { get; set; }

public static IntegrationEventsOptions Default =>
new()
Expand Down
6 changes: 3 additions & 3 deletions src/__SolutionItems/CommonAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
[assembly: AssemblyCompany("Luxoft")]
[assembly: AssemblyCopyright("Copyright © Luxoft 2026")]

[assembly: AssemblyVersion("1.6.7.0")]
[assembly: AssemblyFileVersion("1.6.7.0")]
[assembly: AssemblyInformationalVersion("1.6.7.0")]
[assembly: AssemblyVersion("1.6.8.0")]
[assembly: AssemblyFileVersion("1.6.8.0")]
[assembly: AssemblyInformationalVersion("1.6.8.0")]

#if DEBUG
[assembly: AssemblyConfiguration("Debug")]
Expand Down
Loading