Пример #1
0
        public async Task CreateKeyAsync(DataKey dataKey)
        {
            Application application = await _applicationCommandRepository.GetSingleAsync(a => a.SystemName == _appSettings.SystemName);

            if (application == null)
            {
                application = await _createApplicationCommand.ExecuteAsync(new CreateApplicationCommandDdto
                {
                    SystemName = _appSettings.SystemName
                });

                await _addApplicationDataKeyCommand.ExecuteAsync(application, new AddApplicationDataKeyCommandDdto
                {
                    Type  = dataKey.Name,
                    Value = dataKey.Value
                });

                await _applicationCommandRepository.AddAsync(application);
            }
            else
            {
                await _addApplicationDataKeyCommand.ExecuteAsync(application, new AddApplicationDataKeyCommandDdto
                {
                    Type  = dataKey.Name,
                    Value = dataKey.Value
                });

                await _applicationCommandRepository.UpdateAsync(application);
            }
        }
Пример #2
0
        private async Task <AuthenticationGrantTypePassword> GetAuthenticationGrantTypePassword()
        {
            AuthenticationService authenticationService = await _authenticationServiceCommandRepository.GetSingleAsync(s => s is AuthenticationGrantTypePassword);

            if (!(authenticationService is AuthenticationGrantTypePassword authenticationGrantTypePassword))
            {
                throw new BusinessApplicationException(ExceptionType.BadRequest, ErrorCodes.PasswordLoginNotConfigured, "Password identities are not configured");
            }

            return(authenticationGrantTypePassword);
        }
Пример #3
0
        public async Task RegisterAsync(RegisterApplicationAdto registerApplicationAdto)
        {
            using (ITransaction transaction = _transactionManager.Create())
            {
                try
                {
                    Domain.Applications.Application application = await _commandRepository.GetSingleAsync(a => a.SystemName == registerApplicationAdto.SystemName);

                    if (application == null)
                    {
                        application = await _createApplicationCommand.ExecuteAsync(new CreateApplicationDdto
                        {
                            Name       = registerApplicationAdto.Name,
                            SystemName = registerApplicationAdto.SystemName,
                            HostUri    = registerApplicationAdto.HostUri
                        });

                        await _commandRepository.AddAsync(application);
                    }
                    else
                    {
                        await _changeApplicationCommand.ExecuteAsync(application, new ChangeApplicationDdto
                        {
                            Name    = registerApplicationAdto.Name,
                            HostUri = registerApplicationAdto.HostUri
                        });
                    }

                    transaction.Commit();
                }
                catch (CreateDomainException e)
                {
                    throw new BusinessApplicationException(ExceptionType.Unknown, e);
                }
                catch (ConcurrencyDomainException e)
                {
                    throw new BusinessApplicationException(ExceptionType.Unknown, e);
                }
            }
        }
Пример #4
0
        public async Task <RefreshTokenIdentityAdto> CreateRefreshTokenAsync(CreateRefreshTokenAdto createRefreshTokenAdto)
        {
            using (ITransaction transaction = _transactionManager.Create())
            {
                try
                {
                    Identity identity = await _identityCommandRepository.GetByIdAsync(createRefreshTokenAdto.IdentityId);

                    if (identity == null)
                    {
                        throw new BusinessApplicationException(ExceptionType.NotFound, "Identity not found");
                    }

                    AuthenticationGrantTypeRefreshToken authenticationGrantTypeRefreshToken = (AuthenticationGrantTypeRefreshToken)await
                                                                                              _authenticationServiceCommandRepository.GetSingleAsync(a => a is AuthenticationGrantTypeRefreshToken);

                    if (authenticationGrantTypeRefreshToken == null)
                    {
                        throw new BusinessApplicationException(ExceptionType.NotFound, "Refresh tokens are not configured");
                    }

                    RefreshTokenIdentityDdto refreshTokenIdentityDdto = await _createRefreshTokenCommand.ExecuteAsync(identity, authenticationGrantTypeRefreshToken);

                    await _identityCommandRepository.UpdateAsync(identity);

                    transaction.Commit();

                    return(new RefreshTokenIdentityAdto
                    {
                        Token = refreshTokenIdentityDdto.Token
                    });
                }
                catch (DomainValidationRuleException e)
                {
                    throw new BusinessValidationRuleApplicationException(e.ValidationResult);
                }
            }
        }