From fd879d696e876305d971070957b13263e78b2bf2 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Sat, 4 Jul 2020 12:44:32 -0400 Subject: [PATCH] More logging --- .../Security/AuthenticationContextFactory.cs | 2 ++ src/Tgstation.Server.Host/Security/ClaimsInjector.cs | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Tgstation.Server.Host/Security/AuthenticationContextFactory.cs b/src/Tgstation.Server.Host/Security/AuthenticationContextFactory.cs index aa019be91f..45935ac098 100644 --- a/src/Tgstation.Server.Host/Security/AuthenticationContextFactory.cs +++ b/src/Tgstation.Server.Host/Security/AuthenticationContextFactory.cs @@ -64,6 +64,7 @@ namespace Tgstation.Server.Host.Security .ConfigureAwait(false); if (user == default) { + logger.LogWarning("Unable to find user with ID {0}!", userId); CurrentAuthenticationContext = new AuthenticationContext(); return; } @@ -75,6 +76,7 @@ namespace Tgstation.Server.Host.Security { if (user.LastPasswordUpdate.HasValue && user.LastPasswordUpdate > validAfter) { + logger.LogDebug("Rejecting token for user {0} created before last password update: {1}", userId, user.LastPasswordUpdate.Value); CurrentAuthenticationContext = new AuthenticationContext(); return; } diff --git a/src/Tgstation.Server.Host/Security/ClaimsInjector.cs b/src/Tgstation.Server.Host/Security/ClaimsInjector.cs index 7fd31958de..e99ef64f2c 100644 --- a/src/Tgstation.Server.Host/Security/ClaimsInjector.cs +++ b/src/Tgstation.Server.Host/Security/ClaimsInjector.cs @@ -1,9 +1,11 @@ using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.Globalization; using System.IdentityModel.Tokens.Jwt; +using System.Linq; using System.Security.Claims; using System.Threading; using System.Threading.Tasks; @@ -20,13 +22,20 @@ namespace Tgstation.Server.Host.Security /// readonly IAuthenticationContextFactory authenticationContextFactory; + /// + /// The for the . + /// + readonly ILogger logger; + /// /// Construct a /// /// The value of - public ClaimsInjector(IAuthenticationContextFactory authenticationContextFactory) + /// The value of + public ClaimsInjector(IAuthenticationContextFactory authenticationContextFactory, ILogger logger) { this.authenticationContextFactory = authenticationContextFactory ?? throw new ArgumentNullException(nameof(authenticationContextFactory)); + this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); } /// @@ -86,6 +95,7 @@ namespace Tgstation.Server.Host.Security claims.Add(new Claim(ClaimTypes.Role, RightsHelper.RoleName(I, J))); } + logger.LogTrace("User {0} claims: {1}", authenticationContext.User.Id, String.Join(", ", claims.Select(x => x.Value))); tokenValidatedContext.Principal.AddIdentity(new ClaimsIdentity(claims)); } }