public ServerProxyWithChunking(string serverUri, ICredentials credentials, IAsyncWorker worker)
        {
            IsAuthorized = true;
            VerifyArgument.IsNotNull("serverUri", serverUri);
            ServerEvents = EventPublishers.Studio;

            var uriString = serverUri;

            if (!serverUri.EndsWith("dsf"))
            {
                uriString = serverUri + (serverUri.EndsWith("/") ? "" : "/") + "dsf";
            }
            AppServerUri = new Uri(uriString);
            WebServerUri = new Uri(uriString.Replace("/dsf", ""));


            Dev2Logger.Log.Debug("***** Attempting Server Hub : " + uriString + " -> " + CredentialCache.DefaultNetworkCredentials.Domain + @"\" + CredentialCache.DefaultNetworkCredentials.UserName);
            HubConnection = new HubConnectionWrapperOld(uriString)
            {
                Credentials = credentials
            };
            HubConnection.Error        += OnHubConnectionError;
            HubConnection.Closed       += HubConnectionOnClosed;
            HubConnection.StateChanged += HubConnectionStateChanged;
            InitializeEsbProxy();
            _asyncWorker = worker;
        }
示例#2
0
        protected virtual string ConnectToServer(Dev2.Data.ServiceModel.Connection connection)
        {
            // we need to grab the principle and impersonate to properly execute in context of the requesting user ;)
            var principle = Thread.CurrentPrincipal;
            var identity  = principle.Identity as WindowsIdentity;
            WindowsImpersonationContext context = null;

            try
            {
                if (identity != null && connection.AuthenticationType == AuthenticationType.Windows)
                {
                    context = identity.Impersonate();
                }

                using (var client = new WebClient())
                {
                    if (connection.AuthenticationType == AuthenticationType.Windows)
                    {
                        client.UseDefaultCredentials = true;
                    }
                    else
                    {
                        client.UseDefaultCredentials = false;

                        //// we to default to the hidden public user name of \, silly know but that is how to get around ntlm auth ;)
                        if (connection.AuthenticationType == AuthenticationType.Public)
                        {
                            connection.UserName = GlobalConstants.PublicUsername;
                            connection.Password = string.Empty;
                        }

                        client.Credentials = new NetworkCredential(connection.UserName, connection.Password);
                    }

                    // Need to do hub connect here to get true permissions ;)
                    HubConnection hub = null;
                    try
                    {
                        // Credentials = client.Credentials
                        hub = new HubConnection(connection.FetchTestConnectionAddress())
                        {
                            Credentials = client.Credentials
                        };
                        ServicePointManager.ServerCertificateValidationCallback = ValidateServerCertificate;
#pragma warning disable 168
                        var proxy = hub.CreateHubProxy("esb"); // this is the magic line that causes proper validation
#pragma warning restore 168
                        hub.Start().Wait();

                        Dev2Logger.Log.Debug("Hub State : " + hub.State);

                        return("Success");
                    }
                    catch (Exception)
                    {
                        // Credentials = client.Credentials
                        var hub2 = new HubConnectionWrapperOld(connection.FetchTestConnectionAddress())
                        {
                            Credentials = client.Credentials
                        };
                        ServicePointManager.ServerCertificateValidationCallback = ValidateServerCertificate;
#pragma warning disable 168
                        var proxy = hub2.CreateHubProxy("esb");     // this is the magic line that causes proper validation
#pragma warning restore 168
                        hub2.Start().Wait();

                        Dev2Logger.Log.Debug("Hub State : " + hub2.State);

                        return("Success");
                    }
                    finally
                    {
                        if (hub != null)
                        {
                            hub.Stop();
                            hub.Dispose();
                        }
                    }
                }
            }
            finally
            {
                if (context != null && connection.AuthenticationType == AuthenticationType.Windows)
                {
                    context.Undo();
                }
            }
        }