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());
        }
Beispiel #2
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);
        }