Refactored from ISystemClock to TimeProvider (#14963)
* Removed obsolete ISystemClock. The SecurityStampValidator provides the TimeProvider. * Removed obsolete ISystemClock. * Refactored obsolete ISystemClock with TimeProvider
This commit is contained in:
@@ -13,8 +13,8 @@ public class BackOfficeSecurityStampValidator : SecurityStampValidator<BackOffic
|
|||||||
{
|
{
|
||||||
public BackOfficeSecurityStampValidator(
|
public BackOfficeSecurityStampValidator(
|
||||||
IOptions<BackOfficeSecurityStampValidatorOptions> options,
|
IOptions<BackOfficeSecurityStampValidatorOptions> options,
|
||||||
BackOfficeSignInManager signInManager, ISystemClock clock, ILoggerFactory logger)
|
BackOfficeSignInManager signInManager, ILoggerFactory logger)
|
||||||
: base(options, signInManager, clock, logger)
|
: base(options, signInManager, logger)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,15 +35,15 @@ public class BackOfficeSessionIdValidator
|
|||||||
{
|
{
|
||||||
public const string CookieName = "UMB_UCONTEXT_C";
|
public const string CookieName = "UMB_UCONTEXT_C";
|
||||||
private readonly GlobalSettings _globalSettings;
|
private readonly GlobalSettings _globalSettings;
|
||||||
private readonly ISystemClock _systemClock;
|
private readonly TimeProvider _timeProvider;
|
||||||
private readonly IBackOfficeUserManager _userManager;
|
private readonly IBackOfficeUserManager _userManager;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="BackOfficeSessionIdValidator" /> class.
|
/// Initializes a new instance of the <see cref="BackOfficeSessionIdValidator" /> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public BackOfficeSessionIdValidator(ISystemClock systemClock, IOptionsSnapshot<GlobalSettings> globalSettings, IBackOfficeUserManager userManager)
|
public BackOfficeSessionIdValidator(TimeProvider timeProvider, IOptionsSnapshot<GlobalSettings> globalSettings, IBackOfficeUserManager userManager)
|
||||||
{
|
{
|
||||||
_systemClock = systemClock;
|
_timeProvider = timeProvider;
|
||||||
_globalSettings = globalSettings.Value;
|
_globalSettings = globalSettings.Value;
|
||||||
_userManager = userManager;
|
_userManager = userManager;
|
||||||
}
|
}
|
||||||
@@ -55,7 +55,7 @@ public class BackOfficeSessionIdValidator
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var valid = await ValidateSessionAsync(validateInterval, context.HttpContext, context.Options.CookieManager, _systemClock, context.Properties.IssuedUtc, context.Principal?.Identity as ClaimsIdentity);
|
var valid = await ValidateSessionAsync(validateInterval, context.HttpContext, context.Options.CookieManager, _timeProvider, context.Properties.IssuedUtc, context.Principal?.Identity as ClaimsIdentity);
|
||||||
|
|
||||||
if (valid == false)
|
if (valid == false)
|
||||||
{
|
{
|
||||||
@@ -68,7 +68,7 @@ public class BackOfficeSessionIdValidator
|
|||||||
TimeSpan validateInterval,
|
TimeSpan validateInterval,
|
||||||
HttpContext httpContext,
|
HttpContext httpContext,
|
||||||
ICookieManager cookieManager,
|
ICookieManager cookieManager,
|
||||||
ISystemClock systemClock,
|
TimeProvider timeProvider,
|
||||||
DateTimeOffset? authTicketIssueDate,
|
DateTimeOffset? authTicketIssueDate,
|
||||||
ClaimsIdentity? currentIdentity)
|
ClaimsIdentity? currentIdentity)
|
||||||
{
|
{
|
||||||
@@ -82,9 +82,9 @@ public class BackOfficeSessionIdValidator
|
|||||||
throw new ArgumentNullException(nameof(cookieManager));
|
throw new ArgumentNullException(nameof(cookieManager));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (systemClock == null)
|
if (timeProvider == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(systemClock));
|
throw new ArgumentNullException(nameof(timeProvider));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentIdentity == null)
|
if (currentIdentity == null)
|
||||||
@@ -93,7 +93,7 @@ public class BackOfficeSessionIdValidator
|
|||||||
}
|
}
|
||||||
|
|
||||||
DateTimeOffset? issuedUtc = null;
|
DateTimeOffset? issuedUtc = null;
|
||||||
DateTimeOffset currentUtc = systemClock.UtcNow;
|
DateTimeOffset currentUtc = timeProvider.GetUtcNow();
|
||||||
|
|
||||||
// read the last checked time from a custom cookie
|
// read the last checked time from a custom cookie
|
||||||
var lastCheckedCookie = cookieManager.GetRequestCookie(httpContext, CookieName);
|
var lastCheckedCookie = cookieManager.GetRequestCookie(httpContext, CookieName);
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ public class ConfigureBackOfficeCookieOptions : IConfigureNamedOptions<CookieAut
|
|||||||
private readonly IRuntimeState _runtimeState;
|
private readonly IRuntimeState _runtimeState;
|
||||||
private readonly SecuritySettings _securitySettings;
|
private readonly SecuritySettings _securitySettings;
|
||||||
private readonly IServiceProvider _serviceProvider;
|
private readonly IServiceProvider _serviceProvider;
|
||||||
private readonly ISystemClock _systemClock;
|
private readonly TimeProvider _timeProvider;
|
||||||
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
|
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
|
||||||
private readonly UmbracoRequestPaths _umbracoRequestPaths;
|
private readonly UmbracoRequestPaths _umbracoRequestPaths;
|
||||||
private readonly IUserService _userService;
|
private readonly IUserService _userService;
|
||||||
@@ -48,7 +48,7 @@ public class ConfigureBackOfficeCookieOptions : IConfigureNamedOptions<CookieAut
|
|||||||
/// <param name="dataProtection">The <see cref="IDataProtectionProvider" /></param>
|
/// <param name="dataProtection">The <see cref="IDataProtectionProvider" /></param>
|
||||||
/// <param name="userService">The <see cref="IUserService" /></param>
|
/// <param name="userService">The <see cref="IUserService" /></param>
|
||||||
/// <param name="ipResolver">The <see cref="IIpResolver" /></param>
|
/// <param name="ipResolver">The <see cref="IIpResolver" /></param>
|
||||||
/// <param name="systemClock">The <see cref="ISystemClock" /></param>
|
/// <param name="timeProvider">The <see cref="TimeProvider" /></param>
|
||||||
/// <param name="umbracoRequestPaths">The <see cref="UmbracoRequestPaths"/></param>
|
/// <param name="umbracoRequestPaths">The <see cref="UmbracoRequestPaths"/></param>
|
||||||
/// <param name="basicAuthService">The <see cref="IBasicAuthService"/></param>
|
/// <param name="basicAuthService">The <see cref="IBasicAuthService"/></param>
|
||||||
public ConfigureBackOfficeCookieOptions(
|
public ConfigureBackOfficeCookieOptions(
|
||||||
@@ -61,7 +61,7 @@ public class ConfigureBackOfficeCookieOptions : IConfigureNamedOptions<CookieAut
|
|||||||
IDataProtectionProvider dataProtection,
|
IDataProtectionProvider dataProtection,
|
||||||
IUserService userService,
|
IUserService userService,
|
||||||
IIpResolver ipResolver,
|
IIpResolver ipResolver,
|
||||||
ISystemClock systemClock,
|
TimeProvider timeProvider,
|
||||||
UmbracoRequestPaths umbracoRequestPaths,
|
UmbracoRequestPaths umbracoRequestPaths,
|
||||||
IBasicAuthService basicAuthService)
|
IBasicAuthService basicAuthService)
|
||||||
{
|
{
|
||||||
@@ -74,7 +74,7 @@ public class ConfigureBackOfficeCookieOptions : IConfigureNamedOptions<CookieAut
|
|||||||
_dataProtection = dataProtection;
|
_dataProtection = dataProtection;
|
||||||
_userService = userService;
|
_userService = userService;
|
||||||
_ipResolver = ipResolver;
|
_ipResolver = ipResolver;
|
||||||
_systemClock = systemClock;
|
_timeProvider = timeProvider;
|
||||||
_umbracoRequestPaths = umbracoRequestPaths;
|
_umbracoRequestPaths = umbracoRequestPaths;
|
||||||
_basicAuthService = basicAuthService;
|
_basicAuthService = basicAuthService;
|
||||||
}
|
}
|
||||||
@@ -187,8 +187,8 @@ public class ConfigureBackOfficeCookieOptions : IConfigureNamedOptions<CookieAut
|
|||||||
// When we then try and renew, the difference of issued and expires effectively becomes the new ExpireTimeSpan
|
// When we then try and renew, the difference of issued and expires effectively becomes the new ExpireTimeSpan
|
||||||
// meaning we effectively lose 30 minutes of our ExpireTimeSpan for EVERY principal refresh if we don't
|
// meaning we effectively lose 30 minutes of our ExpireTimeSpan for EVERY principal refresh if we don't
|
||||||
// https://github.com/dotnet/aspnetcore/blob/main/src/Security/Authentication/Cookies/src/CookieAuthenticationHandler.cs#L115
|
// https://github.com/dotnet/aspnetcore/blob/main/src/Security/Authentication/Cookies/src/CookieAuthenticationHandler.cs#L115
|
||||||
ctx.Properties.IssuedUtc = _systemClock.UtcNow;
|
ctx.Properties.IssuedUtc = _timeProvider.GetUtcNow();
|
||||||
ctx.Properties.ExpiresUtc = _systemClock.UtcNow.Add(_globalSettings.TimeOut);
|
ctx.Properties.ExpiresUtc = _timeProvider.GetUtcNow().Add(_globalSettings.TimeOut);
|
||||||
ctx.ShouldRenew = true;
|
ctx.ShouldRenew = true;
|
||||||
},
|
},
|
||||||
OnSigningIn = ctx =>
|
OnSigningIn = ctx =>
|
||||||
@@ -296,7 +296,7 @@ public class ConfigureBackOfficeCookieOptions : IConfigureNamedOptions<CookieAut
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
DateTimeOffset currentUtc = _systemClock.UtcNow;
|
DateTimeOffset currentUtc = _timeProvider.GetUtcNow();
|
||||||
DateTimeOffset? issuedUtc = context.Properties.IssuedUtc;
|
DateTimeOffset? issuedUtc = context.Properties.IssuedUtc;
|
||||||
DateTimeOffset? expiresUtc = context.Properties.ExpiresUtc;
|
DateTimeOffset? expiresUtc = context.Properties.ExpiresUtc;
|
||||||
|
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ public class MemberSecurityStampValidator : SecurityStampValidator<MemberIdentit
|
|||||||
{
|
{
|
||||||
public MemberSecurityStampValidator(
|
public MemberSecurityStampValidator(
|
||||||
IOptions<MemberSecurityStampValidatorOptions> options,
|
IOptions<MemberSecurityStampValidatorOptions> options,
|
||||||
MemberSignInManager signInManager, ISystemClock clock, ILoggerFactory logger)
|
MemberSignInManager signInManager, ILoggerFactory logger)
|
||||||
: base(options, signInManager, clock, logger)
|
: base(options, signInManager, logger)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,11 +27,10 @@ public class TestAuthHandler : AuthenticationHandler<AuthenticationSchemeOptions
|
|||||||
IOptionsMonitor<AuthenticationSchemeOptions> options,
|
IOptionsMonitor<AuthenticationSchemeOptions> options,
|
||||||
ILoggerFactory logger,
|
ILoggerFactory logger,
|
||||||
UrlEncoder encoder,
|
UrlEncoder encoder,
|
||||||
ISystemClock clock,
|
|
||||||
IBackOfficeSignInManager backOfficeSignInManager,
|
IBackOfficeSignInManager backOfficeSignInManager,
|
||||||
IUserService userService,
|
IUserService userService,
|
||||||
IUmbracoMapper umbracoMapper)
|
IUmbracoMapper umbracoMapper)
|
||||||
: base(options, logger, encoder, clock)
|
: base(options, logger, encoder)
|
||||||
{
|
{
|
||||||
_backOfficeSignInManager = backOfficeSignInManager;
|
_backOfficeSignInManager = backOfficeSignInManager;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user