Last active
November 11, 2015 17:04
-
-
Save mkristian/0ad2fc25ab806df83796 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/plugins/rubygem/nexus-ruby-tools/src/main/java/org/sonatype/nexus/ruby/layout/CachingProxyStorage.java b/plugins/rubygem/nexus-ruby-tools/src/main/java/org/sonatype/nexus/ruby/layout/CachingProxyStorage.java | |
index 0cd1814..3905116 100644 | |
--- a/plugins/rubygem/nexus-ruby-tools/src/main/java/org/sonatype/nexus/ruby/layout/CachingProxyStorage.java | |
+++ b/plugins/rubygem/nexus-ruby-tools/src/main/java/org/sonatype/nexus/ruby/layout/CachingProxyStorage.java | |
@@ -79,7 +79,7 @@ public class CachingProxyStorage | |
@Override | |
public void retrieve(BundlerApiFile file) { | |
try { | |
- file.set(new URLStreamLocation(toUrl(file))); | |
+ file.set(toUrl(file)); | |
} | |
catch (IOException e) { | |
file.setException(e); | |
@@ -199,7 +199,7 @@ public class CachingProxyStorage | |
Files.setLastModifiedTime(path, FileTime.fromMillis(mod)); | |
} | |
- protected URL toUrl(RubygemsFile file) throws MalformedURLException { | |
- return new URL(baseurl + file.remotePath()); | |
+ protected URLStreamLocation toUrl(RubygemsFile file) throws MalformedURLException { | |
+ return new URLStreamLocation(new URL(baseurl + file.remotePath())); | |
} | |
-} | |
\ No newline at end of file | |
+} | |
diff --git a/plugins/rubygem/nexus-ruby-tools/src/main/java/org/sonatype/nexus/ruby/layout/SimpleStorage.java b/plugins/rubygem/nexus-ruby-tools/src/main/java/org/sonatype/nexus/ruby/layout/SimpleStorage.java | |
index e9aca6c..f470575 100644 | |
--- a/plugins/rubygem/nexus-ruby-tools/src/main/java/org/sonatype/nexus/ruby/layout/SimpleStorage.java | |
+++ b/plugins/rubygem/nexus-ruby-tools/src/main/java/org/sonatype/nexus/ruby/layout/SimpleStorage.java | |
@@ -18,12 +18,16 @@ import java.io.IOException; | |
import java.io.InputStream; | |
import java.net.MalformedURLException; | |
import java.net.URL; | |
+import java.net.URLConnection; | |
+import java.net.URLDecoder; | |
+import java.nio.charset.StandardCharsets; | |
import java.nio.file.FileAlreadyExistsException; | |
import java.nio.file.Files; | |
import java.nio.file.Path; | |
import java.nio.file.StandardCopyOption; | |
import java.security.SecureRandom; | |
import java.util.zip.GZIPInputStream; | |
+import javax.xml.bind.DatatypeConverter; | |
import org.sonatype.nexus.ruby.DependencyFile; | |
import org.sonatype.nexus.ruby.Directory; | |
@@ -52,9 +56,19 @@ public class SimpleStorage | |
this.url = url; | |
} | |
+ public URLConnection openConnection() throws IOException { | |
+ URLConnection con = url.openConnection(); | |
+ String userinfo = this.url.getUserInfo(); | |
+ if(userinfo != null) { | |
+ String basicAuth = "Basic " + DatatypeConverter.printBase64Binary(URLDecoder.decode(userinfo, "UTF-8").getBytes(StandardCharsets.UTF_8)); | |
+ con.setRequestProperty ("Authorization", basicAuth); | |
+ } | |
+ return con; | |
+ } | |
+ | |
@Override | |
public InputStream openStream() throws IOException { | |
- return url.openStream(); | |
+ return openConnection().getInputStream(); | |
} | |
} | |
@@ -255,4 +269,4 @@ public class SimpleStorage | |
public String[] listDirectory(Directory dir) { | |
return toPath(dir).toFile().list(); | |
} | |
-} | |
\ No newline at end of file | |
+} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment