internal static IUserIdentity ToDomain(this UserIdentityModel userIdentityModel, IConverter securityModelConverter) { NullGuard.NotNull(userIdentityModel, nameof(userIdentityModel)) .NotNull(securityModelConverter, nameof(securityModelConverter)); IEnumerable <Claim> claimCollection = securityModelConverter.Convert <IEnumerable <UserIdentityClaimModel>, IEnumerable <Claim> >(userIdentityModel.UserIdentityClaims); UserIdentityClaimModel latestUserIdentityClaimModel = userIdentityModel.UserIdentityClaims.OrderByDescending(model => model.ModifiedUtcDateTime).FirstOrDefault(); IUserIdentity userIdentity = new UserIdentityBuilder(userIdentityModel.ExternalUserIdentifier) .WithIdentifier(userIdentityModel.UserIdentityIdentifier) .AddClaims(claimCollection) .Build(); if (latestUserIdentityClaimModel == null || latestUserIdentityClaimModel.ModifiedUtcDateTime < userIdentityModel.ModifiedUtcDateTime) { userIdentity.AddAuditInformation(userIdentityModel.CreatedUtcDateTime, userIdentityModel.CreatedByIdentifier, userIdentityModel.ModifiedUtcDateTime, userIdentityModel.ModifiedByIdentifier); } else { userIdentity.AddAuditInformation(userIdentityModel.CreatedUtcDateTime, userIdentityModel.CreatedByIdentifier, latestUserIdentityClaimModel.ModifiedUtcDateTime, latestUserIdentityClaimModel.ModifiedByIdentifier); } return(userIdentity); }
internal static UserIdentityModel WithDefaultIdentifier(this UserIdentityModel userIdentityModel) { NullGuard.NotNull(userIdentityModel, nameof(userIdentityModel)); userIdentityModel.UserIdentityIdentifier = default; return(userIdentityModel); }
internal static UserIdentityModel With(this UserIdentityModel userIdentityModel, IEnumerable <Claim> claimCollection, RepositoryContext context, IConverter securityModelConverter) { NullGuard.NotNull(userIdentityModel, nameof(userIdentityModel)) .NotNull(claimCollection, nameof(claimCollection)) .NotNull(context, nameof(context)) .NotNull(securityModelConverter, nameof(securityModelConverter)); IList <ClaimModel> claimModelCollection = context.Claims.ToListAsync() .GetAwaiter() .GetResult(); userIdentityModel.UserIdentityClaims = claimCollection.AsParallel() .Where(claim => claimModelCollection.Any(c => c.ClaimType == claim.Type)) .Select(claim => securityModelConverter.Convert <Claim, UserIdentityClaimModel>(claim).With(userIdentityModel).With(claimModelCollection.Single(c => c.ClaimType == claim.Type))) .ToList(); return(userIdentityModel); }
internal static UserIdentityClaimModel With(this UserIdentityClaimModel userIdentityClaimModel, UserIdentityModel userIdentityModel) { NullGuard.NotNull(userIdentityClaimModel, nameof(userIdentityClaimModel)) .NotNull(userIdentityModel, nameof(userIdentityModel)); userIdentityClaimModel.UserIdentityIdentifier = userIdentityModel.UserIdentityIdentifier; userIdentityClaimModel.UserIdentity = userIdentityModel; return(userIdentityClaimModel); }