Skip to content

Commit

Permalink
Add policy for admin role (#4124)
Browse files Browse the repository at this point in the history
  • Loading branch information
oleksandr-didyk authored Nov 4, 2024
1 parent 78cf8ad commit fc65aa7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public static class AuthenticationConfiguration
{
public const string EntraAuthorizationPolicyName = "Entra";
public const string MsftAuthorizationPolicyName = "msft";
public const string AdminAuthorizationPolicyName = "RequireAdminAccess";

public const string AccountSignInRoute = "/Account/SignIn";

Expand Down Expand Up @@ -111,6 +112,12 @@ public static void ConfigureAuthServices(this IServiceCollection services, IConf
|| context.User.IsInRole(prodconSvcsRole);
});
});
options.AddPolicy(AdminAuthorizationPolicyName, policy =>
{
policy.AddAuthenticationSchemes(AuthenticationSchemes);
policy.RequireAuthenticatedUser();
policy.RequireRole("Admin");
});
});

services.Configure<MvcOptions>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Net;
using Maestro.Authentication;
using Microsoft.AspNetCore.ApiVersioning;
using Microsoft.AspNetCore.ApiVersioning.Swashbuckle;
using Microsoft.AspNetCore.Authorization;
Expand All @@ -12,6 +13,7 @@ namespace ProductConstructionService.Api.Controllers;

[Route("status")]
[ApiVersion("2020-02-20")]
[Authorize(Policy = AuthenticationConfiguration.AdminAuthorizationPolicyName)]
public class StatusController(IReplicaWorkItemProcessorStateCacheFactory replicaWorkItemProcessorStateCacheFactory) : ControllerBase
{
private readonly IReplicaWorkItemProcessorStateCacheFactory _replicaWorkItemProcessorStateCacheFactory = replicaWorkItemProcessorStateCacheFactory;
Expand Down

0 comments on commit fc65aa7

Please sign in to comment.