From acb82ea9627b9221d966bce0da9447007cfa148c Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Tue, 12 May 2020 13:23:53 -0400 Subject: [PATCH] Additional logging --- .../Security/AuthenticationContextFactory.cs | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/Tgstation.Server.Host/Security/AuthenticationContextFactory.cs b/src/Tgstation.Server.Host/Security/AuthenticationContextFactory.cs index af26926fd2..070642c105 100644 --- a/src/Tgstation.Server.Host/Security/AuthenticationContextFactory.cs +++ b/src/Tgstation.Server.Host/Security/AuthenticationContextFactory.cs @@ -1,9 +1,11 @@ using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Logging; using System; using System.Linq; using System.Threading; using System.Threading.Tasks; using Tgstation.Server.Host.Database; +using Tgstation.Server.Host.Models; namespace Tgstation.Server.Host.Security { @@ -23,15 +25,25 @@ namespace Tgstation.Server.Host.Security /// readonly IIdentityCache identityCache; + /// + /// The for the . + /// + readonly ILogger logger; + /// /// Construct an /// /// The value of /// The value of - public AuthenticationContextFactory(IDatabaseContext databaseContext, IIdentityCache identityCache) + /// The value of . + public AuthenticationContextFactory( + IDatabaseContext databaseContext, + IIdentityCache identityCache, + ILogger logger) { this.databaseContext = databaseContext ?? throw new ArgumentNullException(nameof(databaseContext)); this.identityCache = identityCache ?? throw new ArgumentNullException(nameof(identityCache)); + this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); } /// @@ -69,13 +81,18 @@ namespace Tgstation.Server.Host.Security try { - var instanceUser = instanceId.HasValue - ? await databaseContext.InstanceUsers + InstanceUser instanceUser = null; + if (instanceId.HasValue) + { + instanceUser = await databaseContext.InstanceUsers .Where(x => x.UserId == userId && x.InstanceId == instanceId && x.Instance.Online.Value) .Include(x => x.Instance) .FirstOrDefaultAsync(cancellationToken) - .ConfigureAwait(false) - : null; + .ConfigureAwait(false); + + if (instanceUser == null) + logger.LogDebug("User {0} does not have permissions on instance {1}!", userId, instanceId.Value); + } CurrentAuthenticationContext = new AuthenticationContext(systemIdentity, user, instanceUser); }