Example #1
0
        /// <summary>
        /// Rest definition creator
        /// </summary>
        private static RestDefinition CreateRestDefinition()
        {
            // Security settings
            String security = null;

            //var m_masterConfig = ApplicationServiceContext.Current.GetService<IConfigurationManager>().GetSection<RestConfigurationSection>();
            //var authorizationPolicy = m_masterConfig.Services.FirstOrDefault(o => o.Name == "FHIR").Behaviors.Select(o => o.GetCustomAttribute<AuthenticationSchemeDescriptionAttribute>()).FirstOrDefault(o => o != null)?.Scheme;
            if (ApplicationServiceContext.Current.GetService <FhirMessageHandler>().Capabilities.HasFlag(ServiceEndpointCapabilities.BasicAuth))
            {
                security = "Basic";
            }
            if (ApplicationServiceContext.Current.GetService <FhirMessageHandler>().Capabilities.HasFlag(ServiceEndpointCapabilities.BearerAuth))
            {
                security = "OAuth";
            }

            var retVal = new RestDefinition()
            {
                Mode          = "server",
                Documentation = "Default WCF REST Handler",
                Security      = new SecurityDefinition()
                {
                    Cors    = true,
                    Service = security == null ? null : new List <DataTypes.FhirCodeableConcept>()
                    {
                        new DataTypes.FhirCodeableConcept(new Uri("http://hl7.org/fhir/restful-security-service"), security)
                    }
                },
                Resource = FhirResourceHandlerUtil.GetRestDefinition().ToList()
            };

            return(retVal);
        }
Example #2
0
        /// <summary>
        /// Rest definition creator
        /// </summary>
        private static RestDefinition CreateRestDefinition()
        {
            // Security settings
            String security            = null;
            var    authorizationPolicy = OperationContext.Current.Host.Authorization.ExternalAuthorizationPolicies.Select(o => o.GetType().GetCustomAttribute <AuthenticationSchemeDescriptionAttribute>()?.Scheme)?.Where(o => o != null)?.FirstOrDefault();

            if (authorizationPolicy.HasValue)
            {
                switch (authorizationPolicy.Value)
                {
                case AuthenticationScheme.Basic:
                    security = "Basic";
                    break;

                case AuthenticationScheme.OAuth:
                case AuthenticationScheme.OAuth2:
                    security = "OAuth";
                    break;

                case AuthenticationScheme.Custom:
                    security = "SMART-on-FHIR";
                    break;
                }
            }

            var retVal = new RestDefinition()
            {
                Mode          = "server",
                Documentation = "Default WCF REST Handler",
                Security      = new SecurityDefinition()
                {
                    Cors    = true,
                    Service = security == null ? null : new List <DataTypes.FhirCodeableConcept>()
                    {
                        new DataTypes.FhirCodeableConcept(new Uri("http://hl7.org/fhir/restful-security-service"), security)
                    }
                },
                Resource = FhirResourceHandlerUtil.GetRestDefinition().ToList()
            };

            return(retVal);
        }