2020-09-17 09:42:55 +02:00
|
|
|
using Microsoft.Extensions.Logging;
|
2016-04-12 15:11:07 +02:00
|
|
|
using NPoco;
|
2021-08-11 19:11:35 +02:00
|
|
|
using Umbraco.Cms.Core;
|
2021-02-09 10:22:42 +01:00
|
|
|
using Umbraco.Cms.Core.Cache;
|
|
|
|
|
using Umbraco.Cms.Core.Models.Entities;
|
|
|
|
|
using Umbraco.Cms.Core.Persistence.Querying;
|
|
|
|
|
using Umbraco.Cms.Core.Persistence.Repositories;
|
Implements Public Access in netcore (#10137)
* Getting new netcore PublicAccessChecker in place
* Adds full test coverage for PublicAccessChecker
* remove PublicAccessComposer
* adjust namespaces, ensure RoleManager works, separate public access controller, reduce content controller
* Implements the required methods on IMemberManager, removes old migrated code
* Updates routing to be able to re-route, Fixes middleware ordering ensuring endpoints are last, refactors pipeline options, adds public access middleware, ensures public access follows all hops
* adds note
* adds note
* Cleans up ext methods, ensures that members identity is added on both front-end and back ends. updates how UmbracoApplicationBuilder works in that it explicitly starts endpoints at the time of calling.
* Changes name to IUmbracoEndpointBuilder
* adds note
* Fixing tests, fixing error describers so there's 2x one for back office, one for members, fixes TryConvertTo, fixes login redirect
* fixing build
* Fixes keepalive, fixes PublicAccessMiddleware to not throw, updates startup code to be more clear and removes magic that registers middleware.
* adds note
* removes unused filter, fixes build
* fixes WebPath and tests
* Looks up entities in one query
* remove usings
* Fix test, remove stylesheet
* Set status code before we write to response to avoid error
* Ensures that users and members are validated when logging in. Shares more code between users and members.
* Fixes RepositoryCacheKeys to ensure the keys are normalized
* oops didn't mean to commit this
* Fix casing issues with caching, stop boxing value types for all cache operations, stop re-creating string keys in DefaultRepositoryCachePolicy
* bah, far out this keeps getting recommitted. sorry
Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2021-04-20 15:11:45 +10:00
|
|
|
using Umbraco.Cms.Core.Security;
|
2021-02-12 13:36:50 +01:00
|
|
|
using Umbraco.Cms.Infrastructure.Persistence.Dtos;
|
|
|
|
|
using Umbraco.Cms.Infrastructure.Persistence.Factories;
|
|
|
|
|
using Umbraco.Cms.Infrastructure.Persistence.Querying;
|
2022-01-13 17:44:11 +00:00
|
|
|
using Umbraco.Cms.Infrastructure.Scoping;
|
2021-02-09 11:26:22 +01:00
|
|
|
using Umbraco.Extensions;
|
2015-02-09 17:37:21 +11:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement;
|
|
|
|
|
|
2022-09-19 16:37:24 +02:00
|
|
|
internal class ExternalLoginRepository : EntityRepositoryBase<int, IIdentityUserLogin>, IExternalLoginWithKeyRepository
|
2015-02-09 17:37:21 +11:00
|
|
|
{
|
2022-06-02 08:18:31 +02:00
|
|
|
public ExternalLoginRepository(IScopeAccessor scopeAccessor, AppCaches cache,
|
|
|
|
|
ILogger<ExternalLoginRepository> logger)
|
|
|
|
|
: base(scopeAccessor, cache, logger)
|
2015-02-09 17:37:21 +11:00
|
|
|
{
|
2022-06-02 08:18:31 +02:00
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Query for user tokens
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="query"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public IEnumerable<IIdentityUserToken> Get(IQuery<IIdentityUserToken>? query)
|
2015-02-09 17:37:21 +11:00
|
|
|
{
|
2022-06-02 08:18:31 +02:00
|
|
|
Sql<ISqlContext> sqlClause = GetBaseTokenQuery(false);
|
2015-02-09 17:37:21 +11:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
var translator = new SqlTranslator<IIdentityUserToken>(sqlClause, query);
|
|
|
|
|
Sql<ISqlContext> sql = translator.Translate();
|
2022-01-19 09:21:50 +01:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
List<ExternalLoginTokenDto> dtos = Database.Fetch<ExternalLoginTokenDto>(sql);
|
2022-01-19 09:21:50 +01:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
foreach (ExternalLoginTokenDto dto in dtos)
|
2015-02-09 17:37:21 +11:00
|
|
|
{
|
2022-06-02 08:18:31 +02:00
|
|
|
yield return ExternalLoginFactory.BuildEntity(dto);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-10-23 10:10:02 +11:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Count for user tokens
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="query"></param>
|
|
|
|
|
/// <returns></returns>
|
2024-01-02 13:53:24 +01:00
|
|
|
public int Count(IQuery<IIdentityUserToken>? query)
|
2022-06-02 08:18:31 +02:00
|
|
|
{
|
|
|
|
|
Sql<ISqlContext> sql = Sql().SelectCount().From<ExternalLoginDto>();
|
|
|
|
|
return Database.ExecuteScalar<int>(sql);
|
|
|
|
|
}
|
2020-10-23 10:10:02 +11:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
public void DeleteUserLogins(Guid userOrMemberKey) =>
|
|
|
|
|
Database.Delete<ExternalLoginDto>("WHERE userOrMemberKey=@userOrMemberKey", new { userOrMemberKey });
|
2020-10-23 10:10:02 +11:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
public void Save(Guid userOrMemberKey, IEnumerable<IExternalLogin> logins)
|
|
|
|
|
{
|
|
|
|
|
Sql<ISqlContext> sql = Sql()
|
|
|
|
|
.Select<ExternalLoginDto>()
|
|
|
|
|
.From<ExternalLoginDto>()
|
|
|
|
|
.Where<ExternalLoginDto>(x => x.UserOrMemberKey == userOrMemberKey)
|
|
|
|
|
.ForUpdate();
|
2015-02-09 17:37:21 +11:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
// deduplicate the logins
|
|
|
|
|
logins = logins.DistinctBy(x => x.ProviderKey + x.LoginProvider).ToList();
|
2021-08-11 19:11:35 +02:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
var toUpdate = new Dictionary<int, IExternalLogin>();
|
|
|
|
|
var toDelete = new List<int>();
|
|
|
|
|
var toInsert = new List<IExternalLogin>(logins);
|
2020-10-23 10:10:02 +11:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
List<ExternalLoginDto>? existingLogins = Database.Fetch<ExternalLoginDto>(sql);
|
|
|
|
|
|
|
|
|
|
foreach (ExternalLoginDto? existing in existingLogins)
|
|
|
|
|
{
|
|
|
|
|
IExternalLogin? found = logins.FirstOrDefault(x =>
|
|
|
|
|
x.LoginProvider.Equals(existing.LoginProvider, StringComparison.InvariantCultureIgnoreCase)
|
|
|
|
|
&& x.ProviderKey.Equals(existing.ProviderKey, StringComparison.InvariantCultureIgnoreCase));
|
|
|
|
|
|
|
|
|
|
if (found != null)
|
2021-03-11 19:35:43 +11:00
|
|
|
{
|
2022-06-02 08:18:31 +02:00
|
|
|
toUpdate.Add(existing.Id, found);
|
2021-03-11 19:35:43 +11:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
// if it's an update then it's not an insert
|
|
|
|
|
toInsert.RemoveAll(x => x.ProviderKey == found.ProviderKey && x.LoginProvider == found.LoginProvider);
|
|
|
|
|
}
|
|
|
|
|
else
|
2021-03-11 19:35:43 +11:00
|
|
|
{
|
2022-06-02 08:18:31 +02:00
|
|
|
toDelete.Add(existing.Id);
|
2021-03-11 19:35:43 +11:00
|
|
|
}
|
2022-06-02 08:18:31 +02:00
|
|
|
}
|
2021-03-11 19:35:43 +11:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
// do the deletes, updates and inserts
|
|
|
|
|
if (toDelete.Count > 0)
|
|
|
|
|
{
|
2023-06-06 09:29:03 +02:00
|
|
|
// Before we can remove the external login, we must remove the external login tokens associated with that external login,
|
|
|
|
|
// otherwise we'll get foreign key constraint errors
|
|
|
|
|
Database.DeleteMany<ExternalLoginTokenDto>().Where(x => toDelete.Contains(x.ExternalLoginId)).Execute();
|
2022-06-02 08:18:31 +02:00
|
|
|
Database.DeleteMany<ExternalLoginDto>().Where(x => toDelete.Contains(x.Id)).Execute();
|
2020-10-23 10:10:02 +11:00
|
|
|
}
|
|
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
foreach (KeyValuePair<int, IExternalLogin> u in toUpdate)
|
2015-02-09 17:37:21 +11:00
|
|
|
{
|
2022-06-02 08:18:31 +02:00
|
|
|
Database.Update(ExternalLoginFactory.BuildDto(userOrMemberKey, u.Value, u.Key));
|
|
|
|
|
}
|
2015-02-09 17:37:21 +11:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
Database.InsertBulk(toInsert.Select(i => ExternalLoginFactory.BuildDto(userOrMemberKey, i)));
|
|
|
|
|
}
|
2015-02-09 17:37:21 +11:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
public void Save(Guid userOrMemberKey, IEnumerable<IExternalLoginToken> tokens)
|
|
|
|
|
{
|
|
|
|
|
// get the existing logins (provider + id)
|
|
|
|
|
var existingUserLogins = Database
|
|
|
|
|
.Fetch<ExternalLoginDto>(GetBaseQuery(false)
|
|
|
|
|
.Where<ExternalLoginDto>(x => x.UserOrMemberKey == userOrMemberKey))
|
|
|
|
|
.ToDictionary(x => x.LoginProvider, x => x.Id);
|
2015-02-09 17:37:21 +11:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
// deduplicate the tokens
|
|
|
|
|
tokens = tokens.DistinctBy(x => x.LoginProvider + x.Name).ToList();
|
2015-02-09 17:37:21 +11:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
var providers = tokens.Select(x => x.LoginProvider).Distinct().ToList();
|
2015-02-09 17:37:21 +11:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
Sql<ISqlContext> sql = GetBaseTokenQuery(true)
|
|
|
|
|
.WhereIn<ExternalLoginDto>(x => x.LoginProvider, providers)
|
|
|
|
|
.Where<ExternalLoginDto>(x => x.UserOrMemberKey == userOrMemberKey);
|
2015-02-09 17:37:21 +11:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
var toUpdate = new Dictionary<int, (IExternalLoginToken externalLoginToken, int externalLoginId)>();
|
|
|
|
|
var toDelete = new List<int>();
|
|
|
|
|
var toInsert = new List<IExternalLoginToken>(tokens);
|
2015-02-09 17:37:21 +11:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
List<ExternalLoginTokenDto>? existingTokens = Database.Fetch<ExternalLoginTokenDto>(sql);
|
2015-02-09 17:37:21 +11:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
foreach (ExternalLoginTokenDto existing in existingTokens)
|
2015-02-09 17:37:21 +11:00
|
|
|
{
|
2022-06-02 08:18:31 +02:00
|
|
|
IExternalLoginToken? found = tokens.FirstOrDefault(x =>
|
|
|
|
|
x.LoginProvider.InvariantEquals(existing.ExternalLoginDto.LoginProvider)
|
|
|
|
|
&& x.Name.InvariantEquals(existing.Name));
|
2015-02-09 17:37:21 +11:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
if (found != null)
|
2015-02-09 17:37:21 +11:00
|
|
|
{
|
2022-06-02 08:18:31 +02:00
|
|
|
toUpdate.Add(existing.Id, (found, existing.ExternalLoginId));
|
2015-02-09 17:37:21 +11:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
// if it's an update then it's not an insert
|
|
|
|
|
toInsert.RemoveAll(x =>
|
|
|
|
|
x.LoginProvider.InvariantEquals(found.LoginProvider) && x.Name.InvariantEquals(found.Name));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
toDelete.Add(existing.Id);
|
2015-02-09 17:37:21 +11:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
// do the deletes, updates and inserts
|
|
|
|
|
if (toDelete.Count > 0)
|
2015-02-09 17:37:21 +11:00
|
|
|
{
|
2022-06-02 08:18:31 +02:00
|
|
|
Database.DeleteMany<ExternalLoginTokenDto>().Where(x => toDelete.Contains(x.Id)).Execute();
|
|
|
|
|
}
|
2015-02-09 17:37:21 +11:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
foreach (KeyValuePair<int, (IExternalLoginToken externalLoginToken, int externalLoginId)> u in toUpdate)
|
|
|
|
|
{
|
|
|
|
|
Database.Update(ExternalLoginFactory.BuildDto(u.Value.externalLoginId, u.Value.externalLoginToken, u.Key));
|
|
|
|
|
}
|
2015-02-09 17:37:21 +11:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
var insertDtos = new List<ExternalLoginTokenDto>();
|
|
|
|
|
foreach (IExternalLoginToken t in toInsert)
|
|
|
|
|
{
|
|
|
|
|
if (!existingUserLogins.TryGetValue(t.LoginProvider, out var externalLoginId))
|
2015-02-09 17:37:21 +11:00
|
|
|
{
|
2022-06-02 08:18:31 +02:00
|
|
|
throw new InvalidOperationException(
|
|
|
|
|
$"A token was attempted to be saved for login provider {t.LoginProvider} which is not assigned to this user");
|
2015-02-09 17:37:21 +11:00
|
|
|
}
|
|
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
insertDtos.Add(ExternalLoginFactory.BuildDto(externalLoginId, t));
|
2015-02-09 17:37:21 +11:00
|
|
|
}
|
|
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
Database.InsertBulk(insertDtos);
|
|
|
|
|
}
|
2015-02-09 17:37:21 +11:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
protected override IIdentityUserLogin? PerformGet(int id)
|
|
|
|
|
{
|
|
|
|
|
Sql<ISqlContext> sql = GetBaseQuery(false);
|
|
|
|
|
sql.Where(GetBaseWhereClause(), new { id });
|
2015-02-09 17:37:21 +11:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
ExternalLoginDto? dto = Database.Fetch<ExternalLoginDto>(SqlSyntax.SelectTop(sql, 1)).FirstOrDefault();
|
|
|
|
|
if (dto == null)
|
2015-02-09 17:37:21 +11:00
|
|
|
{
|
2022-06-02 08:18:31 +02:00
|
|
|
return null;
|
2015-02-09 17:37:21 +11:00
|
|
|
}
|
|
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
IIdentityUserLogin entity = ExternalLoginFactory.BuildEntity(dto);
|
2015-02-09 17:37:21 +11:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
// reset dirty initial properties (U4-1946)
|
|
|
|
|
entity.ResetDirtyProperties(false);
|
2015-02-09 17:37:21 +11:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
return entity;
|
|
|
|
|
}
|
2015-02-09 17:37:21 +11:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
protected override IEnumerable<IIdentityUserLogin> PerformGetAll(params int[]? ids)
|
|
|
|
|
{
|
|
|
|
|
if (ids?.Any() ?? false)
|
|
|
|
|
{
|
|
|
|
|
return PerformGetAllOnIds(ids);
|
2015-02-09 17:37:21 +11:00
|
|
|
}
|
|
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
Sql<ISqlContext> sql = GetBaseQuery(false).OrderByDescending<ExternalLoginDto>(x => x.CreateDate);
|
2019-12-17 16:30:26 +01:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
return ConvertFromDtos(Database.Fetch<ExternalLoginDto>(sql))
|
|
|
|
|
.ToArray(); // we don't want to re-iterate again!
|
|
|
|
|
}
|
2015-02-09 17:37:21 +11:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
protected override IEnumerable<IIdentityUserLogin> PerformGetByQuery(IQuery<IIdentityUserLogin> query)
|
|
|
|
|
{
|
|
|
|
|
Sql<ISqlContext> sqlClause = GetBaseQuery(false);
|
|
|
|
|
var translator = new SqlTranslator<IIdentityUserLogin>(sqlClause, query);
|
|
|
|
|
Sql<ISqlContext> sql = translator.Translate();
|
2015-02-09 17:37:21 +11:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
List<ExternalLoginDto>? dtos = Database.Fetch<ExternalLoginDto>(sql);
|
2021-03-11 19:35:43 +11:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
foreach (ExternalLoginDto? dto in dtos)
|
2021-03-11 19:35:43 +11:00
|
|
|
{
|
2022-06-02 08:18:31 +02:00
|
|
|
yield return ExternalLoginFactory.BuildEntity(dto);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-03-11 19:35:43 +11:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
private IEnumerable<IIdentityUserLogin> PerformGetAllOnIds(params int[] ids)
|
|
|
|
|
{
|
|
|
|
|
if (ids.Any() == false)
|
|
|
|
|
{
|
|
|
|
|
yield break;
|
|
|
|
|
}
|
2021-03-11 19:35:43 +11:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
foreach (var id in ids)
|
|
|
|
|
{
|
|
|
|
|
IIdentityUserLogin? identityUserLogin = Get(id);
|
|
|
|
|
if (identityUserLogin is not null)
|
2021-03-11 19:35:43 +11:00
|
|
|
{
|
2022-06-02 08:18:31 +02:00
|
|
|
yield return identityUserLogin;
|
2021-03-11 19:35:43 +11:00
|
|
|
}
|
|
|
|
|
}
|
2022-06-02 08:18:31 +02:00
|
|
|
}
|
2021-03-11 19:35:43 +11:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
private IEnumerable<IIdentityUserLogin> ConvertFromDtos(IEnumerable<ExternalLoginDto> dtos)
|
|
|
|
|
{
|
|
|
|
|
foreach (IIdentityUserLogin entity in dtos.Select(ExternalLoginFactory.BuildEntity))
|
2021-03-11 19:35:43 +11:00
|
|
|
{
|
2022-06-02 08:18:31 +02:00
|
|
|
// reset dirty initial properties (U4-1946)
|
|
|
|
|
((BeingDirtyBase)entity).ResetDirtyProperties(false);
|
|
|
|
|
|
|
|
|
|
yield return entity;
|
2021-03-11 19:35:43 +11:00
|
|
|
}
|
2022-06-02 08:18:31 +02:00
|
|
|
}
|
2021-03-11 19:35:43 +11:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
protected override Sql<ISqlContext> GetBaseQuery(bool isCount)
|
|
|
|
|
{
|
|
|
|
|
Sql<ISqlContext> sql = Sql();
|
|
|
|
|
if (isCount)
|
2021-03-11 19:35:43 +11:00
|
|
|
{
|
2022-06-02 08:18:31 +02:00
|
|
|
sql.SelectCount();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
sql.SelectAll();
|
|
|
|
|
}
|
2021-03-11 19:35:43 +11:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
sql.From<ExternalLoginDto>();
|
|
|
|
|
return sql;
|
|
|
|
|
}
|
2021-03-11 19:35:43 +11:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
protected override string GetBaseWhereClause() => $"{Constants.DatabaseSchema.Tables.ExternalLogin}.id = @id";
|
2021-03-11 19:35:43 +11:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
protected override IEnumerable<string> GetDeleteClauses()
|
|
|
|
|
{
|
|
|
|
|
var list = new List<string> { "DELETE FROM umbracoExternalLogin WHERE id = @id" };
|
|
|
|
|
return list;
|
|
|
|
|
}
|
2021-03-11 19:35:43 +11:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
protected override void PersistNewItem(IIdentityUserLogin entity)
|
|
|
|
|
{
|
|
|
|
|
entity.AddingEntity();
|
2021-03-11 19:35:43 +11:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
ExternalLoginDto dto = ExternalLoginFactory.BuildDto(entity);
|
2021-08-11 19:11:35 +02:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
var id = Convert.ToInt32(Database.Insert(dto));
|
|
|
|
|
entity.Id = id;
|
2021-03-11 19:35:43 +11:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
entity.ResetDirtyProperties();
|
|
|
|
|
}
|
2021-03-11 19:35:43 +11:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
protected override void PersistUpdatedItem(IIdentityUserLogin entity)
|
|
|
|
|
{
|
|
|
|
|
entity.UpdatingEntity();
|
2021-03-11 19:35:43 +11:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
ExternalLoginDto dto = ExternalLoginFactory.BuildDto(entity);
|
|
|
|
|
|
|
|
|
|
Database.Update(dto);
|
2021-03-11 19:35:43 +11:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
entity.ResetDirtyProperties();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Sql<ISqlContext> GetBaseTokenQuery(bool forUpdate)
|
|
|
|
|
=> forUpdate
|
|
|
|
|
? Sql()
|
2021-08-11 19:11:35 +02:00
|
|
|
.Select<ExternalLoginTokenDto>(r => r.Select(x => x.ExternalLoginDto))
|
2021-03-11 19:35:43 +11:00
|
|
|
.From<ExternalLoginTokenDto>()
|
v10 SQLite support + distributed locking abstractions (#11922)
* Created Persistence.SQLite project skeleton.
* SQLite database initialization
* Various changes and hacks to make things work.
* WIP integration tests
* Fix thread safety tests
* Fix tests that relied on tie breaker sorting.
Spent a fair amount of time looking for a less lazy fix but gave up.
* Convert right join to left join ContentTypeRepository.PerformGetByQuery
SQLite doesn't support right join
* Fix test Can_Generate_Delete_SubQuery_Statement
Worth noting that NPoco.DatabaseTypes.SQLiteDatabaseType doesn't override
EscapeSqlIdentifier so NPoco will escape with [].
SQLite docs say > "A keyword enclosed in square brackets is an identifier.
This is not standard SQL.
This quoting mechanism is used by MS Access and SQL Server and is
included in SQLite for compatibility."
Also could have updated SqliteSyntaxProvider to match npoco but
decided against it.
* Fixes for paginated custom order by
* Fix tests broken by lack of unique indexes.
* Fix SqlServerTableByTableTest tests.
These tests didn't actually do anything as the tables already exist so schema creator just returned.
Did however point out that the default implementation for DoesTableExist just returns false so added a default naive implementation.
* Fix ValidateLoginSession - SelectTop must come later
* dry up database cleanup
* Fix up db migration tests.
We can't drop pk in sqlite without recreating table.
Test looks to be testing that add column works as intended which we can test.
* Prevent schema creation errors.
* SQLite ignore lock tests, WAL back on.
* Fix package schema tests
* Fix NPocoFetchTests - case sensitivity not under test
* Fix AdvancedMigrationTests (where possible)
Migrations probably need a good look later.
Maybe nuke old migrations and only support moving to v10 from v9.
If we do that can do some cleanup.
* Cleanup test database configuration
* Run integration tests against SQLite on build agent.
* Drop MS.Data.SQLite
System.Data.SQLite was quicker to roll out due to more CLR type mapping
* YAML
* Skip Umbraco.Tests.Integration.SqlCe
* Drop SqlServerTableByTable tests.
Until this week they did nothing anyway as they with NewSchemaPerTest
so the tests all passed as CreateTable was no op (already exists).
Also all of the tables are created in an empty database by SchemaValidationTest.cs
DatabaseSchemaCreation_Produces_DatabaseSchemaResult_With_Zero_Errors
* Might aswell run against macOS also.
* Copy azure pipelines task header layout
* Delete SQLCe projects
* Remove SQL CE specific code.
* Remove SQL CE NuSpec, template params, build script setup
* Delete umbraco-netcore-only.sln
* Add SkipTests solution configuration and use for codeql
* Remove reference to deleted nuspec file.
* Refactor ConnectionStrings WRT DataDirectory placeholder & ProviderName.
At this point you can try out SQLite support by setting the following
in appsettings.json and then completing the install process.
"ConnectionStrings": {
"umbracoDbDSN": "Data Source=|DataDirectory|/umbraco.sqlite",
"umbracoDbDSN_ProviderName": "System.Data.SQLite"
},
Not currently possible via installer UI without provider name pre-set in
configuration.
* Switch to Microsoft.Data.Sqlite
Some gross hacks but will be good to find out if this works
with apple silicon.
* Enable selection of SQLite via installer UI (also quick install)
* Remove SqlServerDbProviderFactoryCreator to cleanup a TODO
* Move SQL Server support to its own class library
* Add persistence dependencies to Umbraco.CMS metapackage
* Bugfix packages delete query
Created invalid query for SQLite.
* Try out cypress tests Linux + SQLite
* Prevent cypress test artifact upload failure on attempt 2+
* LocalDb bugfixes
* Drop redundant enum
* Move SqlClient constant
* Misc whitespace
* Remove IsSqlCe extension (TODO: drop non 9->10 migrations later).
* Umbraco.Persistence.* -> Umbraco.Cms.Persistence.*
* Display quick install defaults and per provider default database name.
* Misc remove old comment
* little re-arrange
* Remove almost all usages of IsSqlite extension.
* visual adjustments
* Custom Database Configuration is last step and should then say Install.
* use text instead of disabled inputs
* move legend, rename to Install
* Update SqlMainDomLock to work without distributed locks.
* Added IDistributedLockingMechanism interface and in memory impl.
* Drop locking from ISqlSyntaxProvider & wire up scope to abstraction.
* Added SqlServerDistributedLockingMechanism
* Move distributed locking interfaces and exceptions to Core + xmldocs.
* Fix tests, Misc cleanup, Add SQL distributed locking integration tests
* Provide mechanism to specify DistributedLockingMechanism in config
(even if added by composer)
* Nomplementation -> NoImplementation
* Fix misleading comment
* Integration tests use SqlServerDistributedLockingMechanism when possible
* Handle up-gradable locks SqlServerDistributedLockingMechanism.
TODO: InMemoryDistributedLockingMechanism.
Note: Nuked SqlServerDistributedLockingMechanismTests, will still sleep
at night.
Is covered by Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.LockTests
* Make tests pass for InMemoryDistributedLockingMechanism, pretty hacky.
* Tweak constraints on WithCollectionBuilder so i can drop bad constructor
* Added SqliteDistributedLockingMechanism
* Dropped InMemoryDistributedMechanism + magic
InMemoryDistributedMechanism was pretty rubbish and now we have
a decent implementation for SQLite as we no longer block readers
see 8d1f42b.
Also drop the CollectionBuilder setup, instead do the same as we do
for syntax providers etc, it's more automagical so we never require an
explicit selection although we are allowing for it.
However keeping the optional IUmbracoBuilder constructor param for
CollectionBuilders as it's extremely useful.
* Fix quick install "" database name.
* Hide Database Configuration section when a connection string is pre-set.
Doesn't seem worth it to extract db name from connection string.
* Ensure wal test 2+
* Fix logging inconsistencies.
* Ensure in transaction when obtaining locks + no-op the SQLite read lock.
There's no point in running the query just to make a single test pass.
* Fix installer database display names
* Allow SQLite shared cache without losing deferred transactions
* Opt into shared cache for new SQLite databases + fix filename
* Fix misc inconsistency in .gitignore
* Prefer our interceptor interface
* Restore DEBUG_DATABASES code OnConnectionOpened in case it's used.
* Back to private cache.
* Added retry strategy for SQLite + refactor out SQL server specific stuff
* Fix SQL server tests.
* Misc - Orphaned comment, incorrect casing.
* InMemory SQLite test database & turn shared cache back on everywhere.
Co-authored-by: Niels Lyngsø <niels.lyngso@gmail.com>
2022-03-11 16:14:20 +00:00
|
|
|
.AppendForUpdateHint() // ensure these table values are locked for updates, the ForUpdate ext method does not work here
|
2021-03-11 19:35:43 +11:00
|
|
|
.InnerJoin<ExternalLoginDto>()
|
|
|
|
|
.On<ExternalLoginTokenDto, ExternalLoginDto>(x => x.ExternalLoginId, x => x.Id)
|
|
|
|
|
: Sql()
|
|
|
|
|
.Select<ExternalLoginTokenDto>()
|
2022-01-19 09:21:50 +01:00
|
|
|
.AndSelect<ExternalLoginDto>(x => x.LoginProvider, x => x.UserOrMemberKey)
|
2021-03-11 19:35:43 +11:00
|
|
|
.From<ExternalLoginTokenDto>()
|
|
|
|
|
.InnerJoin<ExternalLoginDto>()
|
|
|
|
|
.On<ExternalLoginTokenDto, ExternalLoginDto>(x => x.ExternalLoginId, x => x.Id);
|
2017-07-20 11:21:28 +02:00
|
|
|
}
|