Exemplo n.º 1
0
        private void SetupIdentityProviders(ScenarioDefinition scenarioDefinition, long scenarioSessionId)
        {
            foreach (var scenarioAccount in scenarioDefinition.Setup.Accounts.Where(a => a.AccountType == AccountType.IdentityProvider))
            {
                long accountId = _accountsService.Create(AccountType.IdentityProvider, scenarioAccount.AccountInfo, "qqq", true);
                _dataAccessService.AddScenarionSessionAccount(scenarioSessionId, accountId);
                AccountDescriptor accountDescriptor = _accountsService.Authenticate(accountId, "qqq");
                _executionContextManager.InitializeStateExecutionServices(accountId, accountDescriptor.SecretSpendKey);

                foreach (var attributeScheme in scenarioAccount.IdentityScheme)
                {
                    long schemeId = _dataAccessService.AddAttributeToScheme(accountDescriptor.PublicSpendKey.ToHexString(), attributeScheme.AttributeName, attributeScheme.AttributeSchemeName, attributeScheme.Alias, null);

                    if (attributeScheme.CanBeRoot)
                    {
                        _dataAccessService.ToggleOnRootAttributeScheme(schemeId);
                    }
                }

                IdentitiesScheme rootScheme = _dataAccessService.GetRootIdentityScheme(accountDescriptor.PublicSpendKey.ToHexString());
                foreach (var identity in scenarioAccount.Identities)
                {
                    IEnumerable <(string attributeName, string content)> attrs = GetAttribitesAndContent(identity, accountDescriptor);
                    Identity identityDb = _dataAccessService.CreateIdentity(accountDescriptor.AccountId, identity.Alias, attrs.ToArray());
                }
            }
        }
Exemplo n.º 2
0
        public Poll RegisterPoll(string name)
        {
            var accountId = _accountsService.Create(DataLayer.Enums.AccountType.IdentityProvider, name, "qqq", true);
            var account   = _accountsService.GetById(accountId);
            var issuer    = account.PublicSpendKey.ToHexString();

            var attributeDefitions = new List <AttributeDefinition> {
                new AttributeDefinition
                {
                    IsRoot        = true,
                    AttributeName = "VoterNumber",
                    SchemeName    = AttributesSchemes.ATTR_SCHEME_NAME_IDCARD,
                    Alias         = "Voter Number"
                }
            };

            attributeDefitions.ForEach(a =>
            {
                var schemeId = _dataAccessService.AddAttributeToScheme(issuer, a.AttributeName, a.SchemeName, a.Alias, a.Description);
                if (a.IsRoot)
                {
                    _dataAccessService.ToggleOnRootAttributeScheme(schemeId);
                }
            });


            var id = _dataAccessService.AddPoll(name, accountId);

            return(FetchPoll(id));
        }
Exemplo n.º 3
0
        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 ActionResult <AttributeDefinition[]> SetAttributeDefinitions(string issuer, [FromBody] AttributeDefinition[] attributeDefinitions)
        {
            IEnumerable <IdentitiesScheme> identitiesSchemes = _dataAccessService.GetAttributesSchemeByIssuer(issuer).Where(a => a.AttributeSchemeName != AttributesSchemes.ATTR_SCHEME_NAME_PASSWORD);

            List <AttributeDefinition> newAttributeDefinitions = attributeDefinitions.Where(a => !identitiesSchemes.Any(i => i.AttributeSchemeName == a.SchemeName)).ToList();

            newAttributeDefinitions.ForEach(a =>
            {
                a.SchemeId = _dataAccessService.AddAttributeToScheme(issuer, a.AttributeName, a.SchemeName, a.Alias, a.Description);
            });

            identitiesSchemes.Where(i => i.IsActive && attributeDefinitions.All(a => a.AttributeName != i.AttributeName)).ToList().ForEach(a =>
            {
                _dataAccessService.DeactivateAttribute(a.IdentitiesSchemeId);
            });

            identitiesSchemes.Where(i => !i.IsActive && attributeDefinitions.Any(a => a.AttributeName == i.AttributeName)).ToList().ForEach(a =>
            {
                _dataAccessService.ActivateAttribute(a.IdentitiesSchemeId);
            });

            AttributeDefinition rootAttributeDefinition = attributeDefinitions.FirstOrDefault(a => a.IsRoot);

            if (rootAttributeDefinition != null)
            {
                _dataAccessService.ToggleOnRootAttributeScheme(rootAttributeDefinition.SchemeId);
            }
            else
            {
                _dataAccessService.ToggleOffRootAttributeSchemes(issuer);
            }

            return(_dataAccessService.GetAttributesSchemeByIssuer(issuer, true)
                   .Where(a => a.AttributeSchemeName != AttributesSchemes.ATTR_SCHEME_NAME_PASSWORD)
                   .Select(a => new AttributeDefinition
            {
                SchemeId = a.IdentitiesSchemeId,
                AttributeName = a.AttributeName,
                SchemeName = a.AttributeSchemeName,
                Alias = a.Alias,
                Description = a.Description,
                IsActive = a.IsActive,
                IsRoot = a.CanBeRoot
            }).ToArray());
        }
Exemplo n.º 5
0
        public async Task <ActionResult <AttributeDefinitionsResponse> > SetAttributeDefinitions(string issuer, [FromBody] AttributeDefinition[] attributeDefinitions)
        {
            IEnumerable <IdentitiesScheme> identitiesSchemes = _dataAccessService.GetAttributesSchemeByIssuer(issuer).Where(a => a.AttributeSchemeName != AttributesSchemes.ATTR_SCHEME_NAME_PASSWORD);

            List <AttributeDefinition> newAttributeDefinitions = attributeDefinitions.Where(a => !identitiesSchemes.Any(i => i.AttributeSchemeName == a.SchemeName)).ToList();

            newAttributeDefinitions.ForEach(a =>
            {
                a.SchemeId = _dataAccessService.AddAttributeToScheme(issuer, a.AttributeName, a.SchemeName, a.Alias, a.Description);
            });

            identitiesSchemes.Where(i => i.IsActive && attributeDefinitions.All(a => a.AttributeName != i.AttributeName)).ToList().ForEach(a =>
            {
                _dataAccessService.DeactivateAttribute(a.IdentitiesSchemeId);
            });

            identitiesSchemes.Where(i => !i.IsActive && attributeDefinitions.Any(a => a.AttributeName == i.AttributeName)).ToList().ForEach(a =>
            {
                _dataAccessService.ActivateAttribute(a.IdentitiesSchemeId);
            });

            AttributeDefinition rootAttributeDefinition = attributeDefinitions.FirstOrDefault(a => a.IsRoot);

            if (rootAttributeDefinition != null)
            {
                _dataAccessService.ToggleOnRootAttributeScheme(rootAttributeDefinition.SchemeId);
            }
            else
            {
                _dataAccessService.ToggleOffRootAttributeSchemes(issuer);
            }

            var accountDescriptor = _accountsService.GetByPublicKey(issuer.HexStringToByteArray());

            ActionStatus actionStatus       = null;
            string       integrationKey     = _dataAccessService.GetAccountKeyValue(accountDescriptor.AccountId, _integrationIdPRepository.IntegrationKeyName);
            var          integrationService = _integrationIdPRepository.GetInstance(integrationKey);

            if (integrationService != null)
            {
                var definitions = _dataAccessService.GetAttributesSchemeByIssuer(issuer, true)
                                  .Select(
                    a => new AttributeDefinition
                {
                    SchemeId      = a.IdentitiesSchemeId,
                    AttributeName = a.AttributeName,
                    SchemeName    = a.AttributeSchemeName,
                    Alias         = a.Alias,
                    Description   = a.Description,
                    IsActive      = a.IsActive,
                    IsRoot        = a.CanBeRoot
                }).ToArray();
                actionStatus = await integrationService.StoreScheme(accountDescriptor.AccountId, definitions).ConfigureAwait(false);
            }

            AttributeDefinitionsResponse response = new AttributeDefinitionsResponse
            {
                IntegrationActionStatus = actionStatus,
                AttributeDefinitions    = _dataAccessService.GetAttributesSchemeByIssuer(issuer, true)
                                          .Where(a => a.AttributeSchemeName != AttributesSchemes.ATTR_SCHEME_NAME_PASSWORD)
                                          .Select(a => new AttributeDefinition
                {
                    SchemeId      = a.IdentitiesSchemeId,
                    AttributeName = a.AttributeName,
                    SchemeName    = a.AttributeSchemeName,
                    Alias         = a.Alias,
                    Description   = a.Description,
                    IsActive      = a.IsActive,
                    IsRoot        = a.CanBeRoot
                }).ToArray()
            };

            return(response);
        }