Exemple #1
0
        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 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);
        }
Exemple #3
0
        protected override Task <UserIdentityModel> OnDeleteAsync(UserIdentityModel userIdentityModel)
        {
            NullGuard.NotNull(userIdentityModel, nameof(userIdentityModel));

            UserIdentityClaimModel userIdentityClaimModel = userIdentityModel.UserIdentityClaims.FirstOrDefault();

            while (userIdentityClaimModel != null)
            {
                userIdentityModel.UserIdentityClaims.Remove(userIdentityClaimModel);
                userIdentityClaimModel = userIdentityModel.UserIdentityClaims.FirstOrDefault();
            }

            return(Task.FromResult(userIdentityModel));
        }