public ScenarioSession ResumeScenario(string userSubject, int id) { _logger.Info($"{nameof(ResumeScenario)}({userSubject}, {id})"); try { ScenarioSession scenarioSession = _dataAccessService.GetScenarioSessions(userSubject).FirstOrDefault(s => s.ScenarioId == id); if (scenarioSession == null) { throw new ScenarioSessionNotFoundException(userSubject, id); } bool needInitialize = false; if (!_activeScenarios.TryGetValue(userSubject, out ScenarioMonitoringData scenarioMonitoringData)) { needInitialize = true; } else if (scenarioMonitoringData.ScenarioId != id) { needInitialize = true; } if (needInitialize) { scenarioMonitoringData = new ScenarioMonitoringData { ScenarioId = id, ScenarioSessionId = scenarioSession.ScenarioSessionId, ActivationTime = scenarioSession.StartTime, LastUseTime = DateTime.UtcNow }; _activeScenarios.AddOrUpdate(userSubject, scenarioMonitoringData, (k, v) => v); ScenarioDefinition scenarioDefinition = _scenarios[id]; IEnumerable <Client.DataLayer.Model.Scenarios.ScenarioAccount> scenarioAccounts = _dataAccessService.GetScenarioAccounts(scenarioSession.ScenarioSessionId); foreach (var scenarioAccount in scenarioAccounts) { AccountDescriptor account = _accountsService.GetById(scenarioAccount.AccountId); if (account.AccountType == AccountType.IdentityProvider || account.AccountType == AccountType.ServiceProvider) { AccountDescriptor accountDescriptor = _accountsService.Authenticate(scenarioAccount.AccountId, "qqq"); _executionContextManager.InitializeStateExecutionServices(accountDescriptor.AccountId, accountDescriptor.SecretSpendKey); } } } else { scenarioMonitoringData.LastUseTime = DateTime.UtcNow; } return(scenarioSession); } catch (Exception ex) { _logger.Error($"Failed {nameof(ResumeScenario)}({userSubject}, {id})", ex); throw; } }
protected override void InitializeInner(CancellationToken cancellationToken) { foreach (var autoLogin in _dataAccessService.GetAutoLogins().Where(a => a.Account != null)) { _logger.LogIfDebug(() => $"Autologin of {JsonConvert.SerializeObject(autoLogin, new ByteArrayJsonConverter())}"); int attempts = 5; bool succeeded = false; do { try { _executionContextManager.InitializeStateExecutionServices(autoLogin.Account.AccountId, autoLogin.SecretKey); _logger.Info($"Account {autoLogin.Account.AccountInfo} with id {autoLogin.Account.AccountId} successfully auto logged in"); succeeded = true; } catch (Exception ex) { _logger.Error($"Failure during {nameof(AutoLoginsInitializer)} for {JsonConvert.SerializeObject(autoLogin, new ByteArrayJsonConverter())}", ex); Task.Delay(1000).Wait(); } } while (!succeeded && --attempts > 0); } }
public void Initialize() { var polls = _dataAccessService.GetEcPolls((int)PollState.Started); foreach (var poll in polls) { var account = _dataAccessService.GetAccount(poll.AccountId); _castedVotes.Add(poll.EcPollRecordId, new ConcurrentDictionary <IKey, TaskCompletionSource <bool> >(new Key32())); _executionContextManager.InitializeStateExecutionServices(account.AccountId, account.SecretSpendKey); } }
protected override void InitializeInner(CancellationToken cancellationToken) { _logger.Info($"Started {nameof(InitializeInner)}"); _logger.Info($"There are {_externalIdps?.Length ?? 0} external IdPs"); foreach (var externalIdp in _externalIdps) { _logger.Info($"Initializing {JsonConvert.SerializeObject(externalIdp)}"); try { var provider = _dataAccessService.GetExternalIdentityProvider(externalIdp.Name); if (provider == null) { long accountId = CreateIdentityProviderAccount(externalIdp); _dataAccessService.AddExternalIdentityProvider(externalIdp.Name, externalIdp.Alias, externalIdp.Description, accountId); provider = _dataAccessService.GetExternalIdentityProvider(externalIdp.Name); } var accountDescriptor = _accountsService.Authenticate(provider.AccountId, GetDefaultIdpPassword(provider.Name)); if (accountDescriptor != null) { _logger.Info($"Account {externalIdp.Name} authenticated successfully"); if (externalIdp.AttributeDefinitions != null) { foreach (var item in externalIdp.AttributeDefinitions) { long rootAttributeSchemeId = _dataAccessService.AddAttributeToScheme(accountDescriptor.PublicSpendKey.ToHexString(), item.AttributeName, item.SchemeName, item.Alias, item.Description); if (item.IsRoot) { _dataAccessService.ToggleOnRootAttributeScheme(rootAttributeSchemeId); } } } _executionContextManager.InitializeStateExecutionServices(accountDescriptor.AccountId, accountDescriptor.SecretSpendKey); } else { _logger.Error($"Authentication of the account {externalIdp.Name} failed"); } _logger.Info($"Finished {nameof(InitializeInner)}"); } catch (Exception ex) { _logger.Error($"Failed to initialize the External IdP {externalIdp.Name}", ex); } } }
public IActionResult Authenticate([FromBody] AccountDto accountDto) { _logger.LogIfDebug(() => $"[{accountDto.AccountId}]: Started authentication of the account {JsonConvert.SerializeObject(accountDto)}"); var accountDescriptor = _accountsService.Authenticate(accountDto.AccountId, accountDto.Password); if (accountDescriptor == null) { throw new AccountAuthenticationFailedException(accountDto.AccountId); } if (accountDescriptor.AccountType == AccountType.User) { _executionContextManager.InitializeUtxoExecutionServices(accountDescriptor.AccountId, accountDescriptor.SecretSpendKey, accountDescriptor.SecretViewKey, accountDescriptor.PwdHash); var persistency = _executionContextManager.ResolveUtxoExecutionServices(accountDto.AccountId); if (!persistency.BindingKeySource.Task.IsCompleted) { persistency.BindingKeySource.SetResult(ConfidentialAssetsHelper.PasswordHash(accountDto.Password)); } } else { _executionContextManager.InitializeStateExecutionServices(accountDescriptor.AccountId, accountDescriptor.SecretSpendKey); } var forLog = new { accountDescriptor.AccountId, accountDescriptor.AccountType, accountDescriptor.AccountInfo, SecretSpendKey = accountDescriptor.SecretSpendKey.ToHexString(), PublicSpendKey = accountDescriptor.PublicSpendKey.ToHexString(), SecretViewKey = accountDescriptor.SecretViewKey.ToHexString(), PublicViewKey = accountDescriptor.PublicViewKey.ToHexString() }; _logger.LogIfDebug(() => $"[{accountDto.AccountId}]: Authenticated account {JsonConvert.SerializeObject(forLog)}"); return(Ok(_translatorsRepository.GetInstance <AccountDescriptor, AccountDto>().Translate(accountDescriptor))); }
public void Initialize(CancellationToken cancellationToken) { _logger.Info($"Initializing {nameof(O10InherenceService)}"); InherenceSetting inherenceSetting = _dataAccessService.GetInherenceSetting(Name); if (inherenceSetting == null) { inherenceSetting = CreateO10Inherence(); } AccountId = inherenceSetting.AccountId; _logger.LogIfDebug(() => $"[{AccountId}]: {nameof(Initialize)} proceeding"); AccountDescriptor accountDescriptor = _accountsService.GetById(inherenceSetting.AccountId); if (accountDescriptor == null) { _dataAccessService.RemoveInherenceSetting(Name); inherenceSetting = CreateO10Inherence(); accountDescriptor = _accountsService.Authenticate(inherenceSetting.AccountId, GetDefaultO10InherencePassword()); if (accountDescriptor == null) { throw new Exception($"{nameof(O10InherenceService)} initialization failed"); } } else { accountDescriptor = _accountsService.Authenticate(inherenceSetting.AccountId, GetDefaultO10InherencePassword()); } _logger.Info($"[{AccountId}]: Invoking InitializeStateExecutionServices"); _executionContextManager .InitializeStateExecutionServices( accountDescriptor.AccountId, accountDescriptor.SecretSpendKey, new Func <long, IStateTransactionsService, IStateClientCryptoService, CancellationToken, IUpdater>( (accountId, stateTransactionsService, stateClientSryptoService, ct) => { _clientCryptoService = stateClientSryptoService; return(this); })); Target = accountDescriptor.PublicSpendKey.ToHexString(); cancellationToken.Register(() => { _executionContextManager.UnregisterExecutionServices(AccountId); }); }
public IActionResult SetPollState(long pollId, [FromBody] SetPollStateRequest request) { if (request is null) { throw new ArgumentNullException(nameof(request)); } var poll = _electionCommitteeService.SetPollState(pollId, request.State); var pollModel = _dataAccessService.GetEcPoll(pollId); var account = _dataAccessService.GetAccount(pollModel.AccountId); if (poll.State == PollState.Started) { _executionContextManager.InitializeStateExecutionServices(account.AccountId, account.SecretSpendKey); _electionCommitteeService.IssueVotersRegistrations(pollId, request.SourceAccountId); } else { _executionContextManager.UnregisterExecutionServices(pollModel.AccountId); } return(Ok(poll)); }