Esempio n. 1
0
        /// <summary>
        /// Can only call before using the proxy for the first time
        /// </summary>
        public static void UnsecuredProxy <T>(this ClientBase <T> proxy) where T : class
        {
            if (proxy.State == CommunicationState.Opened)
            {
                throw new InvalidOperationException("Proxy channel is already opened");
            }
            ServiceEndpoint[] endpoints = { proxy.Endpoint };

            SecurityBehavior.ConfigureNone(endpoints);
        }
Esempio n. 2
0
      /// <summary>
      /// Can only call before using the proxy for the first time
      /// </summary>
      public static void UnsecuredProxy<T>(ClientBase<T> proxy) where T : class
      {
         if(proxy.State == CommunicationState.Opened)
         {
            throw new InvalidOperationException("Proxy channel is already opened");
         }
         Collection<ServiceEndpoint> endpoints = new Collection<ServiceEndpoint>();
         endpoints.Add(proxy.Endpoint);

         SecurityBehavior.ConfigureNone(endpoints);
      }
Esempio n. 3
0
        /// <summary>
        /// Can only call before using the proxy for the first time
        /// </summary>
        public static void AnonymousProxy <T>(this ClientBase <T> proxy) where T : class
        {
            if (proxy.State == CommunicationState.Opened)
            {
                throw new InvalidOperationException("Proxy channel is already opened");
            }
            ServiceEndpoint[] endpoints = { proxy.Endpoint };
            proxy.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.PeerTrust;

            SecurityBehavior.ConfigureAnonymous(endpoints);
        }
Esempio n. 4
0
        /// <summary>
        /// Can only call before using the proxy for the first time
        /// </summary>
        public static void SecureProxy <T>(this ClientBase <T> proxy, StoreLocation storeLocation, StoreName storeName, X509FindType findType, string clientCertificateName) where T : class
        {
            if (proxy.State == CommunicationState.Opened)
            {
                throw new InvalidOperationException("Proxy channel is already opened");
            }
            SetCertificate(proxy, storeLocation, storeName, findType, clientCertificateName);
            ServiceEndpoint[] endpoints = { proxy.Endpoint };

            proxy.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.PeerTrust;

            SecurityBehavior.ConfigureBusinessToBusiness(endpoints);
        }
Esempio n. 5
0
        public void SetCredentials(StoreLocation storeLocation, StoreName storeName, X509FindType findType, string clientCertificateName)
        {
            if (State == CommunicationState.Opened)
            {
                throw new InvalidOperationException("Proxy channel is already opened");
            }
            Credentials.ClientCertificate.SetCertificate(storeLocation, storeName, findType, clientCertificateName);

            Collection <ServiceEndpoint> endpoints = new Collection <ServiceEndpoint>();

            endpoints.Add(Endpoint);

            SecurityBehavior.ConfigureBusinessToBusiness(endpoints);
        }
Esempio n. 6
0
        /// <summary>
        /// Can only call before using the proxy for the first time
        /// </summary>
        public static void SecureProxy <T>(this ClientBase <T> proxy, string userName, string password) where T : class
        {
            if (proxy.State == CommunicationState.Opened)
            {
                throw new InvalidOperationException("Proxy channel is already opened");
            }
            ServiceEndpoint[] endpoints = { proxy.Endpoint };

            SecurityBehavior.ConfigureInternet(endpoints, true);//True even for Windows

            proxy.ClientCredentials.UserName.UserName = userName;
            proxy.ClientCredentials.UserName.Password = password;
            proxy.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.PeerTrust;
        }
Esempio n. 7
0
        /// <summary>
        /// Can only call before openning the host
        /// </summary>
        public static void SetSecurityBehavior(this ServiceHost host, ServiceSecurity mode, StoreLocation storeLocation, StoreName storeName, X509FindType findType, string serviceCertificateName, bool useAspNetProviders, string applicationName, bool impersonateAll)
        {
            if (host.State == CommunicationState.Opened)
            {
                throw new InvalidOperationException("Host is already opened");
            }
            SecurityBehavior securityBehavior = new SecurityBehavior(mode, storeLocation, storeName, findType, serviceCertificateName);

            securityBehavior.UseAspNetProviders = useAspNetProviders;
            securityBehavior.ApplicationName    = applicationName;
            securityBehavior.ImpersonateAll     = impersonateAll;

            host.Description.Behaviors.Add(securityBehavior);
        }
Esempio n. 8
0
        public static void SetCredentials <T>(this ChannelFactory <T> factory, StoreLocation storeLocation, StoreName storeName, X509FindType findType, string clientCertificateName)
        {
            if (factory.State == CommunicationState.Opened)
            {
                throw new InvalidOperationException("Proxy channel is already opened");
            }
            factory.Credentials.ClientCertificate.SetCertificate(storeLocation, storeName, findType, clientCertificateName);

            Collection <ServiceEndpoint> endpoints = new Collection <ServiceEndpoint>();

            endpoints.Add(factory.Endpoint);

            SecurityBehavior.ConfigureBusinessToBusiness(endpoints);
            factory.Credentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.PeerTrust;
        }
Esempio n. 9
0
        public void SetCredentials(string userName, string password)
        {
            if (State == CommunicationState.Opened)
            {
                throw new InvalidOperationException("Proxy channel is already opened");
            }
            Collection <ServiceEndpoint> endpoints = new Collection <ServiceEndpoint>();

            endpoints.Add(Endpoint);

            SecurityBehavior.ConfigureInternet(endpoints, true);//True even for Windows

            Credentials.UserName.UserName = userName;
            Credentials.UserName.Password = password;
        }
Esempio n. 10
0
        public static void SetCredentials <T, C>(this DuplexChannelFactory <T, C> factory, string userName, string password) where T : class
        {
            if (factory.State == CommunicationState.Opened)
            {
                throw new InvalidOperationException("Proxy channel is already opened");
            }
            Collection <ServiceEndpoint> endpoints = new Collection <ServiceEndpoint>();

            endpoints.Add(factory.Endpoint);

            SecurityBehavior.ConfigureInternet(endpoints, true);//True even for Windows

            factory.Credentials.UserName.UserName = userName;
            factory.Credentials.UserName.Password = password;

            factory.Credentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.PeerTrust;
        }
Esempio n. 11
0
        public static void SetCredentials <T, C>(this DuplexChannelFactory <T, C> factory, string domain, string userName, string password, TokenImpersonationLevel impersonationLevel) where T : class
        {
            if (factory.State == CommunicationState.Opened)
            {
                throw new InvalidOperationException("Proxy channel is already opened");
            }
            ServiceEndpoint[] endpoints = { factory.Endpoint };

            SecurityBehavior.ConfigureIntranet(endpoints);

            NetworkCredential credentials = new NetworkCredential();

            credentials.Domain   = domain;
            credentials.UserName = userName;
            credentials.Password = password;

            factory.Credentials.Windows.ClientCredential          = credentials;
            factory.Credentials.Windows.AllowedImpersonationLevel = impersonationLevel;
        }
Esempio n. 12
0
      /// <summary>
      /// Can only call before using the proxy for the first time
      /// </summary>
      public static void SecureProxy<T>(ClientBase<T> proxy,string domain,string userName,string password,TokenImpersonationLevel impersonationLevel) where T : class
      {
         if(proxy.State == CommunicationState.Opened)
         {
            throw new InvalidOperationException("Proxy channel is already opened");
         }
         Collection<ServiceEndpoint> endpoints = new Collection<ServiceEndpoint>();
         endpoints.Add(proxy.Endpoint);

         SecurityBehavior.ConfigureIntranet(endpoints);

         NetworkCredential credentials = new NetworkCredential();
         credentials.Domain   = domain;
         credentials.UserName = userName;
         credentials.Password = password;

         proxy.ClientCredentials.Windows.ClientCredential = credentials;
         proxy.ClientCredentials.Windows.AllowedImpersonationLevel = impersonationLevel;
      }
Esempio n. 13
0
        public static void SetSecurityMode <T, C>(this DuplexChannelFactory <T, C> factory, ServiceSecurity mode) where T : class
        {
            switch (mode)
            {
            case ServiceSecurity.None:
            {
                if (factory.State == CommunicationState.Opened)
                {
                    throw new InvalidOperationException("Proxy channel is already opened");
                }
                Collection <ServiceEndpoint> endpoints = new Collection <ServiceEndpoint>();
                endpoints.Add(factory.Endpoint);

                SecurityBehavior.ConfigureNone(endpoints);

                break;
            }

            case ServiceSecurity.Anonymous:
            {
                if (factory.State == CommunicationState.Opened)
                {
                    throw new InvalidOperationException("Proxy channel is already opened");
                }
                Collection <ServiceEndpoint> endpoints = new Collection <ServiceEndpoint>();
                endpoints.Add(factory.Endpoint);

                SecurityBehavior.ConfigureAnonymous(endpoints);

                factory.Credentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.PeerTrust;

                break;
            }

            default:
            {
                throw new InvalidOperationException(mode + " is unsupported with this constructor");
            }
            }
        }
Esempio n. 14
0
        public void SetSecurityMode(ServiceSecurity mode)
        {
            switch (mode)
            {
            case ServiceSecurity.None:
            {
                if (State == CommunicationState.Opened)
                {
                    throw new InvalidOperationException("Proxy channel is already opened");
                }
                Collection <ServiceEndpoint> endpoints = new Collection <ServiceEndpoint>();
                endpoints.Add(Endpoint);

                SecurityBehavior.ConfigureNone(endpoints);

                break;
            }

            case ServiceSecurity.Anonymous:
            {
                if (State == CommunicationState.Opened)
                {
                    throw new InvalidOperationException("Proxy channel is already opened");
                }
                Collection <ServiceEndpoint> endpoints = new Collection <ServiceEndpoint>();
                endpoints.Add(Endpoint);

                SecurityBehavior.ConfigureAnonymous(endpoints);
                break;
            }

            default:
            {
                throw new InvalidOperationException(mode + " is unsupported with this constructor");
            }
            }
        }
 public SecurityBehaviorAttribute(ServiceSecurity mode,StoreLocation storeLocation,StoreName storeName,X509FindType findType,string serviceCertificateName)
 {
     m_SecurityBehavior = new SecurityBehavior(mode,storeLocation,storeName,findType,serviceCertificateName);
 }
 /// <summary>
 /// </summary>
 /// <param name="mode">Certificate is looked up by name from LocalMachine/My store</param>
 public SecurityBehaviorAttribute(ServiceSecurity mode,string serviceCertificateName)
 {
     m_SecurityBehavior = new SecurityBehavior(mode,serviceCertificateName);
 }
 /// <summary>
 /// </summary>
 /// <param name="mode">If set to ServiceSecurity.Anonymous,ServiceSecurity.BusinessToBusiness or ServiceSecurity.Internet then the service certificate must be listed in config file</param>
 public SecurityBehaviorAttribute(ServiceSecurity mode)
 {
     m_SecurityBehavior = new SecurityBehavior(mode);
 }
Esempio n. 18
0
 /// <summary>
 /// </summary>
 /// <param name="mode">If set to ServiceSecurity.Anonymous,ServiceSecurity.BusinessToBusiness or ServiceSecurity.Internet then the service certificate must be listed in config file</param>
 public SecurityBehaviorAttribute(ServiceSecurity mode)
 {
     m_SecurityBehavior = new SecurityBehavior(mode);
 }
Esempio n. 19
0
 /// <summary>
 /// </summary>
 /// <param name="mode">Certificate is looked up by name from LocalMachine/My store</param>
 public SecurityBehaviorAttribute(ServiceSecurity mode, string serviceCertificateName)
 {
     m_SecurityBehavior = new SecurityBehavior(mode, serviceCertificateName);
 }
Esempio n. 20
0
 public SecurityBehaviorAttribute(ServiceSecurity mode, StoreLocation storeLocation, StoreName storeName, X509FindType findType, string serviceCertificateName)
 {
     m_SecurityBehavior = new SecurityBehavior(mode, storeLocation, storeName, findType, serviceCertificateName);
 }