コード例 #1
0
        private async Task CreateApiResourceForApplicationOnIdentityServer(SecurityContractApplication applicationSecurityContractDefinition)
        {
            // Note: Always added 'permission' as the user claims that need to be mapped into access tokens for this API Resource.
            ApiResource identityServerApiResource = await identityApiResourceRespository.GetByNameAsync(applicationSecurityContractDefinition.Fullname);

            if (identityServerApiResource == null)
            {
                await identityApiResourceRespository.CreateAsync(applicationSecurityContractDefinition.Fullname, new[] { "permission" });
            }
            else
            {
                logger.Debug($"[applications.fullname: '{applicationSecurityContractDefinition.Fullname}']: The API Resource with name '{applicationSecurityContractDefinition.Fullname}' already exists on the Identity Server. Not creating a new one!");
            }
        }
コード例 #2
0
        private async Task <ApplicationModel> CreateNewResourceServer(SecurityContractApplication applicationSecurityContractDefinition, Guid updatedByGuid)
        {
            try
            {
                // Note: Always added 'permission' as the user claims that need to be mapped into access tokens for this API Resource.
                ApiResource identityServerApiResource = await identityApiResourceRespository.GetByNameAsync(applicationSecurityContractDefinition.Fullname);

                if (identityServerApiResource == null)
                {
                    await identityApiResourceRespository.CreateAsync(applicationSecurityContractDefinition.Fullname, new[] { "permission" });
                }
                else
                {
                    logger.Warn($"The API Resource with name '{applicationSecurityContractDefinition.Fullname}' already exists on the Identity Server. Not creating a new one!");
                }
            }
            catch (Exception e)
            {
                string errMessage = String.Format($"Error creating new resource on Identity Server: {e.Message}");
                logger.Error(errMessage);
                throw;
            }

            // Create the A3S representation of the resource.
            ApplicationModel application = new ApplicationModel
            {
                Name                    = applicationSecurityContractDefinition.Fullname,
                ChangedBy               = updatedByGuid,
                ApplicationFunctions    = new List <ApplicationFunctionModel>(),
                ApplicationDataPolicies = new List <ApplicationDataPolicyModel>()
            };

            if (applicationSecurityContractDefinition.ApplicationFunctions != null)
            {
                foreach (var function in applicationSecurityContractDefinition.ApplicationFunctions)
                {
                    application.ApplicationFunctions.Add(CreateNewFunctionFromResourceServerFunction(function, updatedByGuid));
                }
            }

            var newApplication = await applicationRepository.CreateAsync(application);

            return(await SynchroniseApplicationDataPoliciesWithSecurityContract(newApplication, applicationSecurityContractDefinition, updatedByGuid));
        }