Beispiel #1
0
        public WitsmlClientProvider(
            IConfiguration configuration,
            IHttpContextAccessor httpContextAccessor,
            ICredentialsService credentialsService,
            IOptions <WitsmlClientCapabilities> witsmlClientCapabilities)
        {
            if (httpContextAccessor.HttpContext == null || httpContextAccessor.HttpContext.Request.Headers["Authorization"].Count == 0)
            {
                return;
            }

            clientCapabilities = witsmlClientCapabilities.Value;

            var headers   = httpContextAccessor.HttpContext.Request.Headers;
            var serverUrl = headers[WitsmlServerUrlHeader];
            var witsmlServerAccessNeeded = !string.IsNullOrEmpty(serverUrl);

            if (!witsmlServerAccessNeeded)
            {
                return;
            }

            var credentials = ExtractCredentialsFromHeader(headers);

            //This provider will unintentionally be invoked also on initial authentication requests. Doing this to let the authentication route be triggered.
            var isEncrypted = credentialsService.VerifyIsEncrypted(credentials[0]);

            if (!isEncrypted)
            {
                return;
            }

            var logQueries = StringHelpers.ToBoolean(configuration["LogQueries"]);

            witsmlClient = new WitsmlClient(serverUrl, credentials[0].Username, credentialsService.Decrypt(credentials[0]), clientCapabilities, null, logQueries);

            var sourceServerUrl = headers[WitsmlSourceServerUrlHeader];

            if (string.IsNullOrEmpty(sourceServerUrl) && credentials.Count == 1)
            {
                return;
            }
            witsmlSourceClient = new WitsmlClient(sourceServerUrl, credentials[1].Username, credentialsService.Decrypt(credentials[1]), clientCapabilities, null, logQueries);
        }