diff --git a/src/Umbraco.Core/Models/Mapping/MemberTabsAndPropertiesMapper.cs b/src/Umbraco.Core/Models/Mapping/MemberTabsAndPropertiesMapper.cs index 2f1e76b834..faf811607e 100644 --- a/src/Umbraco.Core/Models/Mapping/MemberTabsAndPropertiesMapper.cs +++ b/src/Umbraco.Core/Models/Mapping/MemberTabsAndPropertiesMapper.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using Microsoft.Extensions.Options; diff --git a/src/Umbraco.Core/Security/UmbracoBackOfficeIdentity.cs b/src/Umbraco.Core/Security/UmbracoBackOfficeIdentity.cs index 5fd9f23c92..6c9002f095 100644 --- a/src/Umbraco.Core/Security/UmbracoBackOfficeIdentity.cs +++ b/src/Umbraco.Core/Security/UmbracoBackOfficeIdentity.cs @@ -5,7 +5,6 @@ using System.Security.Claims; namespace Umbraco.Core.Security { - /// /// A custom user identity for the Umbraco backoffice /// diff --git a/src/Umbraco.Core/Services/IMembershipRoleService.cs b/src/Umbraco.Core/Services/IMembershipRoleService.cs index 73479801d2..e0d1e21e7a 100644 --- a/src/Umbraco.Core/Services/IMembershipRoleService.cs +++ b/src/Umbraco.Core/Services/IMembershipRoleService.cs @@ -9,7 +9,6 @@ namespace Umbraco.Core.Services where T : class, IMembershipUser { void AddRole(string roleName); - IEnumerable GetAllRoles(); IEnumerable GetAllRolesTyped(); IEnumerable GetAllRoles(int memberId); IEnumerable GetAllRoles(string username); diff --git a/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.MappingProfiles.cs b/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.MappingProfiles.cs index 692342581e..2973abf271 100644 --- a/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.MappingProfiles.cs +++ b/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.MappingProfiles.cs @@ -3,6 +3,7 @@ using Umbraco.Core.DependencyInjection; using Umbraco.Core.Mapping; using Umbraco.Core.Models.Mapping; using Umbraco.Core.Security; +using Umbraco.Infrastructure.Security; using Umbraco.Web.Models.Mapping; namespace Umbraco.Infrastructure.DependencyInjection diff --git a/src/Umbraco.Infrastructure/Install/InstallSteps/NewInstallStep.cs b/src/Umbraco.Infrastructure/Install/InstallSteps/NewInstallStep.cs index b7699b7d0e..b746011494 100644 --- a/src/Umbraco.Infrastructure/Install/InstallSteps/NewInstallStep.cs +++ b/src/Umbraco.Infrastructure/Install/InstallSteps/NewInstallStep.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Specialized; using System.Net.Http; using System.Text; @@ -11,6 +11,7 @@ using Umbraco.Core.Migrations.Install; using Umbraco.Core.Security; using Umbraco.Core.Services; using Umbraco.Extensions; +using Umbraco.Infrastructure.Security; using Umbraco.Web.Install.Models; namespace Umbraco.Web.Install.InstallSteps diff --git a/src/Umbraco.Infrastructure/Security/BackOfficeClaimsPrincipalFactory.cs b/src/Umbraco.Infrastructure/Security/BackOfficeClaimsPrincipalFactory.cs index 77f707d812..0746e82076 100644 --- a/src/Umbraco.Infrastructure/Security/BackOfficeClaimsPrincipalFactory.cs +++ b/src/Umbraco.Infrastructure/Security/BackOfficeClaimsPrincipalFactory.cs @@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.Options; using Umbraco.Core.Security; -namespace Umbraco.Core.Security +namespace Umbraco.Infrastructure.Security { /// /// A diff --git a/src/Umbraco.Infrastructure/Security/BackOfficeIdentityBuilder.cs b/src/Umbraco.Infrastructure/Security/BackOfficeIdentityBuilder.cs index c9f8d35ada..bf0f61bf35 100644 --- a/src/Umbraco.Infrastructure/Security/BackOfficeIdentityBuilder.cs +++ b/src/Umbraco.Infrastructure/Security/BackOfficeIdentityBuilder.cs @@ -3,7 +3,7 @@ using System.Reflection; using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.DependencyInjection; -namespace Umbraco.Core.Security +namespace Umbraco.Infrastructure.Security { public class BackOfficeIdentityBuilder : IdentityBuilder { diff --git a/src/Umbraco.Infrastructure/Security/BackOfficeIdentityErrorDescriber.cs b/src/Umbraco.Infrastructure/Security/BackOfficeIdentityErrorDescriber.cs index 6d36e489b8..38472c38d7 100644 --- a/src/Umbraco.Infrastructure/Security/BackOfficeIdentityErrorDescriber.cs +++ b/src/Umbraco.Infrastructure/Security/BackOfficeIdentityErrorDescriber.cs @@ -1,6 +1,6 @@ using Microsoft.AspNetCore.Identity; -namespace Umbraco.Core.Security +namespace Umbraco.Infrastructure.Security { /// /// Umbraco back office specific diff --git a/src/Umbraco.Infrastructure/Security/BackOfficeIdentityOptions.cs b/src/Umbraco.Infrastructure/Security/BackOfficeIdentityOptions.cs index 77849c4d0c..f599769938 100644 --- a/src/Umbraco.Infrastructure/Security/BackOfficeIdentityOptions.cs +++ b/src/Umbraco.Infrastructure/Security/BackOfficeIdentityOptions.cs @@ -1,6 +1,6 @@ using Microsoft.AspNetCore.Identity; -namespace Umbraco.Core.Security +namespace Umbraco.Infrastructure.Security { /// /// Identity options specifically for the back office identity implementation diff --git a/src/Umbraco.Infrastructure/Security/BackOfficeIdentityUser.cs b/src/Umbraco.Infrastructure/Security/BackOfficeIdentityUser.cs index e2e8031768..ae9b351b65 100644 --- a/src/Umbraco.Infrastructure/Security/BackOfficeIdentityUser.cs +++ b/src/Umbraco.Infrastructure/Security/BackOfficeIdentityUser.cs @@ -2,12 +2,12 @@ using System; using System.Collections.Generic; using System.Linq; using Microsoft.AspNetCore.Identity; +using Umbraco.Core; using Umbraco.Core.Configuration.Models; -using Umbraco.Core.Models.Entities; using Umbraco.Core.Models.Identity; using Umbraco.Core.Models.Membership; -namespace Umbraco.Core.Security +namespace Umbraco.Infrastructure.Security { /// /// The identity user used for the back office diff --git a/src/Umbraco.Infrastructure/Security/BackOfficeUserStore.cs b/src/Umbraco.Infrastructure/Security/BackOfficeUserStore.cs index 1756e84d76..a7d925e580 100644 --- a/src/Umbraco.Infrastructure/Security/BackOfficeUserStore.cs +++ b/src/Umbraco.Infrastructure/Security/BackOfficeUserStore.cs @@ -15,6 +15,7 @@ using Umbraco.Core.Models.Identity; using Umbraco.Core.Models.Membership; using Umbraco.Core.Scoping; using Umbraco.Core.Services; +using Umbraco.Infrastructure.Security; namespace Umbraco.Core.Security { diff --git a/src/Umbraco.Infrastructure/Security/BackOfficeUserValidator.cs b/src/Umbraco.Infrastructure/Security/BackOfficeUserValidator.cs index 8b2c8932a7..a1953159e9 100644 --- a/src/Umbraco.Infrastructure/Security/BackOfficeUserValidator.cs +++ b/src/Umbraco.Infrastructure/Security/BackOfficeUserValidator.cs @@ -1,6 +1,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Identity; using Umbraco.Core.Security; +using Umbraco.Infrastructure.Security; namespace Umbraco.Core.Security { diff --git a/src/Umbraco.Infrastructure/Security/IBackOfficeUserManager.cs b/src/Umbraco.Infrastructure/Security/IBackOfficeUserManager.cs index cc0a63142b..c65570405f 100644 --- a/src/Umbraco.Infrastructure/Security/IBackOfficeUserManager.cs +++ b/src/Umbraco.Infrastructure/Security/IBackOfficeUserManager.cs @@ -1,7 +1,4 @@ -using Umbraco.Core.Security; -using Umbraco.Infrastructure.Security; - -namespace Umbraco.Core.Security +namespace Umbraco.Infrastructure.Security { /// /// The user manager for the back office diff --git a/src/Umbraco.Infrastructure/Security/IBackOfficeUserPasswordChecker.cs b/src/Umbraco.Infrastructure/Security/IBackOfficeUserPasswordChecker.cs index fdf1f1fcf2..f6f90ef82d 100644 --- a/src/Umbraco.Infrastructure/Security/IBackOfficeUserPasswordChecker.cs +++ b/src/Umbraco.Infrastructure/Security/IBackOfficeUserPasswordChecker.cs @@ -1,6 +1,7 @@ using System.Threading.Tasks; +using Umbraco.Core.Security; -namespace Umbraco.Core.Security +namespace Umbraco.Infrastructure.Security { /// /// Used by the BackOfficeUserManager to check the username/password which allows for developers to more easily diff --git a/src/Umbraco.Infrastructure/Security/IMembersUserManager.cs b/src/Umbraco.Infrastructure/Security/IMembersUserManager.cs index a5b0579cb7..a466ea2aa9 100644 --- a/src/Umbraco.Infrastructure/Security/IMembersUserManager.cs +++ b/src/Umbraco.Infrastructure/Security/IMembersUserManager.cs @@ -1,8 +1,3 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Identity; -using Umbraco.Core.Security; - namespace Umbraco.Infrastructure.Security { /// diff --git a/src/Umbraco.Infrastructure/Security/IUmbracoUserManager.cs b/src/Umbraco.Infrastructure/Security/IUmbracoUserManager.cs index be4ffdf2e2..fa3d7a691a 100644 --- a/src/Umbraco.Infrastructure/Security/IUmbracoUserManager.cs +++ b/src/Umbraco.Infrastructure/Security/IUmbracoUserManager.cs @@ -244,11 +244,11 @@ namespace Umbraco.Infrastructure.Security string GeneratePassword(); /// - /// Generates a hashed password for a null user based on the default password hasher + /// Hashes a password for a null user based on the default password hasher /// /// The password to hash /// The hashed password - string GeneratePassword(string password); + string HashPassword(string password); /// /// Used to validate the password without an identity user diff --git a/src/Umbraco.Infrastructure/Security/IUserSessionStore.cs b/src/Umbraco.Infrastructure/Security/IUserSessionStore.cs index c68d1f13f9..bfdf296156 100644 --- a/src/Umbraco.Infrastructure/Security/IUserSessionStore.cs +++ b/src/Umbraco.Infrastructure/Security/IUserSessionStore.cs @@ -1,6 +1,6 @@ using System.Threading.Tasks; -namespace Umbraco.Core.Security +namespace Umbraco.Infrastructure.Security { /// /// An IUserStore interface part to implement if the store supports validating user session Ids diff --git a/src/Umbraco.Infrastructure/Security/IdentityExtensions.cs b/src/Umbraco.Infrastructure/Security/IdentityExtensions.cs index 95a63c6001..911baf2c33 100644 --- a/src/Umbraco.Infrastructure/Security/IdentityExtensions.cs +++ b/src/Umbraco.Infrastructure/Security/IdentityExtensions.cs @@ -1,9 +1,9 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using Microsoft.AspNetCore.Identity; -namespace Umbraco.Extensions +namespace Umbraco.Infrastructure.Security { public static class IdentityExtensions { diff --git a/src/Umbraco.Infrastructure/Security/IdentityMapDefinition.cs b/src/Umbraco.Infrastructure/Security/IdentityMapDefinition.cs index 00239b21eb..88dd6eaeb7 100644 --- a/src/Umbraco.Infrastructure/Security/IdentityMapDefinition.cs +++ b/src/Umbraco.Infrastructure/Security/IdentityMapDefinition.cs @@ -1,14 +1,13 @@ using System; using Microsoft.Extensions.Options; -using Umbraco.Core.Configuration; +using Umbraco.Core; using Umbraco.Core.Configuration.Models; using Umbraco.Core.Mapping; using Umbraco.Core.Models; using Umbraco.Core.Models.Membership; using Umbraco.Core.Services; -using Umbraco.Infrastructure.Security; -namespace Umbraco.Core.Security +namespace Umbraco.Infrastructure.Security { public class IdentityMapDefinition : IMapDefinition { diff --git a/src/Umbraco.Infrastructure/Security/MembersIdentityBuilder.cs b/src/Umbraco.Infrastructure/Security/MembersIdentityBuilder.cs index 553cca6a17..dde340f563 100644 --- a/src/Umbraco.Infrastructure/Security/MembersIdentityBuilder.cs +++ b/src/Umbraco.Infrastructure/Security/MembersIdentityBuilder.cs @@ -7,7 +7,6 @@ namespace Umbraco.Infrastructure.Security { public class MembersIdentityBuilder : IdentityBuilder { - public MembersIdentityBuilder(IServiceCollection services) : base(typeof(MembersIdentityUser), services) { } diff --git a/src/Umbraco.Infrastructure/Security/MembersUserStore.cs b/src/Umbraco.Infrastructure/Security/MembersUserStore.cs index aa28ee5d25..c79e18c168 100644 --- a/src/Umbraco.Infrastructure/Security/MembersUserStore.cs +++ b/src/Umbraco.Infrastructure/Security/MembersUserStore.cs @@ -307,8 +307,7 @@ namespace Umbraco.Infrastructure.Security return Task.FromResult((IList)user.Logins.Select(l => new UserLoginInfo(l.LoginProvider, l.ProviderKey, l.LoginProvider)).ToList()); } - - + /// protected override async Task> FindUserLoginAsync(string userId, string loginProvider, string providerKey, CancellationToken cancellationToken) { diff --git a/src/Umbraco.Infrastructure/Security/BackOfficeLookupNormalizer.cs b/src/Umbraco.Infrastructure/Security/NoOpLookupNormalizer.cs similarity index 76% rename from src/Umbraco.Infrastructure/Security/BackOfficeLookupNormalizer.cs rename to src/Umbraco.Infrastructure/Security/NoOpLookupNormalizer.cs index 957e36d1d0..c81a46e726 100644 --- a/src/Umbraco.Infrastructure/Security/BackOfficeLookupNormalizer.cs +++ b/src/Umbraco.Infrastructure/Security/NoOpLookupNormalizer.cs @@ -1,12 +1,12 @@ using Microsoft.AspNetCore.Identity; -namespace Umbraco.Core.Security +namespace Umbraco.Infrastructure.Security { /// /// No-op lookup normalizer to maintain compatibility with ASP.NET Identity 2 /// - public class BackOfficeLookupNormalizer : ILookupNormalizer + public class NoOpLookupNormalizer : ILookupNormalizer { // TODO: Do we need this? diff --git a/src/Umbraco.Infrastructure/Security/SignOutAuditEventArgs.cs b/src/Umbraco.Infrastructure/Security/SignOutAuditEventArgs.cs index 626932640c..dfdf3bff7d 100644 --- a/src/Umbraco.Infrastructure/Security/SignOutAuditEventArgs.cs +++ b/src/Umbraco.Infrastructure/Security/SignOutAuditEventArgs.cs @@ -1,8 +1,8 @@ +using Umbraco.Core; using Umbraco.Core.Security; -namespace Umbraco.Core.Security +namespace Umbraco.Infrastructure.Security { - /// /// Event args used when signing out /// diff --git a/src/Umbraco.Infrastructure/Security/UmbracoUserManager.cs b/src/Umbraco.Infrastructure/Security/UmbracoUserManager.cs index 2000e108b7..cac0d1ea78 100644 --- a/src/Umbraco.Infrastructure/Security/UmbracoUserManager.cs +++ b/src/Umbraco.Infrastructure/Security/UmbracoUserManager.cs @@ -8,11 +8,11 @@ using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Umbraco.Core.Configuration; using Umbraco.Core.Models.Identity; +using Umbraco.Core.Security; using Umbraco.Net; -namespace Umbraco.Core.Security +namespace Umbraco.Infrastructure.Security { - /// /// Abstract class for Umbraco User Managers for back office users or front-end members /// @@ -34,12 +34,11 @@ namespace Umbraco.Core.Security IPasswordHasher passwordHasher, IEnumerable> userValidators, IEnumerable> passwordValidators, - ILookupNormalizer keyNormalizer, IdentityErrorDescriber errors, IServiceProvider services, ILogger> logger, IOptions passwordConfiguration) - : base(store, optionsAccessor, passwordHasher, userValidators, passwordValidators, keyNormalizer, errors, services, logger) + : base(store, optionsAccessor, passwordHasher, userValidators, passwordValidators, new NoOpLookupNormalizer(), errors, services, logger) { IpResolver = ipResolver ?? throw new ArgumentNullException(nameof(ipResolver)); PasswordConfiguration = passwordConfiguration.Value ?? throw new ArgumentNullException(nameof(passwordConfiguration)); @@ -74,8 +73,8 @@ namespace Umbraco.Core.Security /// Used to validate a user's session /// /// The user id - /// The sesion id - /// True if the sesion is valid, else false + /// The session id + /// True if the session is valid, else false public virtual async Task ValidateSessionIdAsync(string userId, string sessionId) { var userSessionStore = Store as IUserSessionStore; @@ -118,7 +117,7 @@ namespace Umbraco.Core.Security /// /// The password to hash /// The hashed password - public string GeneratePassword(string password) + public string HashPassword(string password) { IPasswordHasher passwordHasher = GetDefaultPasswordHasher(PasswordConfiguration); diff --git a/src/Umbraco.Infrastructure/Security/UserInviteEventArgs.cs b/src/Umbraco.Infrastructure/Security/UserInviteEventArgs.cs index 80b05497a8..ee2930a71b 100644 --- a/src/Umbraco.Infrastructure/Security/UserInviteEventArgs.cs +++ b/src/Umbraco.Infrastructure/Security/UserInviteEventArgs.cs @@ -2,7 +2,7 @@ using Umbraco.Core.Models.Membership; using Umbraco.Core.Security; using Umbraco.Web.Models.ContentEditing; -namespace Umbraco.Core.Security +namespace Umbraco.Infrastructure.Security { public class UserInviteEventArgs : IdentityAuditEventArgs { diff --git a/src/Umbraco.Infrastructure/Services/Implement/MemberService.cs b/src/Umbraco.Infrastructure/Services/Implement/MemberService.cs index b3cf2d5ee3..52f2fe0836 100644 --- a/src/Umbraco.Infrastructure/Services/Implement/MemberService.cs +++ b/src/Umbraco.Infrastructure/Services/Implement/MemberService.cs @@ -928,16 +928,7 @@ namespace Umbraco.Core.Services.Implement scope.Complete(); } } - - public IEnumerable GetAllRoles() - { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) - { - scope.ReadLock(Constants.Locks.MemberTree); - return _memberGroupRepository.GetMany().Select(x => x.Name).Distinct(); - } - } - + /// /// Returns a strongly typed list of all member groups /// diff --git a/src/Umbraco.Tests.Integration/TestServerTest/TestAuthHandler.cs b/src/Umbraco.Tests.Integration/TestServerTest/TestAuthHandler.cs index ab5821c81c..2f567418e6 100644 --- a/src/Umbraco.Tests.Integration/TestServerTest/TestAuthHandler.cs +++ b/src/Umbraco.Tests.Integration/TestServerTest/TestAuthHandler.cs @@ -1,4 +1,4 @@ -using System.Text.Encodings.Web; +using System.Text.Encodings.Web; using System.Threading.Tasks; using Microsoft.AspNetCore.Authentication; using Microsoft.Extensions.Logging; @@ -8,6 +8,7 @@ using Umbraco.Core.Mapping; using Umbraco.Core.Models.Membership; using Umbraco.Core.Security; using Umbraco.Core.Services; +using Umbraco.Infrastructure.Security; using Umbraco.Web.Common.Security; namespace Umbraco.Tests.Integration.TestServerTest diff --git a/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/MemberServiceTests.cs b/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/MemberServiceTests.cs index 0e747c5dc5..a286b0ec42 100644 --- a/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/MemberServiceTests.cs +++ b/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/MemberServiceTests.cs @@ -179,7 +179,7 @@ namespace Umbraco.Tests.Integration.Umbraco.Infrastructure.Services { MemberService.AddRole("MyTestRole"); - var found = MemberService.GetAllRoles(); + IEnumerable found = MemberService.GetAllRolesTyped(); Assert.AreEqual(1, found.Count()); Assert.AreEqual("MyTestRole", found.Single()); @@ -191,7 +191,7 @@ namespace Umbraco.Tests.Integration.Umbraco.Infrastructure.Services MemberService.AddRole("MyTestRole"); MemberService.AddRole("MyTestRole"); - var found = MemberService.GetAllRoles(); + IEnumerable found = MemberService.GetAllRolesTyped(); Assert.AreEqual(1, found.Count()); Assert.AreEqual("MyTestRole", found.Single()); @@ -204,7 +204,7 @@ namespace Umbraco.Tests.Integration.Umbraco.Infrastructure.Services MemberService.AddRole("MyTestRole2"); MemberService.AddRole("MyTestRole3"); - var found = MemberService.GetAllRoles(); + IEnumerable found = MemberService.GetAllRolesTyped(); Assert.AreEqual(3, found.Count()); } @@ -298,7 +298,7 @@ namespace Umbraco.Tests.Integration.Umbraco.Infrastructure.Services MemberService.DeleteRole("MyTestRole1", false); - var memberRoles = MemberService.GetAllRoles(); + IEnumerable memberRoles = MemberService.GetAllRolesTyped(); Assert.AreEqual(0, memberRoles.Count()); } diff --git a/src/Umbraco.Tests.Integration/Umbraco.Web.BackOffice/UmbracoBackOfficeServiceCollectionExtensionsTests.cs b/src/Umbraco.Tests.Integration/Umbraco.Web.BackOffice/UmbracoBackOfficeServiceCollectionExtensionsTests.cs index 37863da472..65a90b9ab7 100644 --- a/src/Umbraco.Tests.Integration/Umbraco.Web.BackOffice/UmbracoBackOfficeServiceCollectionExtensionsTests.cs +++ b/src/Umbraco.Tests.Integration/Umbraco.Web.BackOffice/UmbracoBackOfficeServiceCollectionExtensionsTests.cs @@ -3,6 +3,7 @@ using Microsoft.Extensions.DependencyInjection; using NUnit.Framework; using Umbraco.Core.DependencyInjection; using Umbraco.Core.Security; +using Umbraco.Infrastructure.Security; using Umbraco.Tests.Integration.Testing; using Umbraco.Web.BackOffice.DependencyInjection; diff --git a/src/Umbraco.Tests.UnitTests/AutoFixture/AutoMoqDataAttribute.cs b/src/Umbraco.Tests.UnitTests/AutoFixture/AutoMoqDataAttribute.cs index b0eac41478..8097cbed92 100644 --- a/src/Umbraco.Tests.UnitTests/AutoFixture/AutoMoqDataAttribute.cs +++ b/src/Umbraco.Tests.UnitTests/AutoFixture/AutoMoqDataAttribute.cs @@ -15,6 +15,7 @@ using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; using Umbraco.Core.Security; +using Umbraco.Infrastructure.Security; using Umbraco.Web.BackOffice.Controllers; using Umbraco.Web.BackOffice.Routing; using Umbraco.Web.Common.Install; diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Core/BackOffice/IdentityExtensionsTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/BackOffice/IdentityExtensionsTests.cs index 3b2d0391e2..c758272bf4 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Core/BackOffice/IdentityExtensionsTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/BackOffice/IdentityExtensionsTests.cs @@ -5,7 +5,7 @@ using System; using System.Collections.Generic; using Microsoft.AspNetCore.Identity; using NUnit.Framework; -using Umbraco.Extensions; +using Umbraco.Infrastructure.Security; namespace Umbraco.Tests.UnitTests.Umbraco.Core.BackOffice { diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Core/BackOffice/BackOfficeClaimsPrincipalFactoryTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/BackOffice/BackOfficeClaimsPrincipalFactoryTests.cs similarity index 98% rename from src/Umbraco.Tests.UnitTests/Umbraco.Core/BackOffice/BackOfficeClaimsPrincipalFactoryTests.cs rename to src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/BackOffice/BackOfficeClaimsPrincipalFactoryTests.cs index e681fc6841..c8aa619226 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Core/BackOffice/BackOfficeClaimsPrincipalFactoryTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/BackOffice/BackOfficeClaimsPrincipalFactoryTests.cs @@ -14,8 +14,9 @@ using Umbraco.Core.Configuration.Models; using Umbraco.Core.Models.Membership; using Umbraco.Core.Security; using Umbraco.Extensions; +using Umbraco.Infrastructure.Security; -namespace Umbraco.Tests.UnitTests.Umbraco.Core.BackOffice +namespace Umbraco.Tests.UnitTests.Umbraco.Infrastructure.BackOffice { [TestFixture] public class BackOfficeClaimsPrincipalFactoryTests diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/BackOffice/BackOfficeLookupNormalizerTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/BackOffice/BackOfficeLookupNormalizerTests.cs deleted file mode 100644 index 9ce3a8a3c3..0000000000 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/BackOffice/BackOfficeLookupNormalizerTests.cs +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (c) Umbraco. -// See LICENSE for more details. - -using System; -using NUnit.Framework; -using Umbraco.Core.Security; - -namespace Umbraco.Tests.UnitTests.Umbraco.Web.Backoffice -{ - public class BackOfficeLookupNormalizerTests - { - [Test] - [TestCase(null)] - [TestCase("")] - [TestCase(" ")] - public void NormalizeName_When_Name_Null_Or_Whitespace_Expect_Same_Returned(string name) - { - var sut = new BackOfficeLookupNormalizer(); - - var normalizedName = sut.NormalizeName(name); - - Assert.AreEqual(name, normalizedName); - } - - [Test] - public void NormalizeName_Expect_Input_Returned() - { - var name = Guid.NewGuid().ToString(); - var sut = new BackOfficeLookupNormalizer(); - - var normalizedName = sut.NormalizeName(name); - - Assert.AreEqual(name, normalizedName); - } - - [Test] - [TestCase(null)] - [TestCase("")] - [TestCase(" ")] - public void NormalizeEmail_When_Name_Null_Or_Whitespace_Expect_Same_Returned(string email) - { - var sut = new BackOfficeLookupNormalizer(); - - var normalizedEmail = sut.NormalizeEmail(email); - - Assert.AreEqual(email, normalizedEmail); - } - - [Test] - public void NormalizeEmail_Expect_Input_Returned() - { - var email = $"{Guid.NewGuid()}@umbraco"; - var sut = new BackOfficeLookupNormalizer(); - - var normalizedEmail = sut.NormalizeEmail(email); - - Assert.AreEqual(email, normalizedEmail); - } - } -} diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Security/MemberIdentityUserManagerTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Security/MemberIdentityUserManagerTests.cs index b06b9d1a93..438f6d35bc 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Security/MemberIdentityUserManagerTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Security/MemberIdentityUserManagerTests.cs @@ -69,7 +69,6 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Infrastructure.Security _mockPasswordHasher.Object, userValidators, pwdValidators, - new BackOfficeLookupNormalizer(), new BackOfficeIdentityErrorDescriber(), _mockServiceProviders.Object, new Mock().Object, diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Core/BackOffice/NopLookupNormalizerTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Security/NoOpLookupNormalizerTests.cs similarity index 78% rename from src/Umbraco.Tests.UnitTests/Umbraco.Core/BackOffice/NopLookupNormalizerTests.cs rename to src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Security/NoOpLookupNormalizerTests.cs index f4ea348892..86cb339625 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Core/BackOffice/NopLookupNormalizerTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Security/NoOpLookupNormalizerTests.cs @@ -3,19 +3,17 @@ using System; using NUnit.Framework; -using Umbraco.Core.Security; +using Umbraco.Infrastructure.Security; -namespace Umbraco.Tests.UnitTests.Umbraco.Core.BackOffice +namespace Umbraco.Tests.UnitTests.Umbraco.Infrastructure.Security { - public class NopLookupNormalizerTests + public class NoOpLookupNormalizerTests { [Test] - [TestCase(null)] - [TestCase("")] - [TestCase(" ")] - public void NormalizeName_When_Name_Null_Or_Whitespace_Expect_Same_Returned(string name) + public void NormalizeName_Expect_Input_Returned() { - var sut = new BackOfficeLookupNormalizer(); + var name = Guid.NewGuid().ToString(); + var sut = new NoOpLookupNormalizer(); var normalizedName = sut.NormalizeName(name); @@ -23,10 +21,23 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Core.BackOffice } [Test] - public void NormalizeName_Expect_Input_Returned() + public void NormalizeEmail_Expect_Input_Returned() { - var name = Guid.NewGuid().ToString(); - var sut = new BackOfficeLookupNormalizer(); + var email = $"{Guid.NewGuid()}@umbraco"; + var sut = new NoOpLookupNormalizer(); + + var normalizedEmail = sut.NormalizeEmail(email); + + Assert.AreEqual(email, normalizedEmail); + } + + [Test] + [TestCase(null)] + [TestCase("")] + [TestCase(" ")] + public void NormalizeName_When_Name_Null_Or_Whitespace_Expect_Same_Returned(string name) + { + var sut = new NoOpLookupNormalizer(); var normalizedName = sut.NormalizeName(name); @@ -39,18 +50,7 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Core.BackOffice [TestCase(" ")] public void NormalizeEmail_When_Name_Null_Or_Whitespace_Expect_Same_Returned(string email) { - var sut = new BackOfficeLookupNormalizer(); - - var normalizedEmail = sut.NormalizeEmail(email); - - Assert.AreEqual(email, normalizedEmail); - } - - [Test] - public void NormalizeEmail_Expect_Input_Returned() - { - var email = $"{Guid.NewGuid()}@umbraco"; - var sut = new BackOfficeLookupNormalizer(); + var sut = new NoOpLookupNormalizer(); var normalizedEmail = sut.NormalizeEmail(email); diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/MemberControllerUnitTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/MemberControllerUnitTests.cs index 1beab6257c..0537c73ea7 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/MemberControllerUnitTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/MemberControllerUnitTests.cs @@ -140,7 +140,7 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Web.BackOffice.Controllers string password = "fakepassword9aw89rnyco3938cyr^%&*()i8Y"; Mock.Get(umbracoMembersUserManager) - .Setup(x => x.GeneratePassword(It.IsAny())) + .Setup(x => x.HashPassword(It.IsAny())) .Returns(password); Mock.Get(umbracoMembersUserManager) .Setup(x => x.UpdateAsync(It.IsAny())) diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/UsersControllerTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/UsersControllerTests.cs index d8e5a04c59..ac835779a7 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/UsersControllerTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/UsersControllerTests.cs @@ -5,6 +5,7 @@ using AutoFixture.NUnit3; using Moq; using NUnit.Framework; using Umbraco.Core.Security; +using Umbraco.Infrastructure.Security; using Umbraco.Tests.UnitTests.AutoFixture; using Umbraco.Web.BackOffice.Controllers; using Umbraco.Web.Common.Exceptions; diff --git a/src/Umbraco.Web.BackOffice/Controllers/AuthenticationController.cs b/src/Umbraco.Web.BackOffice/Controllers/AuthenticationController.cs index 502ffbcba2..77cd022d99 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/AuthenticationController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/AuthenticationController.cs @@ -21,6 +21,7 @@ using Umbraco.Core.Models.Security; using Umbraco.Core.Security; using Umbraco.Core.Services; using Umbraco.Extensions; +using Umbraco.Infrastructure.Security; using Umbraco.Net; using Umbraco.Web.BackOffice.Filters; using Umbraco.Web.BackOffice.Security; diff --git a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs index 34d3a96ca3..7939b0f306 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs @@ -24,6 +24,7 @@ using Umbraco.Core.Serialization; using Umbraco.Core.Services; using Umbraco.Core.WebAssets; using Umbraco.Extensions; +using Umbraco.Infrastructure.Security; using Umbraco.Web.BackOffice.ActionResults; using Umbraco.Web.BackOffice.Filters; using Umbraco.Web.BackOffice.Security; diff --git a/src/Umbraco.Web.BackOffice/Controllers/CurrentUserController.cs b/src/Umbraco.Web.BackOffice/Controllers/CurrentUserController.cs index d156551c26..a651a22075 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/CurrentUserController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/CurrentUserController.cs @@ -20,6 +20,7 @@ using Umbraco.Core.Security; using Umbraco.Core.Services; using Umbraco.Core.Strings; using Umbraco.Extensions; +using Umbraco.Infrastructure.Security; using Umbraco.Web.BackOffice.Filters; using Umbraco.Web.BackOffice.Security; using Umbraco.Web.Common.Attributes; diff --git a/src/Umbraco.Web.BackOffice/Controllers/MemberController.cs b/src/Umbraco.Web.BackOffice/Controllers/MemberController.cs index 957863704b..5efea5a1ca 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/MemberController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/MemberController.cs @@ -435,7 +435,7 @@ namespace Umbraco.Web.BackOffice.Controllers throw HttpResponseException.CreateNotificationValidationErrorResponse(validatePassword.Errors.ToErrorMessage()); } - string newPassword = _memberManager.GeneratePassword(contentItem.Password.NewPassword); + string newPassword = _memberManager.HashPassword(contentItem.Password.NewPassword); identityMember.PasswordHash = newPassword; } diff --git a/src/Umbraco.Web.BackOffice/Controllers/UsersController.cs b/src/Umbraco.Web.BackOffice/Controllers/UsersController.cs index fca8c49004..3f0bdcfb70 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/UsersController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/UsersController.cs @@ -28,6 +28,7 @@ using Umbraco.Core.Security; using Umbraco.Core.Services; using Umbraco.Core.Strings; using Umbraco.Extensions; +using Umbraco.Infrastructure.Security; using Umbraco.Web.BackOffice.ActionResults; using Umbraco.Web.BackOffice.Filters; using Umbraco.Web.BackOffice.ModelBinders; diff --git a/src/Umbraco.Web.BackOffice/DependencyInjection/ServiceCollectionExtensions.cs b/src/Umbraco.Web.BackOffice/DependencyInjection/ServiceCollectionExtensions.cs index 7a40c03f9f..bca0c67ed7 100644 --- a/src/Umbraco.Web.BackOffice/DependencyInjection/ServiceCollectionExtensions.cs +++ b/src/Umbraco.Web.BackOffice/DependencyInjection/ServiceCollectionExtensions.cs @@ -67,7 +67,7 @@ namespace Umbraco.Web.BackOffice.DependencyInjection services.TryAddScoped, UserClaimsPrincipalFactory>(); // CUSTOM: - services.TryAddScoped(); + services.TryAddScoped(); services.TryAddScoped(); services.TryAddScoped(); services.TryAddSingleton(); @@ -79,7 +79,7 @@ namespace Umbraco.Web.BackOffice.DependencyInjection * To validate the container the following registrations are required (dependencies of UserManager) * Perhaps we shouldn't be registering UserManager at all and only registering/depending the UmbracoBackOffice prefixed types. */ - services.TryAddScoped(); + services.TryAddScoped(); services.TryAddScoped(); return new BackOfficeIdentityBuilder(services); diff --git a/src/Umbraco.Web.BackOffice/Filters/CheckIfUserTicketDataIsStaleAttribute.cs b/src/Umbraco.Web.BackOffice/Filters/CheckIfUserTicketDataIsStaleAttribute.cs index 6e14468a2a..75fd435741 100644 --- a/src/Umbraco.Web.BackOffice/Filters/CheckIfUserTicketDataIsStaleAttribute.cs +++ b/src/Umbraco.Web.BackOffice/Filters/CheckIfUserTicketDataIsStaleAttribute.cs @@ -16,6 +16,7 @@ using Umbraco.Core.Models.Membership; using Umbraco.Core.Security; using Umbraco.Core.Services; using Umbraco.Extensions; +using Umbraco.Infrastructure.Security; using Umbraco.Web.BackOffice.Security; using Umbraco.Web.Common.Security; diff --git a/src/Umbraco.Web.BackOffice/Security/BackOfficePasswordHasher.cs b/src/Umbraco.Web.BackOffice/Security/BackOfficePasswordHasher.cs index 65f1a7f5bc..7c07699420 100644 --- a/src/Umbraco.Web.BackOffice/Security/BackOfficePasswordHasher.cs +++ b/src/Umbraco.Web.BackOffice/Security/BackOfficePasswordHasher.cs @@ -1,9 +1,10 @@ -using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Identity; using Umbraco.Core.Security; using Umbraco.Core; using Umbraco.Core.Models.Membership; using Microsoft.Extensions.Options; using Umbraco.Core.Serialization; +using Umbraco.Infrastructure.Security; namespace Umbraco.Web.BackOffice.Security { diff --git a/src/Umbraco.Web.BackOffice/Security/BackOfficeSecurityStampValidator.cs b/src/Umbraco.Web.BackOffice/Security/BackOfficeSecurityStampValidator.cs index abd0af1353..ab22e0ba06 100644 --- a/src/Umbraco.Web.BackOffice/Security/BackOfficeSecurityStampValidator.cs +++ b/src/Umbraco.Web.BackOffice/Security/BackOfficeSecurityStampValidator.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Security.Claims; using System.Threading.Tasks; using Microsoft.AspNetCore.Authentication; @@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Umbraco.Core.Security; +using Umbraco.Infrastructure.Security; using Umbraco.Web.Common.Security; namespace Umbraco.Web.BackOffice.Security diff --git a/src/Umbraco.Web.BackOffice/Security/BackOfficeSessionIdValidator.cs b/src/Umbraco.Web.BackOffice/Security/BackOfficeSessionIdValidator.cs index 1ccb94e988..058ffd6585 100644 --- a/src/Umbraco.Web.BackOffice/Security/BackOfficeSessionIdValidator.cs +++ b/src/Umbraco.Web.BackOffice/Security/BackOfficeSessionIdValidator.cs @@ -11,6 +11,7 @@ using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; using Umbraco.Core.Security; using Umbraco.Extensions; +using Umbraco.Infrastructure.Security; namespace Umbraco.Web.BackOffice.Security { diff --git a/src/Umbraco.Web.BackOffice/Security/BackOfficeSignInManager.cs b/src/Umbraco.Web.BackOffice/Security/BackOfficeSignInManager.cs index 6d1c348d7f..3cbd562ef2 100644 --- a/src/Umbraco.Web.BackOffice/Security/BackOfficeSignInManager.cs +++ b/src/Umbraco.Web.BackOffice/Security/BackOfficeSignInManager.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Authentication; +using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.Logging; @@ -13,6 +13,7 @@ using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.Models; using Umbraco.Core.Security; using Umbraco.Extensions; +using Umbraco.Infrastructure.Security; using Umbraco.Net; using Umbraco.Web.BackOffice.Security; diff --git a/src/Umbraco.Web.BackOffice/Security/BackOfficeUserManagerAuditer.cs b/src/Umbraco.Web.BackOffice/Security/BackOfficeUserManagerAuditer.cs index 81be953d22..5ba7a0fd56 100644 --- a/src/Umbraco.Web.BackOffice/Security/BackOfficeUserManagerAuditer.cs +++ b/src/Umbraco.Web.BackOffice/Security/BackOfficeUserManagerAuditer.cs @@ -6,6 +6,7 @@ using Umbraco.Core.Configuration.Models; using Umbraco.Core.Models.Membership; using Umbraco.Core.Security; using Umbraco.Core.Services; +using Umbraco.Infrastructure.Security; namespace Umbraco.Web.Common.Security { diff --git a/src/Umbraco.Web.BackOffice/Security/ConfigureBackOfficeIdentityOptions.cs b/src/Umbraco.Web.BackOffice/Security/ConfigureBackOfficeIdentityOptions.cs index 989c852350..a9d4575c4d 100644 --- a/src/Umbraco.Web.BackOffice/Security/ConfigureBackOfficeIdentityOptions.cs +++ b/src/Umbraco.Web.BackOffice/Security/ConfigureBackOfficeIdentityOptions.cs @@ -6,6 +6,7 @@ using Umbraco.Core; using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.Models; using Umbraco.Core.Security; +using Umbraco.Infrastructure.Security; namespace Umbraco.Web.BackOffice.Security { diff --git a/src/Umbraco.Web.BackOffice/Security/ExternalSignInAutoLinkOptions.cs b/src/Umbraco.Web.BackOffice/Security/ExternalSignInAutoLinkOptions.cs index 8636d9e62d..149f5efb56 100644 --- a/src/Umbraco.Web.BackOffice/Security/ExternalSignInAutoLinkOptions.cs +++ b/src/Umbraco.Web.BackOffice/Security/ExternalSignInAutoLinkOptions.cs @@ -1,8 +1,9 @@ -using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Identity; using System; using System.Runtime.Serialization; using Umbraco.Core.Configuration.Models; using Umbraco.Core.Security; +using Umbraco.Infrastructure.Security; using SecurityConstants = Umbraco.Core.Constants.Security; namespace Umbraco.Web.BackOffice.Security diff --git a/src/Umbraco.Web.BackOffice/Security/IBackOfficeSignInManager.cs b/src/Umbraco.Web.BackOffice/Security/IBackOfficeSignInManager.cs index 669ca21239..1065c117a1 100644 --- a/src/Umbraco.Web.BackOffice/Security/IBackOfficeSignInManager.cs +++ b/src/Umbraco.Web.BackOffice/Security/IBackOfficeSignInManager.cs @@ -1,9 +1,10 @@ -using Microsoft.AspNetCore.Authentication; +using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Identity; using System.Collections.Generic; using System.Security.Claims; using System.Threading.Tasks; using Umbraco.Core.Security; +using Umbraco.Infrastructure.Security; namespace Umbraco.Web.Common.Security { diff --git a/src/Umbraco.Web.BackOffice/Security/PasswordChanger.cs b/src/Umbraco.Web.BackOffice/Security/PasswordChanger.cs index 180f433fab..6144e7b63f 100644 --- a/src/Umbraco.Web.BackOffice/Security/PasswordChanger.cs +++ b/src/Umbraco.Web.BackOffice/Security/PasswordChanger.cs @@ -6,6 +6,7 @@ using Umbraco.Core; using Umbraco.Core.Models; using Umbraco.Core.Security; using Umbraco.Extensions; +using Umbraco.Infrastructure.Security; using Umbraco.Web.Models; using IUser = Umbraco.Core.Models.Membership.IUser; diff --git a/src/Umbraco.Web.Common/Middleware/BootFailedMiddleware.cs b/src/Umbraco.Web.Common/Middleware/BootFailedMiddleware.cs index 685312778d..1dd3b65975 100644 --- a/src/Umbraco.Web.Common/Middleware/BootFailedMiddleware.cs +++ b/src/Umbraco.Web.Common/Middleware/BootFailedMiddleware.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Umbraco.Core; diff --git a/src/Umbraco.Web.Common/Security/BackOfficeUserManager.cs b/src/Umbraco.Web.Common/Security/BackOfficeUserManager.cs index 081ca6b581..ca1a3f561d 100644 --- a/src/Umbraco.Web.Common/Security/BackOfficeUserManager.cs +++ b/src/Umbraco.Web.Common/Security/BackOfficeUserManager.cs @@ -11,6 +11,7 @@ using Umbraco.Core.Configuration.Models; using Umbraco.Core.Models.Membership; using Umbraco.Core.Security; using Umbraco.Extensions; +using Umbraco.Infrastructure.Security; using Umbraco.Net; using Umbraco.Web.Models.ContentEditing; @@ -28,13 +29,12 @@ namespace Umbraco.Web.Common.Security IPasswordHasher passwordHasher, IEnumerable> userValidators, IEnumerable> passwordValidators, - BackOfficeLookupNormalizer keyNormalizer, BackOfficeIdentityErrorDescriber errors, IServiceProvider services, IHttpContextAccessor httpContextAccessor, ILogger> logger, IOptions passwordConfiguration) - : base(ipResolver, store, optionsAccessor, passwordHasher, userValidators, passwordValidators, keyNormalizer, errors, services, logger, passwordConfiguration) + : base(ipResolver, store, optionsAccessor, passwordHasher, userValidators, passwordValidators, errors, services, logger, passwordConfiguration) { _httpContextAccessor = httpContextAccessor; } diff --git a/src/Umbraco.Web.Common/Security/MembersUserManager.cs b/src/Umbraco.Web.Common/Security/MembersUserManager.cs index 86ea7b1972..1604c056b0 100644 --- a/src/Umbraco.Web.Common/Security/MembersUserManager.cs +++ b/src/Umbraco.Web.Common/Security/MembersUserManager.cs @@ -1,8 +1,6 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Security.Principal; -using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.Logging; @@ -30,17 +28,16 @@ namespace Umbraco.Web.Common.Security IPasswordHasher passwordHasher, IEnumerable> userValidators, IEnumerable> passwordValidators, - //TODO: do we need members versions of this? - BackOfficeLookupNormalizer keyNormalizer, BackOfficeIdentityErrorDescriber errors, IServiceProvider services, IHttpContextAccessor httpContextAccessor, ILogger> logger, IOptions passwordConfiguration) - : base(ipResolver, store, optionsAccessor, passwordHasher, userValidators, passwordValidators, keyNormalizer, errors, services, logger, passwordConfiguration) + : base(ipResolver, store, optionsAccessor, passwordHasher, userValidators, passwordValidators, errors, services, logger, passwordConfiguration) { _httpContextAccessor = httpContextAccessor; } + private string GetCurrentUserId(IPrincipal currentUser) { UmbracoBackOfficeIdentity umbIdentity = currentUser?.GetUmbracoIdentity(); @@ -55,82 +52,15 @@ namespace Umbraco.Web.Common.Security return new IdentityAuditEventArgs(auditEvent, ip, currentUserId, string.Empty, affectedUserId, affectedUsername); } + //TODO: have removed all other member audit events - can revisit if we need member auditing on a user level in future + public void RaiseForgotPasswordRequestedEvent(IPrincipal currentUser, string userId) => throw new NotImplementedException(); - // TODO: As per backoffice, review where these are raised and see if they can be simplified and either done in the this usermanager or the signin manager, - // lastly we'll resort to the authentication controller but we should try to remove all instances of that occuring - public void RaiseAccountLockedEvent(IPrincipal currentUser, string userId) => OnAccountLocked(CreateArgs(AuditEvent.AccountLocked, currentUser, userId, string.Empty)); + public void RaiseForgotPasswordChangedSuccessEvent(IPrincipal currentUser, string userId) => throw new NotImplementedException(); - public void RaiseAccountUnlockedEvent(IPrincipal currentUser, string userId) => OnAccountUnlocked(CreateArgs(AuditEvent.AccountUnlocked, currentUser, userId, string.Empty)); + public SignOutAuditEventArgs RaiseLogoutSuccessEvent(IPrincipal currentUser, string userId) => throw new NotImplementedException(); - public void RaiseForgotPasswordRequestedEvent(IPrincipal currentUser, string userId) => OnForgotPasswordRequested(CreateArgs(AuditEvent.ForgotPasswordRequested, currentUser, userId, string.Empty)); + public UserInviteEventArgs RaiseSendingUserInvite(IPrincipal currentUser, UserInvite invite, IUser createdUser) => throw new NotImplementedException(); - public void RaiseForgotPasswordChangedSuccessEvent(IPrincipal currentUser, string userId) => OnForgotPasswordChangedSuccess(CreateArgs(AuditEvent.ForgotPasswordChangedSuccess, currentUser, userId, string.Empty)); - - public void RaiseLoginFailedEvent(IPrincipal currentUser, string userId) => OnLoginFailed(CreateArgs(AuditEvent.LoginFailed, currentUser, userId, string.Empty)); - - public void RaiseLoginRequiresVerificationEvent(IPrincipal currentUser, string userId) => OnLoginRequiresVerification(CreateArgs(AuditEvent.LoginRequiresVerification, currentUser, userId, string.Empty)); - - public void RaiseLoginSuccessEvent(IPrincipal currentUser, string userId) => OnLoginSuccess(CreateArgs(AuditEvent.LoginSucces, currentUser, userId, string.Empty)); - - public SignOutAuditEventArgs RaiseLogoutSuccessEvent(IPrincipal currentUser, string userId) - { - var currentUserId = GetCurrentUserId(currentUser); - var args = new SignOutAuditEventArgs(AuditEvent.LogoutSuccess, IpResolver.GetCurrentRequestIpAddress(), performingUser: currentUserId, affectedUser: userId); - OnLogoutSuccess(args); - return args; - } - - public UserInviteEventArgs RaiseSendingUserInvite(IPrincipal currentUser, UserInvite invite, IUser createdUser) - { - var currentUserId = GetCurrentUserId(currentUser); - var ip = IpResolver.GetCurrentRequestIpAddress(); - var args = new UserInviteEventArgs(ip, currentUserId, invite, createdUser); - OnSendingUserInvite(args); - return args; - } - - public bool HasSendingUserInviteEventHandler => SendingUserInvite != null; - - // TODO: Comments re static events as per backofficeusermanager - public static event EventHandler AccountLocked; - public static event EventHandler AccountUnlocked; - public static event EventHandler ForgotPasswordRequested; - public static event EventHandler ForgotPasswordChangedSuccess; - public static event EventHandler LoginFailed; - public static event EventHandler LoginRequiresVerification; - public static event EventHandler LoginSuccess; - public static event EventHandler LogoutSuccess; - public static event EventHandler PasswordChanged; - public static event EventHandler PasswordReset; - public static event EventHandler ResetAccessFailedCount; - - /// - /// Raised when a user is invited - /// - public static event EventHandler SendingUserInvite; // this event really has nothing to do with the user manager but was the most convenient place to put it - - protected virtual void OnAccountLocked(IdentityAuditEventArgs e) => AccountLocked?.Invoke(this, e); - - protected virtual void OnSendingUserInvite(UserInviteEventArgs e) => SendingUserInvite?.Invoke(this, e); - - protected virtual void OnAccountUnlocked(IdentityAuditEventArgs e) => AccountUnlocked?.Invoke(this, e); - - protected virtual void OnForgotPasswordRequested(IdentityAuditEventArgs e) => ForgotPasswordRequested?.Invoke(this, e); - - protected virtual void OnForgotPasswordChangedSuccess(IdentityAuditEventArgs e) => ForgotPasswordChangedSuccess?.Invoke(this, e); - - protected virtual void OnLoginFailed(IdentityAuditEventArgs e) => LoginFailed?.Invoke(this, e); - - protected virtual void OnLoginRequiresVerification(IdentityAuditEventArgs e) => LoginRequiresVerification?.Invoke(this, e); - - protected virtual void OnLoginSuccess(IdentityAuditEventArgs e) => LoginSuccess?.Invoke(this, e); - - protected virtual void OnLogoutSuccess(SignOutAuditEventArgs e) => LogoutSuccess?.Invoke(this, e); - - protected virtual void OnPasswordChanged(IdentityAuditEventArgs e) => PasswordChanged?.Invoke(this, e); - - protected virtual void OnPasswordReset(IdentityAuditEventArgs e) => PasswordReset?.Invoke(this, e); - - protected virtual void OnResetAccessFailedCount(IdentityAuditEventArgs e) => ResetAccessFailedCount?.Invoke(this, e); + public bool HasSendingUserInviteEventHandler { get; } } } diff --git a/src/Umbraco.Web/Security/ActiveDirectoryBackOfficeUserPasswordChecker.cs b/src/Umbraco.Web/Security/ActiveDirectoryBackOfficeUserPasswordChecker.cs index 46b6540d73..6bba9af2e4 100644 --- a/src/Umbraco.Web/Security/ActiveDirectoryBackOfficeUserPasswordChecker.cs +++ b/src/Umbraco.Web/Security/ActiveDirectoryBackOfficeUserPasswordChecker.cs @@ -4,6 +4,7 @@ using System.Threading.Tasks; using Microsoft.Extensions.Options; using Umbraco.Core.Configuration.Models; using Umbraco.Core.Security; +using Umbraco.Infrastructure.Security; namespace Umbraco.Web.Security { diff --git a/src/Umbraco.Web/Security/IBackOfficeUserPasswordChecker.cs b/src/Umbraco.Web/Security/IBackOfficeUserPasswordChecker.cs index 7bd67e608a..c048903d0d 100644 --- a/src/Umbraco.Web/Security/IBackOfficeUserPasswordChecker.cs +++ b/src/Umbraco.Web/Security/IBackOfficeUserPasswordChecker.cs @@ -1,5 +1,6 @@ -using System.Threading.Tasks; +using System.Threading.Tasks; using Umbraco.Core.Security; +using Umbraco.Infrastructure.Security; namespace Umbraco.Web.Security { diff --git a/src/Umbraco.Web/Security/Providers/MembersRoleProvider.cs b/src/Umbraco.Web/Security/Providers/MembersRoleProvider.cs index 89507a6c5b..da41838131 100644 --- a/src/Umbraco.Web/Security/Providers/MembersRoleProvider.cs +++ b/src/Umbraco.Web/Security/Providers/MembersRoleProvider.cs @@ -1,8 +1,6 @@ -using System.Collections.Specialized; using System.Configuration.Provider; using System.Linq; using System.Web.Security; -using Umbraco.Core; using Umbraco.Core.Models; using Umbraco.Core.Persistence.Querying; using Umbraco.Core.Services; @@ -13,6 +11,7 @@ namespace Umbraco.Web.Security.Providers public class MembersRoleProvider : RoleProvider { private readonly IMembershipRoleService _roleService; + private string _applicationName; public MembersRoleProvider(IMembershipRoleService roleService) { @@ -24,8 +23,6 @@ namespace Umbraco.Web.Security.Providers { } - private string _applicationName; - public override bool IsUserInRole(string username, string roleName) { return GetRolesForUser(username).Any(x => x == roleName); @@ -46,10 +43,12 @@ namespace Umbraco.Web.Security.Providers return _roleService.DeleteRole(roleName, throwOnPopulatedRole); } - public override bool RoleExists(string roleName) - { - return _roleService.GetAllRoles().Any(x => x == roleName); - } + /// + /// Returns true if the specified member role name exists + /// + /// Member role name + /// True if member role exists, otherwise false + public override bool RoleExists(string roleName) => _roleService.GetAllRolesTyped().Any(x => x.Name == roleName); public override void AddUsersToRoles(string[] usernames, string[] roleNames) { @@ -66,10 +65,11 @@ namespace Umbraco.Web.Security.Providers return _roleService.GetMembersInRole(roleName).Select(x => x.Username).ToArray(); } - public override string[] GetAllRoles() - { - return _roleService.GetAllRoles().ToArray(); - } + /// + /// Gets all the member roles + /// + /// A list of member roles + public override string[] GetAllRoles() => _roleService.GetAllRolesTyped().Select(x => x.Name).ToArray(); public override string[] FindUsersInRole(string roleName, string usernameToMatch) { @@ -87,6 +87,7 @@ namespace Umbraco.Web.Security.Providers { return _applicationName; } + set { if (string.IsNullOrEmpty(value))