Skip to content

Commit 315248b

Browse files
committed
Add logging
Signed-off-by: Victor Chang <vicchang@nvidia.com>
1 parent 74a98b1 commit 315248b

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/Authentication/Logging.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@ namespace Monai.Deploy.WorkflowManager.Logging
2020
{
2121
public static partial class Log
2222
{
23-
[LoggerMessage(EventId = 500000, Level = LogLevel.Information, Message = "BYpass authentication.")]
23+
[LoggerMessage(EventId = 500000, Level = LogLevel.Information, Message = "Bypass authentication.")]
2424
public static partial void BypassAuthentication(this ILogger logger);
25+
26+
[LoggerMessage(EventId = 500001, Level = LogLevel.Debug, Message = "User '{user}' attempting to access controller '{controller}'.")]
27+
public static partial void UserAccessingController(this ILogger logger, string? user, string controller);
28+
29+
[LoggerMessage(EventId = 500002, Level = LogLevel.Debug, Message = "User '{user}' access denied due to allowed permissions: '{permissions}'.")]
30+
public static partial void UserAccessDenied(this ILogger logger, string? user, string? permissions);
2531
}
2632
}

src/Authentication/Middleware/EndpointAuthorizationMiddleware.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
using Microsoft.Extensions.Options;
2222
using Monai.Deploy.Security.Authentication.Configurations;
2323
using Monai.Deploy.Security.Authentication.Extensions;
24+
using Monai.Deploy.WorkflowManager.Logging;
2425

2526
namespace Monai.Deploy.Security.Authentication.Middleware
2627
{
@@ -54,11 +55,13 @@ public async Task InvokeAsync(HttpContext httpcontext)
5455
{
5556
if (httpcontext.GetRouteValue("controller") is string controller)
5657
{
58+
_logger.UserAccessingController(httpcontext.User.Identity.Name, controller);
5759
var validEndpoints = httpcontext.GetValidEndpoints(_options.Value.OpenId!.Claims!.RequiredAdminClaims!, _options.Value.OpenId!.Claims!.RequiredUserClaims!);
5860
var result = validEndpoints.Any(e => e.Equals(controller, StringComparison.InvariantCultureIgnoreCase)) || validEndpoints.Contains("all");
5961

6062
if (result is false)
6163
{
64+
_logger.UserAccessDenied(httpcontext.User.Identity.Name, string.Join(',', validEndpoints));
6265
httpcontext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
6366

6467
await httpcontext.Response.CompleteAsync().ConfigureAwait(false);

0 commit comments

Comments
 (0)