[Issue 4072] New - jnlp slaves doesn't support HTTP Auth

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[Issue 4072] New - jnlp slaves doesn't support HTTP Auth

weigon-2
https://hudson.dev.java.net/issues/show_bug.cgi?id=4072
                 Issue #|4072
                 Summary|jnlp slaves doesn't support HTTP Auth
               Component|hudson
                 Version|current
                Platform|Macintosh
              OS/Version|All
                     URL|
                  Status|NEW
       Status whiteboard|
                Keywords|
              Resolution|
              Issue type|PATCH
                Priority|P3
            Subcomponent|core
             Assigned to|issues@hudson
             Reported by|weigon






------- Additional comments from [hidden email] Tue Jul 21 10:29:08 +0000 2009 -------
the jnlp slaves can't ship the auth credentials right now to get past a HTTP
Basic Authed hudson setup. This little patch may be a bit hacky and only support
Basic Auth, but it does the job for me.


$ java -jar slave.jar -noCertificateCheck -jnlpUrl
https://example.org/hudson/computer/NAME/slave-agent.jnlp -jnlpCredentials
user:password


Index: main/remoting/src/main/java/hudson/remoting/Launcher.java
===================================================================
--- main/remoting/src/main/java/hudson/remoting/Launcher.java   (revision 19965)
+++ main/remoting/src/main/java/hudson/remoting/Launcher.java   (working copy)
@@ -94,6 +94,9 @@
             "Connection parameters are obtained by parsing the JNLP file.")
     public URL slaveJnlpURL = null;
 
+    @Option(name="-jnlpCredentials")
+    public String slaveJnlpCredentials = null;
+
     @Option(name="-cp",aliases="-classpath",metaVar="PATH",
             usage="add the given classpath elements to the system classloader.")
     public void addClasspath(String pathList) throws Exception {
@@ -185,6 +188,12 @@
         while (true) {
             try {
                 URLConnection con = slaveJnlpURL.openConnection();
+                if (con instanceof HttpURLConnection && slaveJnlpCredentials !=
null) {
+                    HttpURLConnection http = (HttpURLConnection) con;
+                   String userPassword = slaveJnlpCredentials;
+                   String encoding = new sun.misc.BASE64Encoder().encode
(userPassword.getBytes());
+                   http.setRequestProperty ("Authorization", "Basic " + encoding);
+               }
                 con.connect();
 
                 if (con instanceof HttpURLConnection) {
@@ -216,6 +225,10 @@
                 List<String> jnlpArgs = new ArrayList<String>();
                 for( int i=0; i<argElements.getLength(); i++ )
                         jnlpArgs.add(argElements.item(i).getTextContent());
+                if (slaveJnlpCredentials != null) {
+                       jnlpArgs.add("-credentials");
+                      jnlpArgs.add(slaveJnlpCredentials);
+               }
                 // force a headless mode
                 jnlpArgs.add("-headless");
                 return jnlpArgs;
Index: main/remoting/src/main/java/hudson/remoting/Engine.java
===================================================================
--- main/remoting/src/main/java/hudson/remoting/Engine.java     (revision 19965)
+++ main/remoting/src/main/java/hudson/remoting/Engine.java     (working copy)
@@ -78,6 +78,7 @@
 
     private final String secretKey;
     public final String slaveName;
+    private String credentials;
 
     /**
      * See Main#tunnel in the jnlp-agent module for the details.
@@ -103,6 +104,10 @@
         this.tunnel = tunnel;
     }
 
+    public void setCredentials(String creds) {
+        this.credentials = creds;
+    }
+
     public void setNoReconnect(boolean noReconnect) {
         this.noReconnect = noReconnect;
     }
@@ -130,6 +135,11 @@
 
                     // find out the TCP port
                     HttpURLConnection con =
(HttpURLConnection)salURL.openConnection();
+                if (con instanceof HttpURLConnection && credentials != null) {
+                    HttpURLConnection http = (HttpURLConnection) con;
+                   String encoding = new sun.misc.BASE64Encoder().encode
(credentials.getBytes());
+                   http.setRequestProperty ("Authorization", "Basic " + encoding);
+               }
                     try {
                         con.connect();
                     } catch (IOException x) {
Index: main/remoting/src/main/java/hudson/remoting/jnlp/Main.java
===================================================================
--- main/remoting/src/main/java/hudson/remoting/jnlp/Main.java  (revision 19965)
+++ main/remoting/src/main/java/hudson/remoting/jnlp/Main.java  (working copy)
@@ -64,6 +64,10 @@
             usage="Specify the Hudson root URLs to connect to.")
     public final List<URL> urls = new ArrayList<URL>();
 
+    @Option(name="-credentials",metaVar="USER:PASSWORD",
+            usage="Specify the Hudson credentials")
+    public String credentials;
+
     @Option(name="-noreconnect",
             usage="If the connection ends, don't retry and just exit.")
     public boolean noReconnect = false;
@@ -111,6 +115,8 @@
                 urls, args.get(0), args.get(1));
         if(tunnel!=null)
             engine.setTunnel(tunnel);
+        if(credentials!=null)
+            engine.setCredentials(credentials);
         engine.setNoReconnect(noReconnect);
         engine.start();
         engine.join();

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

[Issue 4072] jnlp slaves doesn't support HTTP Auth

jglick-2
https://hudson.dev.java.net/issues/show_bug.cgi?id=4072



User jglick changed the following:

                What    |Old value                 |New value
================================================================================
                  Status|NEW                       |RESOLVED
--------------------------------------------------------------------------------
              Resolution|                          |DUPLICATE
--------------------------------------------------------------------------------




------- Additional comments from [hidden email] Tue Jul 21 23:56:58 +0000 2009 -------
dupe

*** This issue has been marked as a duplicate of 4071 ***

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]