コード例 #1
0
        public virtual FindIdentitiesResponseObj FindIdentities()
        {
            log.Info(string.Format("Sending findIdentities request to IdentityRegistry"));
            var result = new FindIdentitiesResponseObj();

            try
            {
                var url = "/orgs?page=0&size=1000";

                var idRegService = new IdentityRegistryService();
                var response     = idRegService.MakeGenericCall(url, "GET");
                if (response.HttpStatusCode == HttpStatusCode.OK &&
                    !string.IsNullOrEmpty(response.Body) &&
                    response.Body.Length > 35)
                {
                    var responseObj = JsonConvert.DeserializeObject <IdRegistryResponeObject>(response.Body);
                    result.Organizations = responseObj.content;
                    result.StatusMessage = response.ErrorMessage;
                    result.StatusCode    = (int)response.HttpStatusCode;
                }

                return(result);
            }
            catch (Exception ex)
            {
                log.Error(ex.Message, ex);
                string msg      = "VIS internal server error. " + ex.Message;
                var    errorMsg = new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content      = new StringContent(msg),
                    ReasonPhrase = "Internal error."
                };

                throw new HttpResponseException(errorMsg);
            }
        }
コード例 #2
0
 public ServiceRegistryService()
 {
     serviceRegistryBasePath = ConfigurationManager.AppSettings.Get("ServiceRegistryBaseUrl");
     IdentityRegistryService = new IdentityRegistryService();
 }
コード例 #3
0
        public override void OnActionExecuting(HttpActionContext actionContext)
        {
            var serviceId = string.Empty;
            var orgId     = string.Empty;

            try
            {
                if (actionContext.ActionDescriptor.ActionName == "ping")
                {
                    serviceId = "Ping";
                    orgId     = "Ping";
                }
                else if (bool.Parse(ConfigurationManager.AppSettings.Get("BypassClientCertificateValidation")) == true)
                {
                    log.Warn("BypassClientCertificateValidation is set to true");
                    serviceId = ConfigurationManager.AppSettings.Get("IncomingServiceId");
                    orgId     = ConfigurationManager.AppSettings.Get("IncomingOrganizationId");
                }
                else
                {
                    // Validate client certificate
                    var cert  = actionContext.Request.GetClientCertificate();
                    var valid = new IdentityRegistryService().IsCertificateValid(cert);
                    if (!valid)
                    {
                        throw new AuthenticationException("Provided client certificate is not valid");
                    }

                    // Extract data from certifcate
                    var certData = cert.Subject.Split(',');

                    var certDataDictionary = new Dictionary <string, string>();
                    foreach (var item in certData)
                    {
                        var parts = item.Split('=');
                        if (parts != null && parts.Count() == 2)
                        {
                            if (parts[0].Trim().StartsWith("OID"))
                            {
                                serviceId = parts[1];;
                            }
                            if (parts[0].Trim() == "O")
                            {
                                orgId = parts[1];;
                            }
                            certDataDictionary.Add(parts[0].Trim(), parts[1].Trim());
                        }
                    }
                }

                InstanceContext.CallerOrgId     = orgId;
                InstanceContext.CallerServiceId = serviceId;
            }
            catch (AuthenticationException aex)
            {
                throw new HttpResponseException(new HttpResponseMessage
                {
                    ReasonPhrase = aex.Message,
                    StatusCode   = HttpStatusCode.Unauthorized
                });
            }
            catch (Exception ex)
            {
                log.Error(ex.Message, ex);
                throw;
            }

            log.Info(string.Format("Authenticated call from service id: {0}, org: {1} to url: {2}", serviceId, orgId, actionContext.Request.RequestUri));
        }