Ejemplo n.º 1
0
        internal static IClientSecretIdentity ToDomain(this ClientSecretIdentityModel clientSecretIdentityModel, IConverter securityModelConverter)
        {
            NullGuard.NotNull(clientSecretIdentityModel, nameof(clientSecretIdentityModel))
            .NotNull(securityModelConverter, nameof(securityModelConverter));

            IEnumerable <Claim> claimCollection = securityModelConverter.Convert <IEnumerable <ClientSecretIdentityClaimModel>, IEnumerable <Claim> >(clientSecretIdentityModel.ClientSecretIdentityClaims);

            ClientSecretIdentityClaimModel latestClientSecretIdentityClaimModel = clientSecretIdentityModel.ClientSecretIdentityClaims.OrderByDescending(model => model.ModifiedUtcDateTime).FirstOrDefault();

            IClientSecretIdentity clientSecretIdentity = new ClientSecretIdentityBuilder(clientSecretIdentityModel.FriendlyName)
                                                         .WithIdentifier(clientSecretIdentityModel.ClientSecretIdentityIdentifier)
                                                         .WithClientId(clientSecretIdentityModel.ClientId)
                                                         .WithClientSecret(clientSecretIdentityModel.ClientSecret)
                                                         .AddClaims(claimCollection)
                                                         .Build();

            if (latestClientSecretIdentityClaimModel == null || latestClientSecretIdentityClaimModel.ModifiedUtcDateTime < clientSecretIdentityModel.ModifiedUtcDateTime)
            {
                clientSecretIdentity.AddAuditInformation(clientSecretIdentityModel.CreatedUtcDateTime, clientSecretIdentityModel.CreatedByIdentifier, clientSecretIdentityModel.ModifiedUtcDateTime, clientSecretIdentityModel.ModifiedByIdentifier);
            }
            else
            {
                clientSecretIdentity.AddAuditInformation(clientSecretIdentityModel.CreatedUtcDateTime, clientSecretIdentityModel.CreatedByIdentifier, latestClientSecretIdentityClaimModel.ModifiedUtcDateTime, latestClientSecretIdentityClaimModel.ModifiedByIdentifier);
            }

            return(clientSecretIdentity);
        }
Ejemplo n.º 2
0
        internal static ClientSecretIdentityModel WithDefaultIdentifier(this ClientSecretIdentityModel clientSecretIdentityModel)
        {
            NullGuard.NotNull(clientSecretIdentityModel, nameof(clientSecretIdentityModel));

            clientSecretIdentityModel.ClientSecretIdentityIdentifier = default;

            return(clientSecretIdentityModel);
        }
Ejemplo n.º 3
0
        internal static ClientSecretIdentityModel With(this ClientSecretIdentityModel clientSecretIdentityModel, IEnumerable <Claim> claimCollection, RepositoryContext context, IConverter securityModelConverter)
        {
            NullGuard.NotNull(clientSecretIdentityModel, nameof(clientSecretIdentityModel))
            .NotNull(claimCollection, nameof(claimCollection))
            .NotNull(context, nameof(context))
            .NotNull(securityModelConverter, nameof(securityModelConverter));

            IList <ClaimModel> claimModelCollection = context.Claims.ToListAsync()
                                                      .GetAwaiter()
                                                      .GetResult();

            clientSecretIdentityModel.ClientSecretIdentityClaims = claimCollection.AsParallel()
                                                                   .Where(claim => claimModelCollection.Any(c => c.ClaimType == claim.Type))
                                                                   .Select(claim => securityModelConverter.Convert <Claim, ClientSecretIdentityClaimModel>(claim).With(clientSecretIdentityModel).With(claimModelCollection.Single(c => c.ClaimType == claim.Type)))
                                                                   .ToList();

            return(clientSecretIdentityModel);
        }
Ejemplo n.º 4
0
        internal static ClientSecretIdentityClaimModel With(this ClientSecretIdentityClaimModel clientSecretIdentityClaimModel, ClientSecretIdentityModel clientSecretIdentity)
        {
            NullGuard.NotNull(clientSecretIdentityClaimModel, nameof(clientSecretIdentityClaimModel))
            .NotNull(clientSecretIdentity, nameof(clientSecretIdentity));

            clientSecretIdentityClaimModel.ClientSecretIdentityIdentifier = clientSecretIdentity.ClientSecretIdentityIdentifier;
            clientSecretIdentityClaimModel.ClientSecretIdentity           = clientSecretIdentity;

            return(clientSecretIdentityClaimModel);
        }