Skip to content

Commit

Permalink
Remove unnecessary null check in 2FA authorization filter (#17009)
Browse files Browse the repository at this point in the history
Co-authored-by: Georg von Kries <[email protected]>
  • Loading branch information
hishamco and gvkries authored Nov 30, 2024
1 parent 62ec4b0 commit f74a99b
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ private void ApplyContainedItemOptionsFilter(ContainedItemOptions containedItemO
query.With<ContentItemIndex>(i => !i.Published && i.Latest);
break;
case ContentsStatus.Owner:
var currentUserName = _httpContextAccessor.HttpContext?.User?.FindFirstValue(ClaimTypes.NameIdentifier);
var currentUserName = _httpContextAccessor.HttpContext?.User.FindFirstValue(ClaimTypes.NameIdentifier);

if (currentUserName != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public async Task OnAuthorizationAsync(AuthorizationFilterContext context)
{
ArgumentNullException.ThrowIfNull(context);

if (context.HttpContext?.User?.Identity?.IsAuthenticated == false ||
if ((context.HttpContext?.User.Identity?.IsAuthenticated ?? false) == false ||
context.HttpContext.Request.Path.Equals("/" + _userOptions.LogoffPath, StringComparison.OrdinalIgnoreCase) ||
context.HttpContext.Request.Path.Equals("/" + _userOptions.TwoFactorAuthenticationPath, StringComparison.OrdinalIgnoreCase) ||
context.HttpContext.Request.Path.Equals("/TwoFactor-Authenticator/", StringComparison.OrdinalIgnoreCase))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public override Task<ProviderCultureResult> DetermineProviderCultureResult(HttpC
{
ArgumentNullException.ThrowIfNull(httpContext);

if (httpContext?.User?.Identity?.IsAuthenticated == false)
if ((httpContext?.User.Identity?.IsAuthenticated ?? false) == false)
{
return NullProviderCultureResult;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public override Task CreatingAsync(CreateContentContext context)
context.ContentItem.ModifiedUtc = utcNow;

var httpContext = _httpContextAccessor.HttpContext;
if (context.ContentItem.Owner == null && (httpContext?.User?.Identity?.IsAuthenticated ?? false))
if (context.ContentItem.Owner == null && (httpContext?.User.Identity?.IsAuthenticated ?? false))
{
context.ContentItem.Owner = httpContext.User.FindFirstValue(ClaimTypes.NameIdentifier);
context.ContentItem.Author = httpContext.User.Identity.Name;
Expand All @@ -40,7 +40,7 @@ public override Task UpdatingAsync(UpdateContentContext context)
var utcNow = _clock.UtcNow;
context.ContentItem.ModifiedUtc = utcNow;
var httpContext = _httpContextAccessor.HttpContext;
if (httpContext?.User?.Identity?.IsAuthenticated ?? false)
if (httpContext?.User.Identity?.IsAuthenticated ?? false)
{
// The value is only modified during update so that another event like
// publishing in a Workflow doesn't change it.
Expand Down

0 comments on commit f74a99b

Please sign in to comment.