Esempio n. 1
0
 public async Task <Message <ClientDomain> > Create(ClientDomain aggregate) => await new ExecutionAsync <ClientDomain>(async() =>
 {
     var client = Map <ClientDomain, Client>(aggregate);
     await DatabaseContext.Clients.AddAsync(client);
     await DatabaseContext.SaveChangesAsync();
 }, async() => { return(await DatabaseContext.Clients.AnyAsync(f =>
                                                               f.FirstName == aggregate.FirstName &&
                                                               f.LastName == aggregate.LastName &&
                                                               f.Address == aggregate.Address)); }, "The client is already registered in the database").Run();
Esempio n. 2
0
 public ClientV2Controller(
     TelemetryClient telemetry,
     ClientDomain clientDomain,
     IUserIdentity userIdentity,
     ICache cache)
 {
     this.telemetry    = telemetry;
     this.clientDomain = clientDomain;
     this.userIdentity = userIdentity;
     this.cache        = cache;
 }
 public static ClientView ClientFromDomainToView(this ClientDomain @this)
 {
     return(new ClientView()
     {
         ClientId = @this.ClientId,
         ClientTitle = @this.ClientTitle,
         ClientMarkJuridical = @this.ClientMarkJuridical,
         ClientTaxpayNum = @this.ClientTaxpayNum,
         AccountsOfClient = @this.AccountsOfClient.Select(_ => _.AccountFromDomainToView()).ToList()
     });
 }
Esempio n. 4
0
 public static ClientInfrastr ClientFromDomainToInfra(this ClientDomain @this)
 {
     if (@this != null)
     {
         return(new ClientInfrastr()
         {
             ClientId = @this.ClientId,
             ClientTitle = @this.ClientTitle,
             ClientMarkJuridical = @this.ClientMarkJuridical,
             ClientTaxpayNum = @this.ClientTaxpayNum,
             AccountsOfClient = @this.AccountsOfClient.Select(_ => _.AccountFromDomainToInfra()).ToList()
         });
     }
     else
     {
         return(null);
     }
 }
Esempio n. 5
0
 /// <summary>
 ///  Returns the hashcode for this object.
 /// </summary>
 /// <returns></returns>
 /// <remarks>
 /// Excluding those properties which are not serialized:
 /// ClientCertificates, ServerCertificateValidationCallback, NetworkCredential, ProtocolLoggerDelegate
 /// </remarks>
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = MaxFailures;
         hashCode = (hashCode * 397) ^ RetryDelayTime;
         hashCode = (hashCode * 397) ^ (MailOutputDirectory != null ? MailOutputDirectory.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Name != null ? Name.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (SmtpHost != null ? SmtpHost.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ SmtpPort;
         hashCode = (hashCode * 397) ^ (ClientDomain != null ? ClientDomain.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (LocalEndPoint != null ? LocalEndPoint.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (int)MessageOutput;
         hashCode = (hashCode * 397) ^ (int)SslProtocols;
         hashCode = (hashCode * 397) ^ (int)SecureSocketOptions;
         hashCode = (hashCode * 397) ^ Timeout;
         hashCode = (hashCode * 397) ^ DelayBetweenMessages;
         return(hashCode);
     }
 }
Esempio n. 6
0
        public void Setup()
        {
            var dbContextObtionsBuilder = new DbContextOptionsBuilder <MyFirstDbContext>();

            dbContextObtionsBuilder.UseInMemoryDatabase("MyFirstDatabase" + Guid.NewGuid());
            myFirstDbContext = new MyFirstDbContext(null);

            var clientDomain = new ClientDomain(myFirstDbContext);
            var userIdentity = Substitute.For <IUserIdentity>();

            this.clientV2Controller = new ClientV2Controller(null, clientDomain, userIdentity);

            var identity = new ClaimsIdentity("Password", "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name",
                                              "http://schemas.microsoft.com/ws/2008/06/identity/claims/role");

            identity.AddClaim(
                "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier",
                "agaltier",
                OpenIdConnectConstants.Destinations.AccessToken,
                OpenIdConnectConstants.Destinations.IdentityToken);
            identity.AddClaim(
                "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name",
                "agaltier",
                OpenIdConnectConstants.Destinations.AccessToken,
                OpenIdConnectConstants.Destinations.IdentityToken);
            identity.AddClaim(
                OpenIdConnectConstants.Claims.Subject,
                "agaltier",
                OpenIdConnectConstants.Destinations.AccessToken,
                OpenIdConnectConstants.Destinations.IdentityToken);
            identity.AddClaim(
                "tokenId",
                "1235453432FSD",
                OpenIdConnectConstants.Destinations.AccessToken,
                OpenIdConnectConstants.Destinations.IdentityToken);

            userIdentity.Get(Arg.Any <Controller>()).Returns(identity);
        }
        public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
        {
            string clientId;
            string clientSecret;

            // Tenta pegar o ID e o Segredo da aplicação cliente pela base64 
            if (!context.TryGetBasicCredentials(out clientId, out clientSecret))
            {
                // Se não conseguir, tenta através de de codificação x-www-form-urlencoded
                context.TryGetFormCredentials(out clientId, out clientSecret);
            }

            // Verifica se o ID da aplicação cliente está vazio
            if (context.ClientId == null)
            {
                context.SetError("invalid_clientId", "ClientId should be sent.");
                return Task.FromResult<object>(null);
            }

            // Busca a aplicação cliente na base de dados pelo ID
            var clientDomain = new ClientDomain();
            var client = clientDomain.Read(context.ClientId);

            // Se a aplicação cliente não estiver cadastrada
            if (client == null)
            {
                // invalida o contexto e rejeita a requisição
                context.SetError("invalid_clientId",
                    string.Format("Client '{0}' is not registered in the system.", context.ClientId));
                return Task.FromResult<object>(null);
            }

            // Se a aplicação encontrada pelo ID for do tipo NativeConfidential
            if (client.ApplicationType == ApplicationTypes.NativeConfidential)
            {
                // E se o segredo da aplicação cliente for nulo ou vazio
                if (string.IsNullOrWhiteSpace(clientSecret))
                {
                    // Invalida o contexto e rejeita a requisição, pois aplicações nativas devem passar o segredo
                    context.SetError("invalid_clientId", "Client secret should be sent.");
                    return Task.FromResult<object>(null);
                }

                // Se o segredo da aplicação cliente encontrada no banco de dados for diferente do segredo passado pela aplicação cliente
                if (client.Secret != HashHelper.GetHash(clientSecret))
                {
                    // Invalida o contexto e rejeita a requisição, pois o segredo deve ser o mesmo cadastrado na base de dados
                    context.SetError("invalid_clientId", "Client secret is invalid.");
                    return Task.FromResult<object>(null);
                }
            }

            // Se a aplicação cliente encontrado na base de dados se encontra inativa
            if (!client.Active)
            {
                // Invalida o contexto e rejeita a requisição, pois a aplicação precisa estar ativa para ser aceita
                context.SetError("invalid_clientId", "Client is inactive.");
                return Task.FromResult<object>(null);
            }

            // Guarda no contexto do Owin a origem permitida e o tempo de expiração do token da aplicação cliente
            context.OwinContext.Set("as:clientAllowedOrigin", client.AllowedOrigin);
            context.OwinContext.Set("as:clientRefreshTokenLifeTime", client.RefreshTokenLifeTime.ToString());

            // Valida o contexto, o que significa que a autenticação da aplicação cliente passou
            context.Validated();
            return Task.FromResult<object>(null);
        }
 public void Update(ClientDomain inst)
 {
     clientRepository.UpdateCl(inst.ClientFromDomainToInfra());
 }
Esempio n. 9
0
 public ClientController(ClientDomain clientDomain)
 {
     this.clientDomain = clientDomain;
 }
Esempio n. 10
0
 /// <summary>
 /// Construtor referente ao controller do Módulo Cliente
 /// </summary>
 public ClientController(SysQueirozContext context)
 {
     clientDomain = new ClientDomain(context);
 }
Esempio n. 11
0
 public async Task <Message <ClientDomain> > Update(ClientDomain aggregate) => await new ExecutionAsync <ClientDomain>(async() =>
 {
     var clientToEdit = await DatabaseContext.Clients.FirstOrDefaultAsync(f => f.Id == aggregate.Id);
     clientToEdit     = await MappAsync(aggregate, clientToEdit);
     await DatabaseContext.SaveChangesAsync();
 }).Run();