Browse Source

Add Basic Authorization for UrlResource

See gh-1822
pull/31113/head
Denis Kostin 8 years ago committed by Stephane Nicoll
parent
commit
ac9ca412c8
  1. 7
      spring-core/src/main/java/org/springframework/core/io/UrlResource.java

7
spring-core/src/main/java/org/springframework/core/io/UrlResource.java

@ -31,6 +31,7 @@ import java.nio.charset.StandardCharsets;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.Base64Utils;
import org.springframework.util.ResourceUtils; import org.springframework.util.ResourceUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
@ -41,6 +42,7 @@ import org.springframework.util.StringUtils;
* *
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Sam Brannen * @author Sam Brannen
* @author Denis Kostin
* @since 28.12.2003 * @since 28.12.2003
* @see java.net.URL * @see java.net.URL
*/ */
@ -225,6 +227,11 @@ public class UrlResource extends AbstractFileResolvingResource {
public InputStream getInputStream() throws IOException { public InputStream getInputStream() throws IOException {
URLConnection con = this.url.openConnection(); URLConnection con = this.url.openConnection();
customizeConnection(con); customizeConnection(con);
if (this.url.getUserInfo() != null) {
String basicAuth = "Basic " + Base64Utils.encodeToString(url.getUserInfo().getBytes());
con.setRequestProperty("Authorization", basicAuth);
}
try { try {
return con.getInputStream(); return con.getInputStream();
} }

Loading…
Cancel
Save