Folks,I am trying to remotely retrieve content from an alfresco repository using a URL to the content in question.The URL is as follows:http://127.0.0.1:8080/alfresco/d/d/workspace/SpacesStore/57000863-5dbd-4153-9489-36f007a457d4/asampledocument.pdfThe client application is attempting to retrieve a PDF file from alfresco using a HTPP request that includes basic authentication:
String name = "admin";
String password = "admin";
String authString = name + ":" + password;
byte[] authEncBytes = Base64.encodeBase64(authString.getBytes());
String authStringEnc = new String(authEncBytes);
try {
URL url = new URL(aPdfURL);
URLConnection urlConnection = url.openConnection();
urlConnection.setRequestProperty("Authorization", "Basic " + authStringEnc);
is = urlConnection.getInputStream();
byte[] byteChunk = new byte[READ_CHUNK_SIZE];
int n;
while ((n = is.read(byteChunk)) > 0) {
bais.write(byteChunk, 0, n);
}
pdfAsByteArray = bais.toByteArray();
} catch (Throwable t) {
logger.warn("Failed to retrieve PDF for URL " + aPdfURL, t);
return pdfAsByteArray;
}
The Alfresco server does not seem to recognise/accept the basic authentication in the http request, and redirects the request to the login screen.Using curl I can see the following interaction:
C:\temp>curl -v -uadmin:admin http://127.0.0.1:8080/alfresco/d/d/workspace/SpacesStore/57000863-5dbd-4153-9489-36f007a457d4/sampleDoc.pdf
* About to connect() to 127.0.0.1 port 8080 (#0)
* Trying 127.0.0.1…
* Adding handle: conn: 0x63adc0
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x63adc0) send_pipe: 1, recv_pipe: 0
* Connected to 127.0.0.1 (127.0.0.1) port 8080 (#0)
* Server auth using Basic with user 'admin'
> GET /alfresco/d/d/workspace/SpacesStore/57000863-5dbd-4153-9489-36f007a457d4/sampleDoc.pdf HTTP/1.1
> Authorization: Basic YWRtaW46YWRtaW4=
> User-Agent: curl/7.32.0
> Host: 127.0.0.1:8080
> Accept: */*
>
< HTTP/1.1 302 Moved Temporarily
* Server Apache-Coyote/1.1 is not blacklisted
< Server: Apache-Coyote/1.1
< Set-Cookie: JSESSIONID=2AB897F5161270BB2BA923CEDFE1C7BD; Path=/alfresco
< Location: http://127.0.0.1:8080/alfresco/faces/jsp/login.jsp?_alfRedirect=%2Falfresco%2Fd%2Fd%2Fworkspace%2FSpacesStore%2F57000863-5dbd-4153-9489-36f007a457d4%2FsampleDoc.pdf
< Content-Length: 0
< Date: Mon, 09 Dec 2013 14:23:30 GMT
<
* Connection #0 to host 127.0.0.1 left intact
Is what I am attempting to do here possible? or am I missing a trick? Does the authentication service prevent basic auth for interactions of this nature?