Beispiel #1
0
        ServiceEndpoint[] GetServiceBusEndpoints()
        {
            string serviceNamespace = ServiceBusHelper.ExtractNamespace(new Uri(m_MexAddressTextBox.Text));
            string issuer           = m_NamespaceCredentials[serviceNamespace].Credentials.SharedSecret.IssuerName;
            string secret           = m_NamespaceCredentials[serviceNamespace].Credentials.SharedSecret.IssuerSecret;

            return(ServiceBusMetadataHelper.GetEndpoints(m_MexAddressTextBox.Text, issuer, secret));
        }
Beispiel #2
0
        void OnServiceBusLogOn(object sender, EventArgs e)
        {
            string serviceNamespace = "";

            if (IsServiceBusAddress(m_MexAddressTextBox.Text))
            {
                serviceNamespace = ServiceBusHelper.ExtractNamespace(new Uri(m_MexAddressTextBox.Text));
            }

LOGIN:
            LogonDialog dialog = new LogonDialog(serviceNamespace, ServiceBusHelper.DefaultIssuer);

            dialog.ShowDialog();

            if (IsServiceBusAddress(m_MexAddressTextBox.Text) == false)
            {
                try
                {
                    m_MexAddressTextBox.Text = ServiceBusEnvironment.CreateServiceUri("sb", dialog.ServiceNamespace, "").AbsoluteUri;
                }
                catch
                {
                    System.Windows.Forms.DialogResult result = System.Windows.Forms.MessageBox.Show("Invalid service namespace", "MEX Explorer", System.Windows.Forms.MessageBoxButtons.RetryCancel, System.Windows.Forms.MessageBoxIcon.Error);
                    if (result == System.Windows.Forms.DialogResult.Retry)
                    {
                        goto LOGIN;
                    }
                    else
                    {
                        return;
                    }
                }
            }


            TransportClientEndpointBehavior credentials = new TransportClientEndpointBehavior();

            credentials.CredentialType = TransportClientCredentialType.SharedSecret;
            credentials.Credentials.SharedSecret.IssuerName   = dialog.Issuer;
            credentials.Credentials.SharedSecret.IssuerSecret = dialog.Secret;

            m_NamespaceCredentials[dialog.ServiceNamespace] = credentials;
        }
        void ExploreServiceBus()
        {
            string mexAddress = m_MexAddressTextBox.Text;

            if (IsServiceBusAddress(mexAddress))
            {
                if (m_NamespaceCredentials.ContainsKey(ServiceBusHelper.ExtractNamespace(new Uri(mexAddress))) == false)
                {
                    OnServiceBusLogOn(this, EventArgs.Empty);
                }
            }

            SplashScreen splash = new SplashScreen(Resources.Progress);

            try
            {
                ExploreServiceBus(mexAddress);
            }
            finally
            {
                splash.Close();
                m_ExploreButton.Enabled = true;
            }
        }
Beispiel #4
0
        public void Validate(ServiceDescription description, ServiceHostBase serviceHostBase)
        {
            if (m_SubjectName != null)
            {
                switch (m_Mode)
                {
                case ServiceSecurity.Anonymous:
                case ServiceSecurity.BusinessToBusiness:
                case ServiceSecurity.Internet:
                {
                    string subjectName;
                    if (m_SubjectName != String.Empty)
                    {
                        subjectName = m_SubjectName;
                    }
                    else
                    {
                        subjectName = description.Endpoints[0].Address.Uri.Host;
                    }
                    serviceHostBase.Credentials.ServiceCertificate.SetCertificate(m_StoreLocation, m_StoreName, m_FindType, subjectName);
                    break;
                }

                case ServiceSecurity.ServiceBus:
                {
                    string subjectName;
                    if (m_SubjectName != String.Empty)
                    {
                        subjectName = m_SubjectName;
                    }
                    else
                    {
                        subjectName = ServiceBusHelper.ExtractNamespace(description.Endpoints[0].Address.Uri);
                    }

                    serviceHostBase.Credentials.ServiceCertificate.SetCertificate(m_StoreLocation, m_StoreName, m_FindType, subjectName);

                    break;
                }
                }
            }
            else
            {
                switch (m_Mode)
                {
                case ServiceSecurity.Anonymous:
                case ServiceSecurity.BusinessToBusiness:
                case ServiceSecurity.Internet:
                {
                    string subjectName = description.Endpoints[0].Address.Uri.Host;
                    serviceHostBase.Credentials.ServiceCertificate.SetCertificate(m_StoreLocation, m_StoreName, m_FindType, subjectName);
                    break;
                }

                case ServiceSecurity.ServiceBus:
                {
                    string subjectName = ServiceBusHelper.ExtractNamespace(description.Endpoints[0].Address.Uri);
                    serviceHostBase.Credentials.ServiceCertificate.SetCertificate(m_StoreLocation, m_StoreName, m_FindType, subjectName);
                    break;
                }
                }
            }
            if (UseAspNetProviders == true)
            {
                Debug.Assert(serviceHostBase.Credentials != null);
                serviceHostBase.Authorization.PrincipalPermissionMode = PrincipalPermissionMode.UseAspNetRoles;
                string applicationName;
                Debug.Assert(Roles.ApplicationName == Membership.ApplicationName);
                if (String.IsNullOrEmpty(ApplicationName))
                {
                    ApplicationName = Membership.ApplicationName;
                }
                if (String.IsNullOrEmpty(ApplicationName) || ApplicationName == "/")
                {
                    if (String.IsNullOrEmpty(Assembly.GetEntryAssembly().GetName().Name))
                    {
                        applicationName = AppDomain.CurrentDomain.FriendlyName;
                    }
                    else
                    {
                        applicationName = Assembly.GetEntryAssembly().GetName().Name;
                    }
                }
                else
                {
                    applicationName = ApplicationName;
                }
                Membership.ApplicationName = applicationName;
                Roles.ApplicationName      = applicationName;

                if (m_Mode == ServiceSecurity.Internet)
                {
                    serviceHostBase.Credentials.UserNameAuthentication.UserNamePasswordValidationMode = UserNamePasswordValidationMode.MembershipProvider;
                }
            }
            else
            {
                Debug.Assert(m_ApplicationName == null);
                //Reiterate the defaults
                serviceHostBase.Credentials.UserNameAuthentication.UserNamePasswordValidationMode = UserNamePasswordValidationMode.Windows;
                serviceHostBase.Authorization.PrincipalPermissionMode = PrincipalPermissionMode.UseWindowsGroups;
            }
            if (m_Mode == ServiceSecurity.Anonymous || m_Mode == ServiceSecurity.BusinessToBusiness && UseAspNetProviders == false)
            {
                serviceHostBase.Authorization.PrincipalPermissionMode = PrincipalPermissionMode.None;
            }

            //Make it affect only when possible
            if (ImpersonateAll)
            {
                if (m_Mode == ServiceSecurity.Intranet || (m_Mode == ServiceSecurity.Internet && UseAspNetProviders == false))
                {
                    return;
                }
                else
                {
                    ImpersonateAll = false;
                }
            }
            if (m_Mode == ServiceSecurity.BusinessToBusiness)
            {
                serviceHostBase.Credentials.ClientCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.PeerTrust;
            }
        }
        ServiceEndpoint[] GetServiceBusEndpoints()
        {
            string serviceNamespace = ServiceBusHelper.ExtractNamespace(new Uri(m_MexAddressTextBox.Text));

            return(ServiceBusMetadataHelper.GetEndpoints(m_MexAddressTextBox.Text, m_NamespaceCredentials[serviceNamespace]));
        }
        void OnConfigureDiscovery(object sender, EventArgs e)
        {
            string serviceNamespace = "";

            if (IsServiceBusAddress(m_MexAddressTextBox.Text))
            {
                serviceNamespace = ServiceBusHelper.ExtractNamespace(new Uri(m_MexAddressTextBox.Text));
            }

            bool announcementsEnables = m_ServiceBusAnnouncementSinks.ContainsKey(serviceNamespace);

            if (m_DisoveryPaths.ContainsKey(serviceNamespace) == false)
            {
                m_DisoveryPaths[serviceNamespace] = DiscoverableServiceHost.DiscoveryPath;
            }

            if (m_AnnouncementsPaths.ContainsKey(serviceNamespace) == false)
            {
                m_AnnouncementsPaths[serviceNamespace] = DiscoverableServiceHost.AnnouncementsPath;
            }

            DiscoveryDialog dialog = new DiscoveryDialog(serviceNamespace, m_DisoveryPaths[serviceNamespace], announcementsEnables, m_AnnouncementsPaths[serviceNamespace]);

            dialog.ShowDialog();

            serviceNamespace = dialog.ServiceNamespace;

            m_MexAddressTextBox.Text = ServiceBusEnvironment.CreateServiceUri("sb", serviceNamespace, "").AbsoluteUri;

            m_DisoveryPaths[serviceNamespace] = dialog.DiscoveryPath;

            if (String.IsNullOrWhiteSpace(dialog.AnnouncementsPath) == false)
            {
                m_AnnouncementsPaths[serviceNamespace] = dialog.AnnouncementsPath;

                if (m_NamespaceCredentials.ContainsKey(ServiceBusHelper.ExtractNamespace(new Uri(m_MexAddressTextBox.Text))) == false)
                {
                    OnServiceBusLogOn(this, EventArgs.Empty);
                }

                Uri newAnouncementsAddress = ServiceBusEnvironment.CreateServiceUri("sb", serviceNamespace, m_AnnouncementsPaths[serviceNamespace]);

                if (m_ServiceBusAnnouncementSinks.ContainsKey(serviceNamespace))
                {
                    if (m_ServiceBusAnnouncementSinks[serviceNamespace].AnnouncementsAddress.AbsoluteUri != newAnouncementsAddress.AbsoluteUri)
                    {
                        m_ServiceBusAnnouncementSinks[serviceNamespace].Close();
                        m_ServiceBusAnnouncementSinks.Remove(serviceNamespace);
                    }
                    else
                    {
                        return;
                    }
                }

                TokenProvider tokenPorvider = m_NamespaceCredentials[serviceNamespace];

                m_ServiceBusAnnouncementSinks[serviceNamespace] = new ServiceBusAnnouncementSink <IMetadataExchange>(serviceNamespace, tokenPorvider);
                m_ServiceBusAnnouncementSinks[serviceNamespace].AnnouncementsAddress = newAnouncementsAddress;

                m_ServiceBusAnnouncementSinks[serviceNamespace].OnlineAnnouncementReceived  += OnHelloNotice;
                m_ServiceBusAnnouncementSinks[serviceNamespace].OfflineAnnouncementReceived += OnByeNotice;

                m_ServiceBusAnnouncementSinks[serviceNamespace].Open();
            }
            else
            {
                if (m_ServiceBusAnnouncementSinks.ContainsKey(serviceNamespace))
                {
                    m_ServiceBusAnnouncementSinks[serviceNamespace].Close();
                    m_ServiceBusAnnouncementSinks.Remove(serviceNamespace);
                }
            }
        }