Пример #1
0
 public ActionResult DoStuff()
 {
     var channelFactory = new ChannelFactory<Services.IEchoClaimsChannel>("WS2007FederationHttpBinding_IEchoClaims");
     channelFactory.ConfigureChannelFactory();
     channelFactory.Credentials.SupportInteractive = false;
     var claimsPrincipal = Thread.CurrentPrincipal as IClaimsPrincipal;
     var channel = channelFactory.CreateChannelActingAs(claimsPrincipal.Identities.First().BootstrapToken);
     var success = false;
     try
     {
         var result = channel.Echo();
         if (channel.State != CommunicationState.Faulted)
         {
             channel.Close();
             success = true;
         }
         return View(model: result);
     }
     finally
     {
         if (!success)
         {
             channel.Abort();
         }
     }
 }
        public void TestGenevaWebserviceProvider_WithSSL()
        {
            X509Certificate2 sslCertJavaWSP = CertificateUtil.GetCertificate(StoreName.My, StoreLocation.LocalMachine, JavaWSPSSLCertificate);

            X509Certificate2 certificate2Client = CertificateUtil.GetCertificate(StoreName.My, StoreLocation.LocalMachine, SigningCertificateNameClient);

            //            Uri uri = new Uri("http://localhost:6020/Echo");
            Uri uri = new Uri("https://csky-pc/test/Service1.svc");
            EndpointAddress address = new EndpointAddress(uri);

            SecurityToken issuedToken = TestJavaSTSConnection.GetIssuedToken();

            using (ChannelFactory<IEchoService> factory = new ChannelFactory<IEchoService>(new ServiceproviderBinding(true), address))
            {
                factory.Endpoint.Contract.ProtectionLevel = ProtectionLevel.Sign;
                factory.ConfigureChannelFactory();
                factory.Credentials.ClientCertificate.Certificate = certificate2Client;
                factory.Credentials.ServiceCertificate.DefaultCertificate = CertificateUtil.GetCertificate(StoreName.My, StoreLocation.LocalMachine, "CN=STS");// SigningCertificateNameGenevaService);
                factory.Endpoint.Contract.ProtectionLevel = ProtectionLevel.Sign;

                var service = ChannelFactoryOperations.CreateChannelWithIssuedToken<IEchoService>(factory, issuedToken);

                Structure str = new Structure();
                str.value = "Badabam";
                var echoRequest = new echo();
                echoRequest.Framework = new LibertyFrameworkHeader();
                echoRequest.structureToEcho = str;

                var result = service.Echo(echoRequest);
                Assert.AreEqual("Badabam", result.structureToEcho.value);
            }
        }
        public void IsConfiguredAsFederated_ConfiguredIsCalled_ReturnsTrue()
        {
            // Arrange
            var channelFactory = new ChannelFactory<IService>(new BasicHttpBinding(), new EndpointAddress("http://localhost"));
            channelFactory.ConfigureChannelFactory();

            // Act
            var actual = channelFactory.IsConfiguredAsFederated();

            // Assert
            Assert.AreEqual(true, actual);
        }
        private static IService CreateProxy()
        {
            // request identity token from ADFS
            SecurityToken token = RequestIdentityToken();

            // set up factory and channel
            var binding = new WS2007FederationHttpBinding(WSFederationHttpSecurityMode.TransportWithMessageCredential);
            binding.Security.Message.EstablishSecurityContext = false;
            
            var factory = new ChannelFactory<IService>(binding, _serviceEndpoint);
            factory.Credentials.SupportInteractive = false;

            // enable WIF on channel factory
            factory.ConfigureChannelFactory();

            return factory.CreateChannelWithIssuedToken(token);
        }
Пример #5
0
        public static string ExecuteWS(string signingCertificateNameClient, string address, SecurityToken issuedToken)
        {
            X509Certificate2 certificate2Client = CertificateUtil.GetCertificate(StoreName.My, StoreLocation.LocalMachine, signingCertificateNameClient);
            ChannelFactory<IEchoService> factory = null;

            try
            {

                factory = new ChannelFactory<IEchoService>(new ServiceproviderBinding(false), address);
                factory.Endpoint.Contract.ProtectionLevel = ProtectionLevel.Sign;
                factory.ConfigureChannelFactory();
                factory.Credentials.ClientCertificate.Certificate = certificate2Client;
                factory.Credentials.ServiceCertificate.DefaultCertificate = CertificateUtil.GetCertificate(StoreName.My, StoreLocation.LocalMachine, "CN=STS");// SigningCertificateNameGenevaService);
                factory.Endpoint.Contract.ProtectionLevel = ProtectionLevel.Sign;

                var service = ChannelFactoryOperations.CreateChannelWithIssuedToken<IEchoService>(factory, issuedToken);

                Structure str = new Structure();
                str.value = "Testing .NET client";
                var echoRequest = new echo();
                echoRequest.Framework = new LibertyFrameworkHeader();
                echoRequest.structureToEcho = str;

                echoResponse result = null;
                result = service.Echo(echoRequest);

                return result.structureToEcho.value;
            }

            catch (Exception e)
            {
                if (factory != null && factory.State == CommunicationState.Opened)
                {
                    factory.Close();
                }

                throw;
            }
            finally
            {
                if (factory.State == CommunicationState.Opened)
                {
                    factory.Close();
                }
            }
        }
        private void _btnCallService_Click(object sender, RoutedEventArgs e)
        {
            var binding = new WS2007FederationHttpBinding(WSFederationHttpSecurityMode.TransportWithMessageCredential);
            binding.Security.Message.EstablishSecurityContext = false;
            binding.Security.Message.IssuedKeyType = SecurityKeyType.BearerKey;

            var ep = new EndpointAddress("https://" + Constants.WebHost + "/webservicesecurity/soap.svc/bearer");

            var factory = new ChannelFactory<IService>(binding, ep);
            factory.Credentials.SupportInteractive = false;
            factory.ConfigureChannelFactory();

            var channel = factory.CreateChannelWithIssuedToken(RSTR.SecurityToken);
            var claims = channel.GetClientIdentity();
            
            var sb = new StringBuilder(128);
            claims.ForEach(c => sb.AppendFormat("{0}\n {1}\n\n", c.ClaimType, c.Value));
            _txtDebug.Text = sb.ToString();
        }
        private static void CallMessage(SamlSecurityToken token)
        {
            var factory = new ChannelFactory<IServiceClientChannel>(
                new ClientSamlHttpBinding(SecurityMode.Message),
                new EndpointAddress(
                    new Uri("http://roadie:9000/Services/ClientSaml/Message"),
                    EndpointIdentity.CreateDnsIdentity("Service")));

            factory.Credentials.ServiceCertificate.SetDefaultCertificate(
                StoreLocation.CurrentUser,
                StoreName.My,
                X509FindType.FindBySubjectDistinguishedName,
                "CN=Service");

            factory.ConfigureChannelFactory<IServiceClientChannel>();
            var proxy = factory.CreateChannelWithIssuedToken<IServiceClientChannel>(token);

            proxy.Ping("foo");
            proxy.Close();
        }
        private static void CallMixedMode(SamlSecurityToken token)
        {
            var factory = new ChannelFactory<IServiceClientChannel>("*");

            factory.ConfigureChannelFactory<IServiceClientChannel>();
            var proxy = factory.CreateChannelWithIssuedToken<IServiceClientChannel>(token);

            proxy.Ping("foo");
            proxy.Close();
        }
        public void TestJavaWebserviceProviderWithSSL()
        {
            X509Certificate2 sslCertJavaWSP = CertificateUtil.GetCertificate(StoreName.My, StoreLocation.LocalMachine, JavaWSPSSLCertificate);

            X509Certificate2 certificate2Client = CertificateUtil.GetCertificate(StoreName.My, StoreLocation.LocalMachine, SigningCertificateNameClient);

            Uri uri = new Uri("https://172.16.232.1:8181/poc-provider/ProviderService");
            EndpointIdentity identity = EndpointIdentity.CreateX509CertificateIdentity(sslCertJavaWSP);

            EndpointAddress address = new EndpointAddress(uri, identity);

            SecurityToken issuedToken = TestJavaSTSConnection.GetIssuedToken(new Uri("https://172.16.232.1:8181/poc-provider/ProviderService"));
            ServicePointManager.ServerCertificateValidationCallback = delegate
            {
                return (true);
            };//Removes Validationcheck of SSL certificate, should not be here for Production.

            using (ChannelFactory<IEchoService> factory = new ChannelFactory<IEchoService>(new ServiceproviderBinding(true), address))
            {
                factory.Endpoint.Contract.ProtectionLevel = ProtectionLevel.Sign;
                factory.ConfigureChannelFactory();
                factory.Credentials.ClientCertificate.Certificate = certificate2Client;
                factory.Credentials.ServiceCertificate.DefaultCertificate = CertificateUtil.GetCertificate(StoreName.My, StoreLocation.LocalMachine, SigningCertificateNameJavaService);
                factory.Endpoint.Contract.ProtectionLevel = ProtectionLevel.Sign;

                var service = ChannelFactoryOperations.CreateChannelWithIssuedToken<IEchoService>(factory, issuedToken);

                Structure str = new Structure();
                str.value = "Badabam";
                var echoRequest = new echo();
                echoRequest.Framework = new LibertyFrameworkHeader();
                echoRequest.structureToEcho = str;

                var result = service.Echo(echoRequest);
                Assert.AreEqual("Badabam", result.structureToEcho.value);
            }
        }
        public void WrongProfileForLibertyHeader()
        {
            X509Certificate2 certificate2Client = CertificateUtil.GetCertificate(StoreName.My, StoreLocation.LocalMachine, SigningCertificateNameClient);

            Uri uri = new Uri("http://csky-pc/test/Service1.svc");
            
            EndpointAddress address = new EndpointAddress(uri);

            SecurityToken issuedToken = TestJavaSTSConnection.GetIssuedToken();

            using (ChannelFactory<IEchoService> factory = new ChannelFactory<IEchoService>(new ServiceproviderBinding(false), address))
            {
                factory.Endpoint.Contract.ProtectionLevel = ProtectionLevel.Sign;
                factory.ConfigureChannelFactory();
                factory.Credentials.ClientCertificate.Certificate = certificate2Client;
                factory.Credentials.ServiceCertificate.DefaultCertificate = CertificateUtil.GetCertificate(StoreName.My, StoreLocation.LocalMachine, SigningCertificateNameGenevaService);

                factory.Endpoint.Contract.ProtectionLevel = ProtectionLevel.Sign;

                var service = ChannelFactoryOperations.CreateChannelWithIssuedToken<IEchoService>(factory, issuedToken);

                Structure str = new Structure();
                str.value = "Badabam";
                var echoRequest = new echo();
                echoRequest.Framework = new LibertyFrameworkHeader();
                echoRequest.Framework.Profile = "FailurToComply";
                echoRequest.structureToEcho = str;

                var result = service.Echo(echoRequest);
            }
        }