public void ThirdPartyAuthorization()
 {
     certSOAPHeaderAuthStrategy = new CertificateSOAPHeaderAuthStrategy();
     subAuthorization = new SubjectAuthorization("testsubject");
     certSOAPHeaderAuthStrategy.ThirdPartyAuthorization = subAuthorization;
     Assert.IsNotNull(certSOAPHeaderAuthStrategy.ThirdPartyAuthorization);
 }
 public void ThirdPartyAuthorization()
 {
     signSOAPHeaderAuthStrategy = new SignatureSOAPHeaderAuthStrategy();
     subAuthorization = new SubjectAuthorization("testsubject");
     signSOAPHeaderAuthStrategy.ThirdPartyAuthorization = subAuthorization;
     Assert.IsNotNull(signSOAPHeaderAuthStrategy.ThirdPartyAuthorization);
     Assert.AreEqual("testsubject", ((SubjectAuthorization)(signSOAPHeaderAuthStrategy.ThirdPartyAuthorization)).Subject);
 }
 public void GenerateHeaderStrategyThirdPartyAuthorization()
 {
     certCredential = new CertificateCredential("testusername", "testpassword", "sdk-cert.p12", "KJAERUGBLVF6Y");
     certSOAPHeaderAuthStrategy = new CertificateSOAPHeaderAuthStrategy();
     subAuthorization = new SubjectAuthorization("testsubject");
     certSOAPHeaderAuthStrategy.ThirdPartyAuthorization = subAuthorization;
     certCredential.ThirdPartyAuthorization = subAuthorization;
     string payload = certSOAPHeaderAuthStrategy.GenerateHeaderStrategy(certCredential);
     XmlDocument xmlDoc = GetXmlDocument(payload);
     XmlNodeList xmlNodeListUsername = xmlDoc.GetElementsByTagName("Username");
     Assert.IsTrue(xmlNodeListUsername.Count > 0);
     Assert.AreEqual("testusername", xmlNodeListUsername[0].InnerXml);
     XmlNodeList xmlNodeListPassword = xmlDoc.GetElementsByTagName("Password");
     Assert.IsTrue(xmlNodeListPassword.Count > 0);
     Assert.AreEqual("testpassword", xmlNodeListPassword[0].InnerXml);
     XmlNodeList xmlNodeListSubject = xmlDoc.GetElementsByTagName("Subject");
     Assert.IsTrue(xmlNodeListSubject.Count > 0);
     Assert.AreEqual("testsubject", xmlNodeListSubject[0].InnerXml);
 }
 public void GenerateHeaderStrategyThirdParty()
 {
     signCredential = new SignatureCredential("testusername", "testpassword", "testsignature");
     signSOAPHeaderAuthStrategy = new SignatureSOAPHeaderAuthStrategy();
     subAuthorization = new SubjectAuthorization("testsubject");
     signSOAPHeaderAuthStrategy.ThirdPartyAuthorization = subAuthorization;
     signCredential.ThirdPartyAuthorization = subAuthorization;
     string payload = signSOAPHeaderAuthStrategy.GenerateHeaderStrategy(signCredential);
     XmlDocument xmlDoc = GetXmlDocument(payload);
     XmlNodeList NodeListUsername = xmlDoc.GetElementsByTagName("Username");
     Assert.IsTrue(NodeListUsername.Count > 0);
     Assert.AreEqual("testusername", NodeListUsername[0].InnerXml);
     XmlNodeList xmlNodeListPassword = xmlDoc.GetElementsByTagName("Password");
     Assert.IsTrue(xmlNodeListPassword.Count > 0);
     Assert.AreEqual("testpassword", xmlNodeListPassword[0].InnerXml);
     XmlNodeList xmlNodeListSignature = xmlDoc.GetElementsByTagName("Signature");
     Assert.IsTrue(xmlNodeListSignature.Count > 0);
     Assert.AreEqual("testsignature", xmlNodeListSignature[0].InnerXml);
     XmlNodeList xmlNodeListSubject = xmlDoc.GetElementsByTagName("Subject");
     Assert.IsTrue(xmlNodeListSubject.Count > 0);
     Assert.AreEqual("testsubject", xmlNodeListSubject[0].InnerXml);
 }
 public void ThirdPartyAuthorizationForSubject()
 {
     IThirdPartyAuthorization thirdPartyAuthorization = new SubjectAuthorization("Subject");
     signCredential.ThirdPartyAuthorization = thirdPartyAuthorization;
     Assert.AreEqual(((SubjectAuthorization)thirdPartyAuthorization).Subject, "Subject");
 }
 public void ArgumentExceptionTest()
 {
     SubjectAuthorization subAuthorization = new SubjectAuthorization(null);
 }
        /// <summary>
        /// Returns the API Credentials
        /// </summary>
        /// <param name="apiUserName"></param>
        /// <returns></returns>
        public ICredential GetCredentials(Dictionary<string, string> config, string apiUserName)
        {
            ICredential credential = null;
            Account accnt = GetAccount(config, apiUserName);
            if (accnt == null)
            {
                throw new MissingCredentialException("Missing credentials for " + apiUserName);
            }
            if (!string.IsNullOrEmpty(accnt.APICertificate))
            {
                CertificateCredential certCredential = new CertificateCredential(accnt.APIUserName, accnt.APIPassword, accnt.APICertificate, accnt.PrivateKeyPassword);
                certCredential.ApplicationId = accnt.ApplicationId;
                if (!string.IsNullOrEmpty(accnt.CertificateSubject))
                {
                    SubjectAuthorization subAuthorization = new SubjectAuthorization(accnt.CertificateSubject);
                    certCredential.ThirdPartyAuthorization = subAuthorization;
                }
                credential = certCredential;
            }
            else
            {
                SignatureCredential signCredential = new SignatureCredential(accnt.APIUserName, accnt.APIPassword, accnt.APISignature);
                signCredential.ApplicationId = accnt.ApplicationId;
                if (!string.IsNullOrEmpty(accnt.SignatureSubject))
                {
                    SubjectAuthorization subjectAuthorization = new SubjectAuthorization(accnt.SignatureSubject);
                    signCredential.ThirdPartyAuthorization = subjectAuthorization;
                }
                credential = signCredential;
            }
            ValidateCredentials(credential);

            return credential;
        }
        /// <summary>
        /// Returns the API Credentials
        /// </summary>
        /// <param name="apiUserName"></param>
        /// <returns></returns>
        public ICredential GetCredentials(string apiUserName)
        {
            if (apiUserName == null)
            {
                apiUserName = GetDefaultAccountName();
            }

            ICredential credential = null;
            ConfigManager configMngr = ConfigManager.Instance;
            Account accnt = configMngr.GetAccount(apiUserName);
            if (accnt == null)
            {
                throw new MissingCredentialException("Missing credentials for " + apiUserName);
            }
            if (!string.IsNullOrEmpty(accnt.APICertificate))
            {
                CertificateCredential certCredential = new CertificateCredential(accnt.APIUsername, accnt.APIPassword, accnt.APICertificate, accnt.PrivateKeyPassword);
                certCredential.ApplicationID = accnt.ApplicationId;
                if (!string.IsNullOrEmpty(accnt.CertificateSubject))
                {
                    SubjectAuthorization subAuthorization = new SubjectAuthorization(accnt.CertificateSubject);
                    certCredential.ThirdPartyAuthorization = subAuthorization;
                }
                credential = certCredential;
            }
            else
            {
                SignatureCredential signCredential = new SignatureCredential(accnt.APIUsername, accnt.APIPassword, accnt.APISignature);
                signCredential.ApplicationID = accnt.ApplicationId;
                if (!string.IsNullOrEmpty(accnt.SignatureSubject))
                {
                    SubjectAuthorization subjectAuthorization = new SubjectAuthorization(accnt.SignatureSubject);
                    signCredential.ThirdPartyAuthorization = subjectAuthorization;
                }
                credential = signCredential;
            }
            ValidateCredentials(credential);

            return credential;
        }