GetCredential() public method

public GetCredential ( Uri uriPrefix, string authType ) : NetworkCredential
uriPrefix Uri
authType string
return NetworkCredential
コード例 #1
0
ファイル: CrashHandler.cs プロジェクト: hungdluit/sipserver
		private void SendReport()
		{
			try
			{
				var fileName = Path.GetTempFileName();
				File.WriteAllText(fileName, report, Encoding.Unicode);

				CredentialCache credentialCache = new CredentialCache();
				credentialCache.Add(uploadUri, @"Basic", new NetworkCredential(@"uprep", @"qeiusroi123woi3zf"));

				var webClient = new WebClient();
				webClient.Credentials = credentialCache.GetCredential(uploadUri, @"Basic");
				webClient.QueryString.Add("app", "SRV");
				webClient.QueryString.Add("ver", version.ToString());
				webClient.UploadFile(uploadUri, fileName);
			}
			catch
			{
			}
		}
コード例 #2
0
ファイル: Program.cs プロジェクト: nbuuck/eNPCScan
        private static bool SendMailNotification(NPC FoundNPC)
        {
            // Construct Message
            MailMessage msg = new MailMessage();
            msg.From = new MailAddress(user.getUser());
            msg.To.Add(strRecipientAddress);
            msg.Subject = FoundNPC.getName() + " FOUND!";
            msg.Body = FoundNPC.getName() + " (" + FoundNPC.getID().ToString("D") + ") has been cached!";
            msg.IsBodyHtml = false;
            msg.Priority = MailPriority.Normal;

            // Send the Message
            SmtpClient client = new SmtpClient();
            client.Host = server.getHostName();
            client.Port = server.getPort();
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            client.EnableSsl = server.UseSSL();
            client.UseDefaultCredentials = false;
            //client.Timeout = 10000;

            CredentialCache cache = new CredentialCache();
            cache.Add(new Uri("http://" + server.getHostName()), "Basic", new NetworkCredential(user.getUser(), user.getPassword()));
            client.Credentials = cache.GetCredential(new Uri("http://" + server.getHostName()), "Basic");

            ConsoleLogMessage("Sending mail alert...", ConsoleMessage.INFO);
            client.Send(msg);

            return true;
        }
コード例 #3
0
        public void All ()
        {
		CredentialCache c = new CredentialCache ();
		
		NetworkCredential cred1 = new NetworkCredential ("user1", "pwd1");
		NetworkCredential cred2 = new NetworkCredential ("user2", "pwd2");
		NetworkCredential cred3 = new NetworkCredential ("user3", "pwd3");
		NetworkCredential cred4 = new NetworkCredential ("user4", "pwd4");
		NetworkCredential cred5 = new NetworkCredential ("user5", "pwd5");
		
		c.Add (new Uri ("http://www.ximian.com"), "Basic", cred1);
		c.Add (new Uri ("http://www.ximian.com"), "Kerberos", cred2);
		
		c.Add (new Uri ("http://www.contoso.com/portal/news/index.aspx"), "Basic", cred1);
		c.Add (new Uri ("http://www.contoso.com/portal/news/index.aspx?item=1"), "Basic", cred2);
		c.Add (new Uri ("http://www.contoso.com/portal/news/index.aspx?item=12"), "Basic", cred3);
		c.Add (new Uri ("http://www.contoso.com/portal/"), "Basic", cred4);
		c.Add (new Uri ("http://www.contoso.com"), "Basic", cred5);
		
		NetworkCredential result = null;
	
		try {
			c.Add (new Uri("http://www.ximian.com"), "Basic", cred1);
			Assertion.Fail ("#1: should have failed");
		} catch (ArgumentException) { }

		c.Add (new Uri("http://www.contoso.com/"), "**Unknown**", cred1);
		result = c.GetCredential (new Uri("http://www.contoso.com/"), "**Unknown**");
		Assertion.AssertEquals ("#3", result, cred1);
		c.Remove (new Uri("http://www.contoso.com/"), "**Unknown**");
		result = c.GetCredential (new Uri("http://www.contoso.com/"), "**Unknown**");
		Assertion.Assert ("#4", result == null);

		c.Add (new Uri("http://www.contoso.com/"), "**Unknown**", cred1);
		result = c.GetCredential (new Uri("http://www.contoso.com"), "**Unknown**");
		Assertion.AssertEquals ("#5", result, cred1);
		c.Remove (new Uri("http://www.contoso.com"), "**Unknown**");
		result = c.GetCredential (new Uri("http://www.contoso.com"), "**Unknown**");
		Assertion.Assert ("#6", result == null);

		c.Add (new Uri("http://www.contoso.com/portal/"), "**Unknown**", cred1);
		result = c.GetCredential (new Uri("http://www.contoso.com/portal/foo/bar.html"), "**Unknown**");
		Assertion.AssertEquals ("#7", result, cred1);
		c.Remove (new Uri("http://www.contoso.com"), "**Unknown**");
		result = c.GetCredential (new Uri("http://www.contoso.com"), "**Unknown**");
		Assertion.Assert ("#8", result == null);

		result = c.GetCredential (new Uri("http://www.contoso.com:80/portal/news/index.aspx"), "Basic");
		Assertion.AssertEquals ("#9", result, cred3);

		result = c.GetCredential (new Uri("http://www.contoso.com:80/portal/news/index"), "Basic");
		Assertion.AssertEquals ("#10", result, cred3);

		result = c.GetCredential (new Uri("http://www.contoso.com:80/portal/news/"), "Basic");
		Assertion.AssertEquals ("#11", result, cred3);
		
		result = c.GetCredential (new Uri("http://www.contoso.com:80/portal/news"), "Basic");
		Assertion.AssertEquals ("#12", result, cred4);

		result = c.GetCredential (new Uri("http://www.contoso.com:80/portal/ne"), "Basic");
		Assertion.AssertEquals ("#13", result, cred4);

		result = c.GetCredential (new Uri("http://www.contoso.com:80/portal/"), "Basic");
		Assertion.AssertEquals ("#14", result, cred4);				

		result = c.GetCredential (new Uri("http://www.contoso.com:80/portal"), "Basic");
		Assertion.AssertEquals ("#15", result, cred5);

		result = c.GetCredential (new Uri("http://www.contoso.com:80/"), "Basic");
		Assertion.AssertEquals ("#16", result, cred5);

		result = c.GetCredential (new Uri("http://www.contoso.com"), "Basic");
		Assertion.AssertEquals ("#17", result, cred5);		

		/*		
		IEnumerator e = c.GetEnumerator ();
		while (e.MoveNext ()) {
			Console.WriteLine (e.Current.GetType () + " : " + e.Current.ToString ());
		}
		*/
	}
コード例 #4
0
        private void btnRestCred_Click(object sender, RoutedEventArgs e)
        {
            string BaseUrl = "http://crm.denallix.com/Denallix/xrmservices/2011/OrganizationData.svc/AccountSet";
            //string Resource = "AccountSet?";
            var client = new RestClient();
            client.BaseUrl = BaseUrl;
            
            CredentialCache credCache = new CredentialCache();

            credCache.GetCredential(new Uri(RemoveTrailingSlash(BaseUrl)), "Negotiate"); 
 //           credCache.GetCredential(new Uri(""), "Negotiate"); 


            //credCache.GetCredential(new Uri(BaseUrl), "NTLM");

            SourceCode.Workflow.Common.Authentication.ADCredentials ad = new SourceCode.Workflow.Common.Authentication.ADCredentials();
            CredentialCache k2Cache = ad.GetCredentials(RemoveTrailingSlash(BaseUrl));

            var request = new RestRequest();
            request.Credentials = credCache;
            //request.Credentials = new NetworkCredential("holly", "K2pass!", "DENALLIX");
//            request.Credentials = request.Credentials.GetCredential(new Uri(RemoveTrailingSlash(BaseUrl)), "NTLM");
            request.Method = RestSharp.Method.GET;
            request.RequestFormat = RestSharp.DataFormat.Xml;
            //request.Resource = Resource;



            var response = client.Execute(request);
        }
コード例 #5
0
        //Array hosts;
        /* Construct and send mail. */
        private void SendMessage()
        {
            //try
            //{
            /* Create Mail Message */
            MailMessage oMessage = new MailMessage();
            oMessage.From = new MailAddress(from);
            oMessage.To.Add(to);
            oMessage.Subject = subject;
            oMessage.Body = ebody;

            /*Set up SMTPClient */
            SmtpClient smtpClient = new SmtpClient();
            smtpClient.Host = host;
            smtpClient.Port = port;
            CredentialCache CredCache;
            NetworkCredential creds;
            string Domain;

            switch (Auth)
            {
                case 1: /* Setup Basic Auth over TLS */
                    tblkStatus.Text += "Authentication: Basic over TLS\n";
                    if (tbUserName.Text.Contains("\\") == true)
                    {
                        char[] delim = { '\\' };
                        string[] text = tbUserName.Text.Split(delim);
                        Domain = text[0];
                        UserName = text[1];
                    }
                    else if (tbUserName.Text.Contains("@") == true)
                    {
                        char[] delim = { '@' };
                        string[] text = tbUserName.Text.Split(delim);
                        Domain = text[0];
                        UserName = text[1];
                    }
                    else
                    {
                        UserName = tbUserName.Text;
                    }
                    smtpClient.UseDefaultCredentials = false;
                    smtpClient.EnableSsl = true;
                    CredCache = new CredentialCache();
                    creds = new NetworkCredential(UserName, Password, Domain);
                    CredCache.Add(new Uri("smtp://" + host + ":" + port + "/"), "BASIC", creds);
                    smtpClient.Credentials = CredCache.GetCredential(new Uri("smtp://" + host + ":" + port + "/"), "BASIC");
                    tblkStatus.Text += "Credential Cache Generated for: " + host + ":" + port + "\n";
                    string thumb = SSLThumbPrint;
                    X509Store certstore = new X509Store(StoreName.My, StoreLocation.LocalMachine);
                    certstore.Open(OpenFlags.ReadOnly);
                    var certs = certstore.Certificates;
                    if (rbSSLStore.IsChecked == true)
                    {
                        certstore = new X509Store(StoreName.My, StoreLocation.LocalMachine);
                        certstore.Open(OpenFlags.ReadOnly);
                        certs = certstore.Certificates.Find(X509FindType.FindByThumbprint, thumb, false);
                    }
                    if (rbSSLFile.IsChecked == true)
                    {
                        certstore = new X509Store();
                        string file = SSLThumbPrint;
                        certstore.Add(new X509Certificate2(file));
                        certs = certstore.Certificates;
                    }
                    if (certs.Count != 1)
                    {
                        tblkStatus.Text += string.Format("Cert Error: {0} Certs found, we only need 1", certs.Count);
                        throw new ApplicationException(string.Format("{0} certs found, we only need 1", certs.Count));

                    }
                    var name = certs[0].SubjectName.ToString();
                    X509Certificate cert = certs[0];
                    System.Windows.Forms.MessageBox.Show(name);
                    smtpClient.ClientCertificates.Add(cert);
                    break;
                case 2: /* Setup Windows Integrated Authentication */
                    tblkStatus.Text += "Authentication: NTLM\n";
                    if (tbUserName.Text.Contains("\\") == true)
                    {
                        char[] delim = { '\\' };
                        string[] text = tbUserName.Text.Split(delim);
                        Domain = text[0];
                        UserName = text[1]; ;
                    }
                    else if (tbUserName.Text.Contains("@") == true)
                    {
                        char[] delim = { '@' };
                        string[] text = tbUserName.Text.Split(delim);
                        Domain = text[0];
                        UserName = text[1];
                    }
                    else
                    {
                        UserName = tbUserName.Text;
                    }
                    smtpClient.UseDefaultCredentials = false;
                    CredCache = new CredentialCache();
                    creds = new NetworkCredential(UserName, Password);
                    CredCache.Add(new Uri("smtp://" + host + ":" + port + "/"), "NTLM", creds);
                    smtpClient.Credentials = CredCache.GetCredential(new Uri("smtp://" + host + ":" + port + "/"), "NTLM");
                    tblkStatus.Text += "Credential Cache Generated for: " + host + ":" + port + "\n";
                    smtpClient.EnableSsl = false;
                    tblkStatus.Text += "SSL Disabled\n==============\n";
                    break;
            }
            try /* Try to send the message */
            {
                tblkStatus.Text += "Sending Message\n";
                smtpClient.Send(oMessage);
                tblkStatus.Text += "Message Sent\n";
            }
            catch (Exception ex) /* Houston we have a problem */
            {
                //throw new ApplicationException(string.Format("Error:\n{0}", ex));
                System.Windows.Forms.MessageBox.Show(ex.ToString());
                string error = ex.ToString();
                tblkStatus.Text += string.Format("Error:\n{0}\n", error);

            }
        }
コード例 #6
0
ファイル: UploadShipmentData.cs プロジェクト: wra222/testgit
        private bool CheckOA3Key(IHierarchicalBOM bom, IProduct p, string fkiPath, CredentialCache FKICredentialCache, string editor, UnitOfWork uow)
        {
            bool bWIN8 = false;
            IList<IBOMNode> P1BomNodeList = bom.GetFirstLevelNodesByNodeType("P1");
            //foreach (IBOMNode bomNode in P1BomNodeList)
            //{
            //    if (bomNode.Part.Descr.StartsWith("ECOA"))
            //    {
            //        bWIN8 = true;
            //        break;
            //    }
            //}
            CommonImpl2 cm2 = new CommonImpl2();
            bWIN8 = cm2.CheckIsWIN8(bom);


            if (!bWIN8) return true;

            if (fkiPath == "") return true; //Switch off checking by FKIServer.
            string thisURI = "";
            if (fkiPath.EndsWith("/"))
            {
                thisURI = fkiPath + "UnitStatus";
            }
            else
            {
                thisURI = fkiPath + "/UnitStatus";
            }

            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(thisURI);
            req.AllowAutoRedirect = true;
            req.CookieContainer = new CookieContainer();
            req.ContentType = "application/plain; charset=utf-8";
            req.Accept = "*/*";
            req.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
            req.KeepAlive = true;
            req.Method = "POST";
            req.Credentials = FKICredentialCache.GetCredential(new Uri(fkiPath), "NTLM");

            string XMLInputData = "<?xml version='1.0' encoding='utf-8' ?>";
            XMLInputData += "<UnitStatusRequest xmlns='http://HP.ITTS.OA30/digitaldistribution/2011/08'>";
            XMLInputData += "<HPSerialNumber>";
            XMLInputData += p.CUSTSN;
            XMLInputData += "</HPSerialNumber>";
            XMLInputData += "<ProductKeyID>";
            XMLInputData += "";
            XMLInputData += "</ProductKeyID>";
            XMLInputData += "</UnitStatusRequest>";
            Encoding encoding = Encoding.Default;
            byte[] buffer = encoding.GetBytes(XMLInputData);
            req.ContentLength = buffer.Length;
            req.GetRequestStream().Write(buffer, 0, buffer.Length);

            HttpWebResponse res = (HttpWebResponse)req.GetResponse();
            XmlTextReader xmlr = new XmlTextReader(res.GetResponseStream());
            string status = "";
            string rc = "";
            bool bError = false;
            bool bFound = false;
            StringBuilder str = new StringBuilder("Formatted Response:\n");

            while (xmlr.Read())
            {
                switch (xmlr.NodeType)
                {
                    case XmlNodeType.Element:
                        if (xmlr.IsEmptyElement)
                            str.AppendFormat("<{0}/>", xmlr.Name);
                        else
                            str.AppendFormat("<{0}>", xmlr.Name);
                        break;
                    case XmlNodeType.Text:
                        str.Append(xmlr.Value);
                        break;
                    case XmlNodeType.CDATA:
                        str.AppendFormat("<![CDATA[{0}]]>", xmlr.Value);
                        break;
                    case XmlNodeType.ProcessingInstruction:
                        str.AppendFormat("<?{0} {1}?>", xmlr.Name, xmlr.Value);
                        break;
                    case XmlNodeType.Comment:
                        str.AppendFormat("<!--{0}-->", xmlr.Value);
                        break;
                    case XmlNodeType.XmlDeclaration:
                        str.AppendFormat("<?xml version='1.0'?>");
                        break;
                    case XmlNodeType.DocumentType:
                        str.AppendFormat("<!DOCTYPE{0} [{1}]>", xmlr.Name, xmlr.Value);
                        break;
                    case XmlNodeType.EntityReference:
                        str.Append(xmlr.Name);
                        break;
                    case XmlNodeType.EndElement:
                        str.AppendFormat("</{0}>", xmlr.Name);
                        break;
                    case XmlNodeType.Whitespace:
                        str.Append("\n");
                        break;
                }

                if (xmlr.NodeType == System.Xml.XmlNodeType.Element && xmlr.LocalName.Equals("ReturnCode"))
                {
                    xmlr.Read();
                    str.Append(xmlr.Value);
                    rc = xmlr.Value.Trim();
                    if (rc != "000") bError = true;
                    continue;
                }

                if (xmlr.NodeType == System.Xml.XmlNodeType.Element && xmlr.LocalName.Equals("ReturnMessage"))
                {
                    if (bError)
                    {
                        xmlr.Read();
                        str.Append(xmlr.Value);
                        string msg = xmlr.Value;
                        xmlr.Close();
                        throw new Exception("[" + rc + "]:" + msg);
                    }
                }

                if (xmlr.NodeType == System.Xml.XmlNodeType.Element && xmlr.LocalName.Equals("ProductKeyStateName"))
                {
                    xmlr.Read();
                    str.Append(xmlr.Value);
                    status = xmlr.Value;
                    // Marked this by Benson at 2013/3/8
                    //  if (status == "NotifiedBound")
                    if (status == "NotifiedBound" || status == "FKIErrorBound")
                    {
                        //只能有一行状态为"Bound"/"NotifiedBound"/"PendingBound" --OLD
                        //只能有一行状态为"Bound"/"NotifiedBound"/"PendingBound/FKIErrorBound" --NEW add by Benson at 2013/3/8

                        if (bFound)
                        {
                            xmlr.Close();
                            return false;
                        }
                        bFound = true;
                        continue;
                    }


                    if (status == "Bound" || status == "PendingBound")
                    {
                        //只能有一行状态为"Bound"/"NotifiedBound"/"PendingBound"
                        if (bFound)
                        {
                            xmlr.Close();
                            return false;
                        }
                        bFound = true;

                        //对于状态为Bound/PendingBound的Product需要记录到ProductInfo中
                        IMES.FisObject.FA.Product.ProductInfo item = new IMES.FisObject.FA.Product.ProductInfo();
                        item.ProductID = p.ProId;
                        item.InfoType = "Win8KeyState";
                        item.InfoValue = status;
                        item.Editor = editor;
                        if (productRepository.CheckExistProductInfo(p.ProId, "Win8KeyState"))
                        {
                            IMES.FisObject.FA.Product.ProductInfo cond = new IMES.FisObject.FA.Product.ProductInfo();
                            cond.ProductID = p.ProId;
                            cond.InfoType = "Win8KeyState";
                            productRepository.UpdateProductInfoDefered(uow, item, cond);
                        }
                        else
                        {
                            productRepository.InsertProductInfoDefered(uow, item);
                        }

                        continue;
                    }
                    //Returned 或PendingReturn或NotifiedReturned或FKIErrorReturn --Mantis0001691
                    // Marked this by Benson at 2013/3/8
                    //   if (status != "Returned" && status != "NotifiedReturned" && status != "PendingReturn")
                    if (status != "Returned" && status != "NotifiedReturned" && status != "PendingReturn" && status != "FKIErrorReturn")
                    {
                        xmlr.Close();
                        return false;
                    }
                }
            }
            xmlr.Close();
            Console.Write(str.ToString());
            return bFound;
        }