Skip to content

Commit f02912c

Browse files
committed
Pull request #144: Support for authentication in user-provided remote artifacts (OAuth2.0, HTTP basic, HTTP header)
Merge in ITB/csv-validator from development to master * commit 'f32c7c92b132b3992b7fc077043c5af810063ef0': Support for authentication in user-provided remote artifacts (OAuth2.0, HTTP basic, HTTP header)
2 parents 7f042cb + f32c7c9 commit f02912c

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

csvvalidator-web/src/main/java/eu/europa/ec/itb/csv/web/UploadController.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
import eu.europa.ec.itb.validation.commons.web.dto.Translations;
3838
import eu.europa.ec.itb.validation.commons.web.dto.UploadResult;
3939
import eu.europa.ec.itb.validation.commons.web.locale.CustomLocaleResolver;
40+
import jakarta.servlet.http.HttpServletRequest;
41+
import jakarta.servlet.http.HttpServletResponse;
4042
import org.apache.commons.io.FileUtils;
4143
import org.apache.commons.lang3.StringUtils;
4244
import org.apache.commons.lang3.tuple.Pair;
@@ -53,14 +55,14 @@
5355
import org.springframework.web.servlet.ModelAndView;
5456
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
5557

56-
import jakarta.servlet.http.HttpServletRequest;
57-
import jakarta.servlet.http.HttpServletResponse;
5858
import java.io.ByteArrayInputStream;
5959
import java.io.File;
6060
import java.io.IOException;
6161
import java.io.InputStream;
6262
import java.net.http.HttpClient;
63+
import java.net.http.HttpRequest;
6364
import java.util.*;
65+
import java.util.function.Consumer;
6466

6567
import static eu.europa.ec.itb.validation.commons.web.Constants.*;
6668

@@ -236,7 +238,7 @@ public UploadResult<Translations> handleUpload(@PathVariable("domain") String do
236238
}
237239
List<FileInfo> externalSchemas = new ArrayList<>();
238240
try {
239-
externalSchemas = getExternalFiles(externalSchemaContentType, externalSchemaFiles, externalSchemaUri, externalSchemaString, domainConfig.getSchemaInfo(validationType), tempFolderForRequest, domainConfig.getHttpVersion());
241+
externalSchemas = getExternalFiles(externalSchemaContentType, externalSchemaFiles, externalSchemaUri, externalSchemaString, domainConfig.getSchemaInfo(validationType), tempFolderForRequest, domainConfig.getHttpVersion(), domainConfig);
240242
} catch (ValidatorException e) {
241243
LOG.error(e.getMessageForLog(), e);
242244
result.setMessage(e.getMessageForDisplay(localisationHelper));
@@ -468,14 +470,16 @@ public ModelAndView handleUploadMinimalEmbedded(@PathVariable("domain") String d
468470
* @param schemaInfo The schema information from the domain.
469471
* @param parentFolder The temporary folder to use for file system storage.
470472
* @param httpVersion The HTTP version to use.
473+
* @param domainConfig The domain configuration.
471474
* @return The list of user-provided artifacts.
472475
* @throws IOException If an error occurs.
473476
*/
474477
private List<FileInfo> getExternalFiles(String[] externalContentType, MultipartFile[] externalFiles, String[] externalUri, String[] externalString,
475-
ValidationArtifactInfo schemaInfo, File parentFolder, HttpClient.Version httpVersion) throws IOException {
478+
ValidationArtifactInfo schemaInfo, File parentFolder, HttpClient.Version httpVersion, DomainConfig domainConfig) throws IOException {
476479
List<FileInfo> externalArtifacts = new ArrayList<>();
477480
if (externalContentType != null) {
478-
for(int i=0; i < externalContentType.length; i++) {
481+
Consumer<HttpRequest.Builder> requestDecorator = fileManager.createRemoteFileRequestDecorator(domainConfig, schemaInfo);
482+
for (int i=0; i < externalContentType.length; i++) {
479483
if (StringUtils.isNotBlank(externalContentType[i])) {
480484
File inputFile;
481485
MultipartFile currentExtFile = null;
@@ -490,9 +494,9 @@ private List<FileInfo> getExternalFiles(String[] externalContentType, MultipartF
490494
if (externalString != null && externalString.length>i) {
491495
currentExtString = externalString[i];
492496
}
493-
inputFile = getInputFile(externalContentType[i], currentExtFile, currentExtUri, currentExtString, parentFolder, httpVersion);
497+
inputFile = getInputFile(externalContentType[i], currentExtFile, currentExtUri, currentExtString, parentFolder, httpVersion, requestDecorator);
494498
if (inputFile != null) {
495-
externalArtifacts.add(new FileInfo(inputFile));
499+
externalArtifacts.add(new FileInfo(inputFile, null, null, requestDecorator));
496500
}
497501
}
498502
}
@@ -542,10 +546,11 @@ private boolean validateExternalFiles(List<FileInfo> externalArtifacts, Validati
542546
* @param inputString The provided direct input to load the content from.
543547
* @param parentFolder The temporary folder to use.
544548
* @param httpVersion The HTTP version to use.
549+
* @param requestDecorator The request decorator to use.
545550
* @return The input content's file.
546551
* @throws IOException If an error occurs.
547552
*/
548-
private File getInputFile(String contentType, MultipartFile inputFile, String inputUri, String inputString, File parentFolder, HttpClient.Version httpVersion) throws IOException {
553+
private File getInputFile(String contentType, MultipartFile inputFile, String inputUri, String inputString, File parentFolder, HttpClient.Version httpVersion, Consumer<HttpRequest.Builder> requestDecorator) throws IOException {
549554
File file = null;
550555
if (CONTENT_TYPE_FILE.equals(contentType)) {
551556
if (inputFile!=null && !inputFile.isEmpty()) {
@@ -555,7 +560,7 @@ private File getInputFile(String contentType, MultipartFile inputFile, String in
555560
}
556561
} else if (CONTENT_TYPE_URI.equals(contentType)) {
557562
if (StringUtils.isNotBlank(inputUri)) {
558-
file = this.fileManager.getFileFromURL(parentFolder, inputUri, httpVersion);
563+
file = this.fileManager.getFileFromURL(parentFolder, inputUri, null, null, null, null, null, null, httpVersion, requestDecorator).getFile();
559564
}
560565
} else if (CONTENT_TYPE_STRING.equals(contentType)) {
561566
if (StringUtils.isNotBlank(inputString)) {

0 commit comments

Comments
 (0)