@ -28,6 +28,7 @@ import java.net.URL;
@@ -28,6 +28,7 @@ import java.net.URL;
import java.net.URLConnection ;
import java.net.URLDecoder ;
import java.nio.charset.StandardCharsets ;
import java.util.Base64 ;
import org.springframework.lang.Nullable ;
import org.springframework.util.Assert ;
@ -46,6 +47,8 @@ import org.springframework.util.StringUtils;
@@ -46,6 +47,8 @@ import org.springframework.util.StringUtils;
* /
public class UrlResource extends AbstractFileResolvingResource {
private static final String AUTHORIZATION = "Authorization" ;
/ * *
* Original URI , if available ; used for URI and File access .
* /
@ -237,6 +240,16 @@ public class UrlResource extends AbstractFileResolvingResource {
@@ -237,6 +240,16 @@ public class UrlResource extends AbstractFileResolvingResource {
}
}
@Override
protected void customizeConnection ( URLConnection con ) throws IOException {
super . customizeConnection ( con ) ;
String userInfo = this . url . getUserInfo ( ) ;
if ( userInfo ! = null ) {
String encodedCredentials = Base64 . getUrlEncoder ( ) . encodeToString ( userInfo . getBytes ( ) ) ;
con . setRequestProperty ( AUTHORIZATION , "Basic " + encodedCredentials ) ;
}
}
/ * *
* This implementation returns the underlying URL reference .
* /