/// <summary>
        /// Login by using holder-of-key SAML token
        /// </summary>
        /// <param name="xmlToken">Holder-of-key saml token</param>
        private SecurityPolicyAssertion GetSecurityPolicyAssertionForHokToken(XmlElement xmlToken)
        {
            Console.WriteLine();
            Console.WriteLine("Trying to login to server '{0}' by using Holder-of-Key token ...", _service.Url);

            //When this property is set to true, client requests that use the POST method
            //expect to receive a 100-Continue response from the server to indicate that
            //the client should send the data to be posted. This mechanism allows clients
            //to avoid sending large amounts of data over the network when the server,
            //based on the request headers, intends to reject the request
            ServicePointManager.Expect100Continue = true;
            ServicePointManager.SecurityProtocol  = SecurityProtocolType.Tls;

            X509Certificate2 certificateToBeAdded = new X509Certificate2();
            string           certificateFile      = ConfigurationManager.AppSettings["PfxCertificateFile"];
            string           password             = ConfigurationManager.AppSettings["PfxCertificateFilePassword"];

            certificateToBeAdded.Import(certificateFile, password ?? string.Empty, X509KeyStorageFlags.MachineKeySet);

            var customSecurityAssertion = new CustomSecurityAssertionHok();

            customSecurityAssertion.BinaryToken   = xmlToken;
            customSecurityAssertion.TokenType     = strSamlV2TokenType;
            customSecurityAssertion.SecurityToken = new X509SecurityToken(certificateToBeAdded);

            return(customSecurityAssertion);
        }
 /// <summary>
 /// Creates a custom SOAP request filter
 /// </summary>
 /// <param name="parentAssertion">Custom security assertion</param>
 public CustomSecurityClientOutputFilterHok(CustomSecurityAssertionHok parentAssertion)
     : base(parentAssertion.ServiceActor, true)
 {
     issuedToken      = new IssuedToken(parentAssertion.BinaryToken, parentAssertion.TokenType);
     samlAssertionId  = parentAssertion.BinaryToken.Attributes.GetNamedItem("ID").Value;
     messageSignature = new MessageSignature(parentAssertion.SecurityToken);
 }
 /// <summary>
 /// Creates a custom SOAP request filter
 /// </summary>
 /// <param name="parentAssertion">Custom security assertion</param>
 public CustomSecurityClientOutputFilterHok(CustomSecurityAssertionHok parentAssertion)
     : base(parentAssertion.ServiceActor, true)
 {
     issuedToken = new IssuedToken(parentAssertion.BinaryToken, parentAssertion.TokenType);
     samlAssertionId = parentAssertion.BinaryToken.Attributes.GetNamedItem("ID").Value;
     messageSignature = new MessageSignature(parentAssertion.SecurityToken);
 }
        /// <summary>
        /// Login by using holder-of-key SAML token
        /// </summary>
        /// <param name="xmlToken">Holder-of-key saml token</param>
        private SecurityPolicyAssertion GetSecurityPolicyAssertionForHokToken(XmlElement xmlToken)
        {
            Console.WriteLine();
            Console.WriteLine("Trying to login to server '{0}' by using Holder-of-Key token ...", _service.Url);

            //When this property is set to true, client requests that use the POST method 
            //expect to receive a 100-Continue response from the server to indicate that 
            //the client should send the data to be posted. This mechanism allows clients 
            //to avoid sending large amounts of data over the network when the server, 
            //based on the request headers, intends to reject the request
            ServicePointManager.Expect100Continue = true;
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;

            X509Certificate2 certificateToBeAdded = new X509Certificate2();
            string certificateFile = ConfigurationManager.AppSettings["PfxCertificateFile"];
            string password = ConfigurationManager.AppSettings["PfxCertificateFilePassword"];
            certificateToBeAdded.Import(certificateFile, password ?? string.Empty, X509KeyStorageFlags.MachineKeySet);

            var customSecurityAssertion = new CustomSecurityAssertionHok();
            customSecurityAssertion.BinaryToken = xmlToken;
            customSecurityAssertion.TokenType = strSamlV2TokenType;
            customSecurityAssertion.SecurityToken = new X509SecurityToken(certificateToBeAdded);

            return customSecurityAssertion;
        }