Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-5331

add basic auth to url in "user:pass@uri" form

XMLWordPrintable

    • Icon: Patch Patch
    • Resolution: Unresolved
    • Icon: Major Major
    • urlscm-plugin
    • None
    • all

      In URLSRC.java revision 23018 near line 68 and also line 123

      // example url string.
      String urlString = "http://user:pass@source/hudson/job/MyJob/lastSuccessfulBuild/artifact/trunk/artifact.jar";

      URL url = new URL(urlString);
      URLConnection connection = url.openConnection();
      String userinfo = url.getUserInfo();
      if(userinfo!=null) {
      String[] userpass = userinfo.split(":");
      if(userpass.length>0) {
      String username = userpass[0];
      String password = "";
      if(userpass.length>1)

      { password = userpass[1]; }

      String auth = "Basic " + (new sun.misc.BASE64Encoder().encode((username + ":" + password).getBytes()));
      connection.setRequestProperty("Authorization", auth);
      }
      }
      InputStream is = connection.getInputStream();

            mdonohue mdonohue
            sdrinovsky sdrinovsky
            Votes:
            2 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: