Use Invariant when toString userIds
This commit is contained in:
@@ -73,11 +73,11 @@ namespace Umbraco.Cms.Infrastructure.Install.InstallSteps
|
||||
|
||||
_userService.Save(admin);
|
||||
|
||||
var membershipUser = await _userManager.FindByIdAsync(Constants.Security.SuperUserId.ToString());
|
||||
var membershipUser = await _userManager.FindByIdAsync(Constants.Security.SuperUserIdAsString);
|
||||
if (membershipUser == null)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"No user found in membership provider with id of {Constants.Security.SuperUserId}.");
|
||||
$"No user found in membership provider with id of {Constants.Security.SuperUserIdAsString}.");
|
||||
}
|
||||
|
||||
//To change the password here we actually need to reset it since we don't have an old one to use to change
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Factories
|
||||
{
|
||||
public static IIdentityUserToken BuildEntity(ExternalLoginTokenDto dto)
|
||||
{
|
||||
var entity = new IdentityUserToken(dto.Id, dto.ExternalLoginDto.LoginProvider, dto.Name, dto.Value, dto.ExternalLoginDto.UserId.ToString(), dto.CreateDate);
|
||||
var entity = new IdentityUserToken(dto.Id, dto.ExternalLoginDto.LoginProvider, dto.Name, dto.Value, dto.ExternalLoginDto.UserId.ToString(CultureInfo.InvariantCulture), dto.CreateDate);
|
||||
|
||||
// reset dirty initial properties (U4-1946)
|
||||
entity.ResetDirtyProperties(false);
|
||||
@@ -18,7 +18,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Factories
|
||||
|
||||
public static IIdentityUserLogin BuildEntity(ExternalLoginDto dto)
|
||||
{
|
||||
var entity = new IdentityUserLogin(dto.Id, dto.LoginProvider, dto.ProviderKey, dto.UserId.ToString(), dto.CreateDate)
|
||||
var entity = new IdentityUserLogin(dto.Id, dto.LoginProvider, dto.ProviderKey, dto.UserId.ToString(CultureInfo.InvariantCulture), dto.CreateDate)
|
||||
{
|
||||
UserData = dto.UserData
|
||||
};
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using Umbraco.Cms.Core.Models.Membership;
|
||||
using Umbraco.Extensions;
|
||||
@@ -11,7 +12,7 @@ namespace Umbraco.Cms.Core.Security
|
||||
/// </summary>
|
||||
public class MemberIdentityUser : UmbracoIdentityUser
|
||||
{
|
||||
private string _comments;
|
||||
private string _comments;
|
||||
|
||||
// Custom comparer for enumerables
|
||||
private static readonly DelegateEqualityComparer<IReadOnlyCollection<IReadOnlyUserGroup>> s_groupsComparer = new DelegateEqualityComparer<IReadOnlyCollection<IReadOnlyUserGroup>>(
|
||||
@@ -77,7 +78,7 @@ namespace Umbraco.Cms.Core.Security
|
||||
/// </summary>
|
||||
public string MemberTypeAlias { get; set; }
|
||||
|
||||
private static string UserIdToString(int userId) => string.Intern(userId.ToString());
|
||||
private static string UserIdToString(int userId) => string.Intern(userId.ToString(CultureInfo.InvariantCulture));
|
||||
|
||||
// TODO: Should we support custom member properties for persistence/retrieval?
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace Umbraco.Cms.Core.Security
|
||||
throw new InvalidOperationException($"Unable to convert user ID ({userId})to int using InvariantCulture");
|
||||
}
|
||||
|
||||
protected static string UserIdToString(int userId) => string.Intern(userId.ToString());
|
||||
protected static string UserIdToString(int userId) => string.Intern(userId.ToString(CultureInfo.InvariantCulture));
|
||||
|
||||
/// <summary>
|
||||
/// Not supported in Umbraco
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Umbraco.Cms.Core.Events;
|
||||
@@ -25,7 +26,7 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
using (var scope = ScopeProvider.CreateScope(autoComplete: true))
|
||||
{
|
||||
// TODO: This is temp until we update the external service to support guids for both users and members
|
||||
var asString = userId.ToString();
|
||||
var asString = userId.ToString(CultureInfo.InvariantCulture);
|
||||
return _externalLoginRepository.Get(Query<IIdentityUserLogin>().Where(x => x.UserId == asString))
|
||||
.ToList();
|
||||
}
|
||||
@@ -36,7 +37,7 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
using (var scope = ScopeProvider.CreateScope(autoComplete: true))
|
||||
{
|
||||
// TODO: This is temp until we update the external service to support guids for both users and members
|
||||
var asString = userId.ToString();
|
||||
var asString = userId.ToString(CultureInfo.InvariantCulture);
|
||||
return _externalLoginRepository.Get(Query<IIdentityUserToken>().Where(x => x.UserId == asString))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// See LICENSE for more details.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
@@ -59,7 +60,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Web.BackOffice.Authorization
|
||||
public async Task Editing_Single_Admin_User_By_Admin_User_Is_Authorized()
|
||||
{
|
||||
AuthorizationHandlerContext authHandlerContext = CreateAuthorizationHandlerContext();
|
||||
AdminUsersHandler sut = CreateHandler(queryStringValue: Admin2UserId.ToString(), editingWithAdmin: true);
|
||||
AdminUsersHandler sut = CreateHandler(queryStringValue: Admin2UserId.ToString(CultureInfo.InvariantCulture), editingWithAdmin: true);
|
||||
|
||||
await sut.HandleAsync(authHandlerContext);
|
||||
|
||||
@@ -70,7 +71,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Web.BackOffice.Authorization
|
||||
public async Task Editing_Single_Admin_User_By_Non_Admin_User_Is_Not_Authorized()
|
||||
{
|
||||
AuthorizationHandlerContext authHandlerContext = CreateAuthorizationHandlerContext();
|
||||
AdminUsersHandler sut = CreateHandler(queryStringValue: Admin2UserId.ToString());
|
||||
AdminUsersHandler sut = CreateHandler(queryStringValue: Admin2UserId.ToString(CultureInfo.InvariantCulture));
|
||||
|
||||
await sut.HandleAsync(authHandlerContext);
|
||||
|
||||
@@ -81,7 +82,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Web.BackOffice.Authorization
|
||||
public async Task Editing_Single_Non_Admin_User_By_Non_Admin_User_Is_Authorized()
|
||||
{
|
||||
AuthorizationHandlerContext authHandlerContext = CreateAuthorizationHandlerContext();
|
||||
AdminUsersHandler sut = CreateHandler(queryStringValue: NonAdmin2UserId.ToString());
|
||||
AdminUsersHandler sut = CreateHandler(queryStringValue: NonAdmin2UserId.ToString(CultureInfo.InvariantCulture));
|
||||
|
||||
await sut.HandleAsync(authHandlerContext);
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
@@ -510,7 +511,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
|
||||
[AllowAnonymous]
|
||||
public async Task<IActionResult> PostSetPassword(SetPasswordModel model)
|
||||
{
|
||||
var identityUser = await _userManager.FindByIdAsync(model.UserId.ToString());
|
||||
var identityUser = await _userManager.FindByIdAsync(model.UserId.ToString(CultureInfo.InvariantCulture));
|
||||
|
||||
var result = await _userManager.ResetPasswordAsync(identityUser, model.ResetCode, model.Password);
|
||||
if (result.Succeeded)
|
||||
@@ -560,7 +561,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
_userManager.NotifyForgotPasswordChanged(User, model.UserId.ToString());
|
||||
_userManager.NotifyForgotPasswordChanged(User, model.UserId.ToString(CultureInfo.InvariantCulture));
|
||||
return Ok();
|
||||
}
|
||||
|
||||
|
||||
@@ -348,7 +348,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
|
||||
[AllowAnonymous]
|
||||
public async Task<IActionResult> ValidatePasswordResetCode([Bind(Prefix = "u")]int userId, [Bind(Prefix = "r")]string resetCode)
|
||||
{
|
||||
var user = await _userManager.FindByIdAsync(userId.ToString());
|
||||
var user = await _userManager.FindByIdAsync(userId.ToString(CultureInfo.InvariantCulture));
|
||||
if (user != null)
|
||||
{
|
||||
var result = await _userManager.VerifyUserTokenAsync(user, "Default", "ResetPassword", resetCode);
|
||||
|
||||
@@ -250,7 +250,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
|
||||
[ValidateAngularAntiForgeryToken]
|
||||
public async Task<Dictionary<string, string>> GetCurrentUserLinkedLogins()
|
||||
{
|
||||
var identityUser = await _backOfficeUserManager.FindByIdAsync(_backofficeSecurityAccessor.BackOfficeSecurity.GetUserId().ResultOr(0).ToString());
|
||||
var identityUser = await _backOfficeUserManager.FindByIdAsync(_backofficeSecurityAccessor.BackOfficeSecurity.GetUserId().ResultOr(0).ToString(CultureInfo.InvariantCulture));
|
||||
|
||||
// deduplicate in case there are duplicates (there shouldn't be now since we have a unique constraint on the external logins
|
||||
// but there didn't used to be)
|
||||
|
||||
@@ -76,10 +76,10 @@ namespace Umbraco.Cms.Web.BackOffice.Install
|
||||
// Uses same approach as NewInstall Step
|
||||
using IServiceScope scope = _serviceScopeFactory.CreateScope();
|
||||
IBackOfficeUserManager backOfficeUserManager = scope.ServiceProvider.GetRequiredService<IBackOfficeUserManager>();
|
||||
BackOfficeIdentityUser membershipUser = await backOfficeUserManager.FindByIdAsync(Core.Constants.Security.SuperUserId.ToString());
|
||||
BackOfficeIdentityUser membershipUser = await backOfficeUserManager.FindByIdAsync(Core.Constants.Security.SuperUserIdAsString);
|
||||
if (membershipUser == null)
|
||||
{
|
||||
throw new InvalidOperationException($"No user found in membership provider with id of {Core.Constants.Security.SuperUserId}.");
|
||||
throw new InvalidOperationException($"No user found in membership provider with id of {Core.Constants.Security.SuperUserIdAsString}.");
|
||||
}
|
||||
|
||||
//To change the password here we actually need to reset it since we don't have an old one to use to change
|
||||
|
||||
Reference in New Issue
Block a user