Skip to content

Commit f5096ba

Browse files
AmbertvuAmbert van Unen
andauthored
Now properly checks the lockedoutdate (#14908)
* Now properly checks the lockedoutdate * Also fix Test (failed constructor) * Processed feedback * Added obsolete constructor --------- Co-authored-by: Ambert van Unen <[email protected]>
1 parent 4bc36a7 commit f5096ba

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

src/Umbraco.Infrastructure/Security/IdentityMapDefinition.cs

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public class IdentityMapDefinition : IMapDefinition
1818
{
1919
private readonly AppCaches _appCaches;
2020
private readonly IEntityService _entityService;
21+
private readonly SecuritySettings _securitySettings;
2122
private readonly GlobalSettings _globalSettings;
2223
private readonly ILocalizedTextService _textService;
2324
private readonly ITwoFactorLoginService _twoFactorLoginService;
@@ -26,28 +27,48 @@ public IdentityMapDefinition(
2627
ILocalizedTextService textService,
2728
IEntityService entityService,
2829
IOptions<GlobalSettings> globalSettings,
30+
IOptions<SecuritySettings> securitySettings,
2931
AppCaches appCaches,
3032
ITwoFactorLoginService twoFactorLoginService)
3133
{
3234
_textService = textService;
3335
_entityService = entityService;
3436
_globalSettings = globalSettings.Value;
37+
_securitySettings = securitySettings.Value;
3538
_appCaches = appCaches;
3639
_twoFactorLoginService = twoFactorLoginService;
3740
}
3841

42+
[Obsolete("Use constructor that also takes an IOptions<SecuritySettings>. Scheduled for removal in V14")]
43+
public IdentityMapDefinition(
44+
ILocalizedTextService textService,
45+
IEntityService entityService,
46+
IOptions<GlobalSettings> globalSettings,
47+
AppCaches appCaches,
48+
ITwoFactorLoginService twoFactorLoginService)
49+
: this(
50+
textService,
51+
entityService,
52+
globalSettings,
53+
StaticServiceProvider.Instance.GetRequiredService<IOptions<SecuritySettings>>(),
54+
appCaches,
55+
twoFactorLoginService)
56+
{
57+
}
58+
3959
[Obsolete("Use constructor that also takes an ITwoFactorLoginService. Scheduled for removal in V12")]
4060
public IdentityMapDefinition(
4161
ILocalizedTextService textService,
4262
IEntityService entityService,
4363
IOptions<GlobalSettings> globalSettings,
4464
AppCaches appCaches)
4565
: this(
46-
textService,
47-
entityService,
48-
globalSettings,
49-
appCaches,
50-
StaticServiceProvider.Instance.GetRequiredService<ITwoFactorLoginService>())
66+
textService,
67+
entityService,
68+
globalSettings,
69+
StaticServiceProvider.Instance.GetRequiredService<IOptions<SecuritySettings>>(),
70+
appCaches,
71+
StaticServiceProvider.Instance.GetRequiredService<ITwoFactorLoginService>())
5172
{
5273
}
5374

@@ -107,7 +128,8 @@ private void Map(IUser source, BackOfficeIdentityUser target)
107128
source.GetUserCulture(_textService, _globalSettings).ToString(); // project CultureInfo to string
108129
target.IsApproved = source.IsApproved;
109130
target.SecurityStamp = source.SecurityStamp;
110-
target.LockoutEnd = source.IsLockedOut ? DateTime.MaxValue.ToUniversalTime() : (DateTime?)null;
131+
DateTime? lockedOutUntil = source.LastLockoutDate?.AddMinutes(_securitySettings.UserDefaultLockoutTimeInMinutes);
132+
target.LockoutEnd = source.IsLockedOut ? (lockedOutUntil ?? DateTime.MaxValue).ToUniversalTime() : null;
111133
}
112134

113135
// Umbraco.Code.MapAll -Id -LockoutEnabled -PhoneNumber -PhoneNumberConfirmed -ConcurrencyStamp -NormalizedEmail -NormalizedUserName -Roles
@@ -124,7 +146,8 @@ private void Map(IMember source, MemberIdentityUser target)
124146
target.PasswordConfig = source.PasswordConfiguration;
125147
target.IsApproved = source.IsApproved;
126148
target.SecurityStamp = source.SecurityStamp;
127-
target.LockoutEnd = source.IsLockedOut ? DateTime.MaxValue.ToUniversalTime() : (DateTime?)null;
149+
DateTime? lockedOutUntil = source.LastLockoutDate?.AddMinutes(_securitySettings.UserDefaultLockoutTimeInMinutes);
150+
target.LockoutEnd = source.IsLockedOut ? (lockedOutUntil ?? DateTime.MaxValue).ToUniversalTime() : null;
128151
target.Comments = source.Comments;
129152
target.LastLockoutDateUtc = source.LastLockoutDate == DateTime.MinValue
130153
? null

tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Security/MemberManagerTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public MemberManager CreateSut()
4343
Mock.Of<ILocalizedTextService>(),
4444
Mock.Of<IEntityService>(),
4545
new TestOptionsSnapshot<GlobalSettings>(new GlobalSettings()),
46+
new TestOptionsSnapshot<SecuritySettings>(new SecuritySettings()),
4647
AppCaches.Disabled,
4748
Mock.Of<ITwoFactorLoginService>())
4849
};

0 commit comments

Comments
 (0)