コード例 #1
0
ファイル: SearchService.cs プロジェクト: usuyama/fhir-server
        public void Build(ListedCapabilityStatement statement)
        {
            foreach (var resource in ModelInfo.SupportedResources)
            {
                var resourceType = ModelInfo.FhirTypeNameToResourceType(resource).GetValueOrDefault();

                statement.TryAddRestInteraction(resourceType, CapabilityStatement.TypeRestfulInteraction.HistoryType);
                statement.TryAddRestInteraction(resourceType, CapabilityStatement.TypeRestfulInteraction.HistoryInstance);
            }

            var restComponent = statement
                                .Rest
                                .Single();

            if (restComponent.Interaction == null)
            {
                restComponent.Interaction = new List <CapabilityStatement.SystemInteractionComponent>();
            }

            restComponent.Interaction.Add(new CapabilityStatement.SystemInteractionComponent
            {
                Code = CapabilityStatement.SystemRestfulInteraction.HistorySystem,
            });
        }
コード例 #2
0
 public void AddExportDetails(ListedCapabilityStatement capabilityStatement)
 {
     GetAndAddOperationDefinitionUriToCapabilityStatement(capabilityStatement, OperationsConstants.Export);
     GetAndAddOperationDefinitionUriToCapabilityStatement(capabilityStatement, OperationsConstants.PatientExport);
     GetAndAddOperationDefinitionUriToCapabilityStatement(capabilityStatement, OperationsConstants.GroupExport);
 }
コード例 #3
0
 protected override void AddResourceCapability(ListedCapabilityStatement statement, ResourceType resourceType)
 {
     statement.TryAddRestInteraction(resourceType, CapabilityStatement.TypeRestfulInteraction.Create);
 }
コード例 #4
0
 protected virtual void AddResourceCapability(ListedCapabilityStatement statement, ResourceType resourceType)
 {
 }
コード例 #5
0
 public void AddMemberMatchDetails(ListedCapabilityStatement capabilityStatement)
 {
     GetAndAddOperationDefinitionUriToCapabilityStatement(capabilityStatement, OperationsConstants.MemberMatch);
 }
コード例 #6
0
 public void AddReindexDetails(ListedCapabilityStatement capabilityStatement)
 {
     GetAndAddOperationDefinitionUriToCapabilityStatement(capabilityStatement, OperationsConstants.Reindex);
     GetAndAddOperationDefinitionUriToCapabilityStatement(capabilityStatement, OperationsConstants.ResourceReindex);
 }
コード例 #7
0
 public void AddAnonymizedExportDetails(ListedCapabilityStatement capabilityStatement)
 {
     GetAndAddOperationDefinitionUriToCapabilityStatement(capabilityStatement, OperationsConstants.AnonymizedExport);
 }
コード例 #8
0
        private static void AddOAuthSecurityService(ListedCapabilityStatement statement, string authority, IHttpClientFactory httpClientFactory, ILogger logger)
        {
            EnsureArg.IsNotNull(statement, nameof(statement));
            EnsureArg.IsNotNull(authority, nameof(authority));
            EnsureArg.IsNotNull(httpClientFactory, nameof(httpClientFactory));

            ListedRestComponent restComponent = statement.Rest.Server();
            SecurityComponent   security      = restComponent.Security ?? new SecurityComponent();

            var codableConceptInfo = new Core.Models.CodableConceptInfo();

            security.Service.Add(codableConceptInfo);
            codableConceptInfo.Coding.Add(Constants.RestfulSecurityServiceOAuth.ToCoding());

            var openIdConfigurationUrl = $"{authority}/.well-known/openid-configuration";

            HttpResponseMessage openIdConfigurationResponse;

            using (HttpClient httpClient = httpClientFactory.CreateClient())
            {
                try
                {
                    openIdConfigurationResponse = httpClient.GetAsync(new Uri(openIdConfigurationUrl)).GetAwaiter().GetResult();
                }
                catch (Exception ex)
                {
                    logger.LogWarning(ex, $"There was an exception while attempting to read the OpenId Configuration from \"{openIdConfigurationUrl}\".");
                    throw new OpenIdConfigurationException();
                }
            }

            if (openIdConfigurationResponse.IsSuccessStatusCode)
            {
                JObject openIdConfiguration = JObject.Parse(openIdConfigurationResponse.Content.ReadAsStringAsync().GetAwaiter().GetResult());

                string tokenEndpoint, authorizationEndpoint;

                try
                {
                    tokenEndpoint         = openIdConfiguration["token_endpoint"].Value <string>();
                    authorizationEndpoint = openIdConfiguration["authorization_endpoint"].Value <string>();
                }
                catch (Exception ex)
                {
                    logger.LogWarning(ex, $"There was an exception while attempting to read the endpoints from \"{openIdConfigurationUrl}\".");
                    throw new OpenIdConfigurationException();
                }

                var smartExtension = new
                {
                    url       = Constants.SmartOAuthUriExtension,
                    extension = new[]
                    {
                        new
                        {
                            url      = Constants.SmartOAuthUriExtensionToken,
                            valueUri = tokenEndpoint,
                        },
                        new
                        {
                            url      = Constants.SmartOAuthUriExtensionAuthorize,
                            valueUri = authorizationEndpoint,
                        },
                    },
                };

                security.Extension.Add(JObject.FromObject(smartExtension));
            }
            else
            {
                logger.LogWarning($"The OpenId Configuration request from \"{openIdConfigurationUrl}\" returned an {openIdConfigurationResponse.StatusCode} status code.");
                throw new OpenIdConfigurationException();
            }

            restComponent.Security = security;
        }
コード例 #9
0
 public void AddConvertDataDetails(ListedCapabilityStatement capabilityStatement)
 {
     GetAndAddOperationDefinitionUriToCapabilityStatement(capabilityStatement, OperationsConstants.ConvertData);
 }
コード例 #10
0
        private void AddOAuthSecurityService(ListedCapabilityStatement statement)
        {
            ListedRestComponent restComponent = statement.Rest.Server();
            SecurityComponent   security      = restComponent.Security ?? new SecurityComponent();

            var codableConceptInfo = new CodableConceptInfo();

            security.Service.Add(codableConceptInfo);

            codableConceptInfo.Coding.Add(_modelInfoProvider.Version == FhirSpecification.Stu3
                ? Constants.RestfulSecurityServiceStu3OAuth
                : Constants.RestfulSecurityServiceOAuth);

            var openIdConfigurationUrl = $"{_securityConfiguration.Authentication.Authority}/.well-known/openid-configuration";

            HttpResponseMessage openIdConfigurationResponse;

            using (HttpClient httpClient = _httpClientFactory.CreateClient())
            {
                try
                {
                    openIdConfigurationResponse = httpClient.GetAsync(new Uri(openIdConfigurationUrl)).GetAwaiter().GetResult();
                }
                catch (Exception ex)
                {
                    _logger.LogWarning(ex, "There was an exception while attempting to read the OpenId Configuration from \"{openIdConfigurationUrl}\".", openIdConfigurationUrl);
                    throw new OpenIdConfigurationException();
                }
            }

            if (openIdConfigurationResponse.IsSuccessStatusCode)
            {
                JObject openIdConfiguration = JObject.Parse(openIdConfigurationResponse.Content.ReadAsStringAsync().GetAwaiter().GetResult());

                string tokenEndpoint, authorizationEndpoint;

                try
                {
                    tokenEndpoint         = openIdConfiguration["token_endpoint"].Value <string>();
                    authorizationEndpoint = openIdConfiguration["authorization_endpoint"].Value <string>();
                }
                catch (Exception ex)
                {
                    _logger.LogWarning(ex, "There was an exception while attempting to read the endpoints from \"{openIdConfigurationUrl}\".", openIdConfigurationUrl);
                    throw new OpenIdConfigurationException();
                }

                var smartExtension = new
                {
                    url       = Constants.SmartOAuthUriExtension,
                    extension = new[]
                    {
                        new
                        {
                            url      = Constants.SmartOAuthUriExtensionToken,
                            valueUri = tokenEndpoint,
                        },
                        new
                        {
                            url      = Constants.SmartOAuthUriExtensionAuthorize,
                            valueUri = authorizationEndpoint,
                        },
                    },
                };

                security.Extension.Add(JObject.FromObject(smartExtension));
            }
            else
            {
                _logger.LogWarning("The OpenId Configuration request from \"{openIdConfigurationUrl}\" returned an {statusCode} status code.", openIdConfigurationUrl, openIdConfigurationResponse.StatusCode);
                throw new OpenIdConfigurationException();
            }

            restComponent.Security = security;
        }