Skip to content

Commit a404b21

Browse files
author
Sabrina Juarez Garcia
committed
Merge branch 'feature/Update_AzureStorage_SDK' of https://github.com/genexuslabs/JavaClasses into feature/Update_AzureStorage_SDK
2 parents 1d743b6 + 6ea4e0b commit a404b21

File tree

2 files changed

+66
-34
lines changed

2 files changed

+66
-34
lines changed

android/src/main/java/com/genexus/specific/android/HttpClient.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,14 @@ public void prepareSSLSocket(SSLSocket socket) {
8888
// enable TLSv1.1/1.2 if available
8989
// (see https://github.com/rfc2822/davdroid/issues/229)
9090
String[] supportedProtocols = socket.getSupportedProtocols();
91+
9192
ArrayList<String> tempList = new ArrayList<String>();
9293
Collections.addAll(tempList, supportedProtocols);
93-
// remove only olds and unsecure protocols (SSLv3 ), TLS in all version are supported.
94+
// remove only olds and unsecure protocols (SSLv3 ), TLS 1.2 and up are supported.
9495
tempList.remove("SSLv3");
9596
// from : https://blog.dev-area.net/2015/08/13/android-4-1-enable-tls-1-1-and-tls-1-2/
96-
// add 1.1 and 1.2 if not yet added, at least in Android 4.x
97-
if (!tempList.contains("TLSv1.1"))
98-
tempList.add("TLSv1.1");
97+
// Tls 1.1 is not supoerted anymore in Android 16 or up. Exception java.lang.IllegalArgumentException: protocol TLSv1.1 is not supported if added
98+
// add 1.2 if not yet added, at least in Android 4.x
9999
if (!tempList.contains("TLSv1.2"))
100100
tempList.add("TLSv1.2");
101101

gxcloudstorage-awss3-v2/src/main/java/com/genexus/db/driver/ExternalProviderS3V2.java

Lines changed: 62 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ private void initialize() throws Exception {
119119
this.folder = folder;
120120

121121
this.client = buildS3Client(accessKey, secretKey, endpointValue, clientRegion);
122-
this.presigner = buildS3Presigner(accessKey, secretKey, clientRegion);
122+
this.presigner = buildS3Presigner(accessKey, secretKey, endpointValue, clientRegion);
123123
bucketExists();
124124
}
125125
}
@@ -178,7 +178,7 @@ private S3Client buildS3Client(String accessKey, String secretKey, String endpoi
178178
return s3Client;
179179
}
180180

181-
private S3Presigner buildS3Presigner(String accessKey, String secretKey, String region) {
181+
private S3Presigner buildS3Presigner(String accessKey, String secretKey, String endpoint, String region) {
182182
boolean bUseIAM = !getPropertyValue(USE_IAM, "", "").isEmpty() || (accessKey.equals("") && secretKey.equals(""));
183183

184184
S3Presigner.Builder builder = S3Presigner.builder()
@@ -193,6 +193,10 @@ private S3Presigner buildS3Presigner(String accessKey, String secretKey, String
193193
logger.debug("Using IAM Credentials for presigner");
194194
}
195195

196+
if (!endpoint.isEmpty() && !endpoint.contains(".amazonaws.com")) {
197+
builder.endpointOverride(URI.create(endpoint));
198+
}
199+
196200
return builder.build();
197201
}
198202

@@ -568,15 +572,27 @@ else if (url.startsWith(this.getStorageUriWithoutRegion()))
568572
}
569573

570574
private String getStorageUri() {
571-
return (!pathStyleUrls) ?
572-
"https://" + bucket + ".s3." + clientRegion + ".amazonaws.com/" :
573-
".s3." + clientRegion + ".amazonaws.com//" + bucket + "/";
575+
if (!pathStyleUrls) {
576+
if (endpointUrl.contains(".amazonaws.com")) {
577+
return "https://" + bucket + ".s3." + clientRegion + ".amazonaws.com/";
578+
} else {
579+
return endpointUrl + "/" + bucket + "/";
580+
}
581+
} else {
582+
return endpointUrl + "/" + bucket + "/";
583+
}
574584
}
575585

576586
private String getStorageUriWithoutRegion() {
577-
return (!pathStyleUrls) ?
578-
"https://" + bucket + ".s3.amazonaws.com/" :
579-
".s3.amazonaws.com//" + bucket + "/";
587+
if (!pathStyleUrls) {
588+
if (endpointUrl.contains(".amazonaws.com")) {
589+
return "https://" + bucket + ".s3.amazonaws.com/";
590+
} else {
591+
return endpointUrl + "/" + bucket + "/";
592+
}
593+
} else {
594+
return endpointUrl + "/" + bucket + "/";
595+
}
580596
}
581597

582598
// With ACL implementation
@@ -650,19 +666,27 @@ private String getResourceUrlWithACL(String externalFileName, ResourceAccessCont
650666
} else {
651667
try {
652668
int lastIndex = Math.max(externalFileName.lastIndexOf('/'), externalFileName.lastIndexOf('\\'));
653-
String path = externalFileName.substring(0, lastIndex + 1);
654-
String fileName = externalFileName.substring(lastIndex + 1);
669+
String path = lastIndex >= 0 ? externalFileName.substring(0, lastIndex + 1) : "";
670+
String fileName = lastIndex >= 0 ? externalFileName.substring(lastIndex + 1) : externalFileName;
655671
String encodedFileName = URLEncoder.encode(fileName, StandardCharsets.UTF_8.toString());
656672

657-
String url = String.format(
658-
"https://%s.s3.%s.amazonaws.com/%s%s",
659-
bucket,
660-
clientRegion,
661-
path,
662-
encodedFileName
663-
);
664-
665-
return url;
673+
if (endpointUrl.contains(".amazonaws.com")) {
674+
return String.format(
675+
"https://%s.s3.%s.amazonaws.com/%s%s",
676+
bucket,
677+
clientRegion,
678+
path,
679+
encodedFileName
680+
);
681+
} else {
682+
return String.format(
683+
"%s/%s/%s%s",
684+
endpointUrl,
685+
bucket,
686+
path,
687+
encodedFileName
688+
);
689+
}
666690
} catch (UnsupportedEncodingException uee) {
667691
logger.error("Failed to encode resource URL for " + externalFileName, uee);
668692
return "";
@@ -771,19 +795,27 @@ private String getResourceUrlWithoutACL(String externalFileName, int expirationM
771795
} else if (ownerEnforcedBucketPrivacy == BucketPrivacy.PUBLIC){
772796
try {
773797
int lastIndex = Math.max(externalFileName.lastIndexOf('/'), externalFileName.lastIndexOf('\\'));
774-
String path = externalFileName.substring(0, lastIndex + 1);
775-
String fileName = externalFileName.substring(lastIndex + 1);
798+
String path = lastIndex >= 0 ? externalFileName.substring(0, lastIndex + 1) : "";
799+
String fileName = lastIndex >= 0 ? externalFileName.substring(lastIndex + 1) : externalFileName;
776800
String encodedFileName = URLEncoder.encode(fileName, StandardCharsets.UTF_8.toString());
777801

778-
String url = String.format(
779-
"https://%s.s3.%s.amazonaws.com/%s%s",
780-
bucket,
781-
clientRegion,
782-
path,
783-
encodedFileName
784-
);
785-
786-
return url;
802+
if (endpointUrl.contains(".amazonaws.com")) {
803+
return String.format(
804+
"https://%s.s3.%s.amazonaws.com/%s%s",
805+
bucket,
806+
clientRegion,
807+
path,
808+
encodedFileName
809+
);
810+
} else {
811+
return String.format(
812+
"%s/%s/%s%s",
813+
endpointUrl,
814+
bucket,
815+
path,
816+
encodedFileName
817+
);
818+
}
787819
} catch (UnsupportedEncodingException uee) {
788820
logger.error("Failed to encode resource URL for {}", externalFileName, uee);
789821
return "";

0 commit comments

Comments
 (0)