Downloading a file using http basic authentication

515 views
Skip to first unread message

sivak...@gmail.com

unread,
Jun 4, 2014, 2:23:31 PM6/4/14
to suppor...@runmyprocess.com
Hi,

I need to download a file (a pdf file which we have generated in RMP) from RMP using HTTP basic authentication. Can we do it?

Thank you!

Regards,
Siva

thoshino

unread,
Jun 19, 2014, 6:49:52 PM6/19/14
to suppor...@runmyprocess.com
Hi,

Yes, you can.
Just request a GET request to the file URL and you should be able to download.

Best regards,

Taka

sivak...@gmail.com

unread,
Sep 15, 2014, 2:29:19 PM9/15/14
to suppor...@runmyprocess.com
Hi Taka,

Thanks for your Reply. Since we have configured SAML for our authentication, we are not able to use simple http authentication to fetch the private files. I am looking at the options to use SAML from my application which reads the RMP files. I will let you know if I need any more help.

Thank you!

Regards,
Siva

thoshino

unread,
Sep 15, 2014, 2:33:08 PM9/15/14
to suppor...@runmyprocess.com, sivak...@gmail.com
Hi Siva,

You should still be able to use Basic auth to get files, regardless of account setting (Saml or Google).

Best regards,

Taka

Sivakumar Venkatachalam

unread,
Sep 15, 2014, 3:51:18 PM9/15/14
to thoshino, suppor...@runmyprocess.com
Hi Taka,

I am getting HTTP Status 401 Unauthorized. Here is the Java code I have (using Apache HttpClient library):

String urlString = "https://live.runmyprocess.com/live/2215365968/upload/628fe150-399e-11e4-88ca-22000b411df2/LIVE_2016_1410431188603_nomination_nominatorview.pdf?method=GET";
String fileName = "C:/rmp_file.pdf";

CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope("https://live.runmyprocess.com/", 443), new UsernamePasswordCredentials("sivak...@gmail.com", "xxxxxxxx"));
CloseableHttpClient httpclient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();
try {
            HttpGet httpget = new HttpGet(urlString);
            System.out.println("Executing request " + httpget.getRequestLine());
            CloseableHttpResponse response = httpclient.execute(httpget);
            try {
                System.out.println("----------------------------------------");
                System.out.println(response.getStatusLine());
                byte[] ba = EntityUtils.toByteArray(response.getEntity());
                FileOutputStream fos = new FileOutputStream(fileName);
                int baLength = ba.length;
                fos.write(ba, 0, baLength);
                fos.flush();
                fos.close();
            } finally {
                response.close();
            }
        } finally {
            httpclient.close();
        }

Regards,
Siva


--
A ship is safe in harbor, but that's not what ships are built for - William Shedd

thoshino

unread,
Sep 15, 2014, 6:53:34 PM9/15/14
to suppor...@runmyprocess.com, thos...@runmyprocess.com, sivak...@gmail.com
Hi,

I cannot debug the Java code, but I can make it work with a REST tool as attached screenshot.
To be sure, I logged out of RMP for sure, then executed this HTTP request and I can get the data, pdf is readable.

Can you try the URL without the "?method" parameter?


Best regards,

Taka
2014-09-15 15_36_33-DHC.png

Pray Desai

unread,
Sep 15, 2014, 8:40:01 PM9/15/14
to
Hi Siva,

As mentioned by Taka in previous thread, there is no issue with your SSO as RunMyProcess APIs are accessible with an admin's RunMyProcess email:password encoded in Base64. It seems you haven't encoded your credentials. You can see highlighted Auth Headers in Taka's screenshot earlier.

Anyways, here is a working sample Java code to download a file from RunMyProcess. Although, logic to generate file is different from yours, feel free to refer it or re-use it.


import java.io.ByteArrayOutputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;

import java.net.URL;

import javax.net.ssl.HttpsURLConnection;

import org.apache.commons.codec.binary.Base64;

public class GetFile {
private static String USERNAME="";
private static String PASSWORD="";
public static void main(String[] args) {
GetFile g = new GetFile();
g.download();
}
public void download() { 
try { 
URL url = new URL(FILE_URL); 
HttpsURLConnection connection = (HttpsURLConnection)url.openConnection(); 
connection.setRequestMethod("GET"); 
String plainCreds = USERNAME+":"+PASSWORD;
byte[] plainCredsBytes = plainCreds.getBytes();
byte[] base64CredsBytes = Base64.encodeBase64(plainCredsBytes);
String encoding = new String(base64CredsBytes);
connection.setRequestProperty("Authorization", (new StringBuilder()).append("Basic ").append(encoding).toString()); 
 InputStream is = connection.getInputStream();
 InputStreamReader in = new InputStreamReader(is);
 ByteArrayOutputStream out = new ByteArrayOutputStream();
 byte[] buf = new byte[1024];
 int ByteRead,ByteWritten=0;
 
  while ((ByteRead = is.read(buf)) != -1) {
            out.write(buf, 0, ByteRead);
            ByteWritten += ByteRead;
        }
 
 out.close();
 in.close();
 byte[] response = out.toByteArray();
 
 String file_tokens[] = FILE_URL.split("/");
 String file_name = file_tokens[file_tokens.length-1];
 FileOutputStream fos = new FileOutputStream(file_name);
 fos.write(response);
 fos.close();
   
 System.out.println("Finished");
}
 catch(Exception e) 
e.printStackTrace(); 

}
}



----------------
Regards,
Pray Desai,
Fujitsu RunMyProcess.


--
Fujitsu - RunMyProcess
---
You received this message because you are subscribed to the Google Groups "RunMyProcess Support Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to supportforum+unsubscribe@runmyprocess.com.
To post to this group, send email to suppor...@runmyprocess.com.
Visit this group at http://groups.google.com/a/runmyprocess.com/group/supportforum/.
To view this discussion on the web visit https://groups.google.com/a/runmyprocess.com/d/msgid/supportforum/fc9a278d-3cac-4a39-bc9e-6cc816b401d5%40runmyprocess.com.



--

sivak...@gmail.com

unread,
Sep 16, 2014, 12:38:33 AM9/16/14
to suppor...@runmyprocess.com
Hi Taka and Payal

Thank you so much for your help!! It works fine now.

Regards,
Siva

Reply all
Reply to author
Forward
0 new messages