General Discussion

General discussion on using Go including questions and tips

This is a public Discussion Area  publicRSS

Post

    Tim Z
    Using CCTray with authentication
    Post posted February 24, 2009 by Tim Z
    4920 Views, 4 Comment
    Topic:
    Using CCTray with authentication
    Body:
    Has anyone been able to get CCTray to work when authentication is enabled on the server? The documentation for 1.2 mentions the CCTray feed supports basic authorization, but I’m questioning if CCTray itself does not support authentication. [http://studios.thoughtworks.com/cruise-continuous-integration/1.2/help/whats_new_in_cruise.html] When attempting to connect to http://guest:guest@localhost:8153/cruise/cctray.xml in CCTray, I receive this error: Failed to connect to server: The remote server returned an error: (401) Unauthorized. I’ve got both a password file (for a GUEST user) and LDAP authentication enabled, but neither type of account succeeds through CCTray.

    Comment

    • Qiao Liang 乔梁
      posted February 24, 2009 by Qiao Liang 乔梁

      Hi Tim Z,

      As I know, the official CCTray (R1.4.2.14) does not support basic authentication yet. So you have to modify the source code and rebuild it by yourself.

      We did change it only for our testing before. the code is here: (only one file named ‘WebRetriever’ need to be changed for CC.NET 1.4.2.14)

      using System;
      using System.Collections.Specialized;
      using System.IO;
      using System.Net;
      
      namespace ThoughtWorks.CruiseControl.CCTrayLib.Monitoring
      {
          public class WebRetriever : IWebRetriever
          {
              public string Get(Uri uri)
              {
                  ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
                  WebRequest request = WebRequest.Create(uri);
      
                  if (uri.UserInfo != string.Empty)
                  {
                      BasicAuthentication(uri, request);
                  }
      
                  using (WebResponse response = request.GetResponse())
                  {
                      using (Stream responseStream = response.GetResponseStream())
                      {
                          StreamReader streamReader = new StreamReader(responseStream);
                          return streamReader.ReadToEnd();
                      }
                  }
              }
      
              protected void BasicAuthentication(Uri uri, WebRequest request)
              {
                  string username = uri.UserInfo.Split(':')[0];
                  string password = uri.UserInfo.Split(':')[1];
      
                  NetworkCredential myCred = new NetworkCredential(username, password);
                  CredentialCache myCache = new CredentialCache();
                  myCache.Add(uri, "Basic", myCred);
      
                  request.Credentials = myCache;
              }
      
              public void Post(Uri uri, NameValueCollection input)
              {
                  ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
                  WebRequest request = WebRequest.Create(uri);
                  string strInput = GetInputString(input);
      
                  request.Method = "POST";
                  request.ContentType = "application/x-www-form-urlencoded";
                  request.ContentLength = strInput.Length;
      
                  Stream writeStream = request.GetRequestStream();
                  System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
                  byte[] bytes = encoding.GetBytes(strInput);
                  writeStream.Write(bytes, 0, bytes.Length);
                  writeStream.Close();
              }
      
              private static string GetInputString(NameValueCollection input)
              {
                  string strInput = "";
      
                  for (int i = 0; i < input.Keys.Count; i++)
                  {
                      if (strInput.Length == 0)
                      {
                          strInput = string.Format("{0}={1}", input.Keys[i], input[input.Keys[i]]);
                      }
                      else
                      {
                          strInput += string.Format("&{0}={1}", input.Keys[i], input[input.Keys[i]]);
                      }
                  }
                  return strInput;
              }
          }
      }
      

      Qiao Liang

    • Tim Z
      posted February 26, 2009 by Tim Z

      Thanks, Qiao – your code worked perfectly.

    • Qiao Liang 乔梁
      posted June 30, 2010 by Qiao Liang 乔梁

      This is the package of cctray with auth.

    • LeeBenhart
      posted October 12, 2010 by LeeBenhart

      The zip file does work with older version of CCTray. 

      The zip file does not work with version 1.5.7256.1. 

       The problem is the username/password must be embedded in the URL. Attempting such a change to supply a custom URL results in --> Failed to connect to server: Unable to retrieve project status from the remote server (404 errors)

        Has anyone been able to get past this issue?
       
      Article ID: 834489 - Last Review: November 15, 2007 - Revision: 11.5 --> http://support.microsoft.com/kb/834489

      Internet Explorer does not support user names and passwords in Web site addresses (HTTP or HTTPS URLs)