Skip to content

Commit 3ea765e

Browse files
authored
VCST-4420: Skip password expire check when impersonating (#126)
1 parent 01d1e64 commit 3ea765e

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/VirtoCommerce.ProfileExperienceApiModule.Data/Schemas/ProfileSchema.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,8 @@ public async Task CheckAuthAsync(IResolveFieldContext context, object resource,
773773
var principal = context.GetCurrentPrincipal();
774774
var userId = principal.GetCurrentUserId();
775775
var isExternalSignIn = principal.IsExternalSignIn();
776+
var isImpersonated = principal.IsImpersonated();
777+
776778
var signInManager = _signInManagerFactory();
777779

778780
try
@@ -783,7 +785,7 @@ public async Task CheckAuthAsync(IResolveFieldContext context, object resource,
783785
UserName = Xapi.Core.ModuleConstants.AnonymousUser.UserName,
784786
};
785787

786-
if (checkPasswordExpired && user.PasswordExpired && !isExternalSignIn)
788+
if (checkPasswordExpired && user.PasswordExpired && !isExternalSignIn && !isImpersonated)
787789
{
788790
throw AuthorizationError.PasswordExpired();
789791
}

src/VirtoCommerce.ProfileExperienceApiModule.Data/Schemas/UserType.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public UserType(IContactAggregateRepository contactAggregateRepository, IUserMan
9797

9898
private static bool GetPasswordExpired(IResolveFieldContext<ApplicationUser> context)
9999
{
100-
return context.Source.PasswordExpired && !IsExternalSignIn(context);
100+
return context.Source.PasswordExpired && !IsExternalSignIn(context) && !IsImpersonated(context);
101101
}
102102

103103
private static int? GetPasswordExpiryInDays(IResolveFieldContext<ApplicationUser> context, UserOptionsExtended userOptionsExtended)
@@ -108,6 +108,7 @@ private static bool GetPasswordExpired(IResolveFieldContext<ApplicationUser> con
108108

109109
if (!user.PasswordExpired &&
110110
!IsExternalSignIn(context) &&
111+
!IsImpersonated(context) &&
111112
userOptionsExtended.RemindPasswordExpiryInDays > 0 &&
112113
userOptionsExtended.MaxPasswordAge != null &&
113114
userOptionsExtended.MaxPasswordAge.Value > TimeSpan.Zero)
@@ -129,5 +130,10 @@ private static bool IsExternalSignIn(IResolveFieldContext<ApplicationUser> conte
129130
{
130131
return context.Source.Id == context.GetCurrentUserId() && context.GetCurrentPrincipal().IsExternalSignIn();
131132
}
133+
134+
private static bool IsImpersonated(IResolveFieldContext<ApplicationUser> context)
135+
{
136+
return context.GetCurrentPrincipal().IsImpersonated();
137+
}
132138
}
133139
}

0 commit comments

Comments
 (0)