Skip to content

Instantly share code, notes, and snippets.

@fkleon
Last active May 17, 2017 00:38
Show Gist options
  • Save fkleon/ffeac173cb2de64eb8877db76e89ec20 to your computer and use it in GitHub Desktop.
Save fkleon/ffeac173cb2de64eb8877db76e89ec20 to your computer and use it in GitHub Desktop.
adore-djatoka: Support for source image URLs protected by basic authentication

Support passing basic authentication credentials via source image URLs (rft_id)

This patch allows adore-djatoka to properly resolve source image URLs that contain URL-encoded basic auth credentials, for example:

http://user:[email protected]/gmd/gmd433/g4330/g4330/np000066.jp2

Note that this way of passing credentials has been deprecated in RFC3986. It is only used to pass the credentials to adore-djatoka, which then uses the Authorization header to communicate with the target server.

Previously adore-djatoka would parse the source URL, but not use the URL-encoded credentials to make the subsequent request to the source URL.

With this patch adore-djatoka can resolve source URLs like this:

curl -G
'https://localhost.lan/adore-djatoka/resolver' \
  -d url_ver=Z39.88-2004 \
  -d rft_id=http://user:[email protected]/gmd/gmd433/g4330/g4330/np000066.jp2 \
  -d svc_id=info:lanl-repo/svc/getRegion \
  -d svc_val_fmt=info:ofi/fmt:kev:mtx:jpeg2000 \
  -d svc.format=image/jpeg \
  -d svc.level=3

It can be applied on top of the adore-ajatoka 1.1 source code available from sourceforge.net/projects/djatoka.

From 3b9eb92e96d0da00871507bdf3c6d33bf2c3b0fd Mon Sep 17 00:00:00 2001
From: Frederik Leonhardt <[email protected]>
Date: Thu, 11 May 2017 08:23:39 +1200
Subject: [PATCH] Support basic auth on source URLs
---
src/gov/lanl/adore/djatoka/util/IOUtils.java | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/src/gov/lanl/adore/djatoka/util/IOUtils.java b/src/gov/lanl/adore/djatoka/util/IOUtils.java
index e7cbd8f..f01beed 100644
--- a/src/gov/lanl/adore/djatoka/util/IOUtils.java
+++ b/src/gov/lanl/adore/djatoka/util/IOUtils.java
@@ -116,6 +116,14 @@ public class IOUtils {
} else {
try {
URLConnection huc = location.openConnection();
+
+ // Set basic auth if applicable
+ if (location.getUserInfo() != null) {
+ final String userPass = location.getUserInfo();
+ final String basicAuth = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary(userPass.getBytes());
+ huc.setRequestProperty ("Authorization", basicAuth);
+ }
+
huc.connect();
in = huc.getInputStream();
} catch (MalformedURLException e) {
--
2.7.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment