コード例 #1
0
        private HttpRaftRequest CreateRequest(NodeConnectionInfo node, TimeSpan?timeout, string url, HttpMethod httpMethod, ILog logger)
        {
            if (timeout.HasValue == false)
            {
                timeout = TimeSpan.FromSeconds(20); // use default if not defined
            }

            var request = new HttpRaftRequest(node, url, httpMethod, info =>
            {
                HttpClient client;
                var dispose = (IDisposable)GetConnection(info, timeout.Value, out client);
                return(Tuple.Create(dispose, client));
            },
                                              _cancellationToken, logger)
            {
                UnauthorizedResponseAsyncHandler = HandleUnauthorizedResponseAsync,
                ForbiddenResponseAsyncHandler    = HandleForbiddenResponseAsync
            };

            GetAuthenticator(node).ConfigureRequest(this, new WebRequestEventArgs
            {
                Client      = request.HttpClient,
                Credentials = node.ToOperationCredentials()
            });
            return(request);
        }
コード例 #2
0
        private void AssertForbiddenCredentialSupportWindowsAuth(HttpResponseMessage response, NodeConnectionInfo nodeConnection)
        {
            if (nodeConnection.ToOperationCredentials().Credentials == null)
            {
                return;
            }

            var requiredAuth = response.Headers.GetFirstValue("Raven-Required-Auth");

            if (requiredAuth == "Windows")
            {
                // we are trying to do windows auth, but we didn't get the windows auth headers
                throw new SecurityException(
                          "Attempted to connect to a RavenDB Server that requires authentication using Windows credentials, but the specified server does not support Windows authentication." +
                          Environment.NewLine +
                          "If you are running inside IIS, make sure to enable Windows authentication.");
            }
        }
コード例 #3
0
        internal ReturnToQueue GetConnection(NodeConnectionInfo nodeConnection, out HttpClient result)
        {
            var connectionQueue = _httpClientsCache.GetOrAdd(nodeConnection.Name, _ => new ConcurrentQueue <HttpClient>());

            if (connectionQueue.TryDequeue(out result) == false)
            {
                var webRequestHandler = new WebRequestHandler
                {
                    UseDefaultCredentials = nodeConnection.HasCredentials() == false,
                    Credentials           = nodeConnection.ToOperationCredentials().Credentials
                };

                result = new HttpClient(webRequestHandler)
                {
                    BaseAddress = nodeConnection.Uri
                };
            }

            return(new ReturnToQueue(result, connectionQueue));
        }
コード例 #4
0
        private HttpRaftRequest CreateRequest(NodeConnectionInfo node, string url, HttpMethod httpMethod)
        {
            var request = new HttpRaftRequest(node, url, httpMethod, info =>
            {
                HttpClient client;
                var dispose = (IDisposable)GetConnection(info, out client);
                return(Tuple.Create(dispose, client));
            },
                                              _cancellationToken)
            {
                UnauthorizedResponseAsyncHandler = HandleUnauthorizedResponseAsync,
                ForbiddenResponseAsyncHandler    = HandleForbiddenResponseAsync
            };

            GetAuthenticator(node).ConfigureRequest(this, new WebRequestEventArgs
            {
                Client      = request.HttpClient,
                Credentials = node.ToOperationCredentials()
            });
            return(request);
        }