From c1cce1ddf927b6ace65e1b5146c94625c055207b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B3nio=20Lindo?= Date: Fri, 2 Aug 2024 17:24:45 +0100 Subject: [PATCH] wip --- .../java/com/databasepreservation/DBVTK.java | 8 ++--- .../common/api/v1/FileResource.java | 31 +++++++++++++++++-- .../transformers/DenormalizeTransformer.java | 1 + src/main/webapp/WEB-INF/web.xml | 10 +++--- 4 files changed, 39 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/databasepreservation/DBVTK.java b/src/main/java/com/databasepreservation/DBVTK.java index abcc4666..83ab0945 100644 --- a/src/main/java/com/databasepreservation/DBVTK.java +++ b/src/main/java/com/databasepreservation/DBVTK.java @@ -130,7 +130,7 @@ public FilterRegistrationBean casSingleSignOutFilter() { FilterRegistrationBean registrationBean = new FilterRegistrationBean<>(); registrationBean.setFilter(new OnOffFilter()); registrationBean.setName("CasSingleSignOutFilter"); - registrationBean.addInitParameter("inner-filter-class", "org.jasig.cas.client.session.SingleSignOutFilter"); + registrationBean.addInitParameter("inner-filter-class", "org.apereo.cas.client.session.SingleSignOutFilter"); registrationBean.addInitParameter("config-prefix", "ui.filter.cas"); registrationBean.addInitParameter("casServerUrlPrefix", "http://localhost:8888/cas"); registrationBean.addUrlPatterns("/*"); @@ -149,7 +149,7 @@ public FilterRegistrationBean casValidationFilter() { registrationBean.setFilter(new OnOffFilter()); registrationBean.setName("CasValidationFilter"); registrationBean.addInitParameter("inner-filter-class", - "org.jasig.cas.client.validation.Cas30ProxyReceivingTicketValidationFilter"); + "org.apereo.cas.client.validation.Cas30ProxyReceivingTicketValidationFilter"); registrationBean.addInitParameter("config-prefix", "ui.filter.cas"); registrationBean.addInitParameter("casServerUrlPrefix", "https://localhost:8443/cas"); registrationBean.addInitParameter("serverName", "https://localhost:8888"); @@ -168,7 +168,7 @@ public FilterRegistrationBean casAuthenticationFilter() { FilterRegistrationBean registrationBean = new FilterRegistrationBean<>(); registrationBean.setFilter(new OnOffFilter()); registrationBean.setName("CasAuthenticationFilter"); - registrationBean.addInitParameter("inner-filter-class", "org.jasig.cas.client.authentication.AuthenticationFilter"); + registrationBean.addInitParameter("inner-filter-class", "org.apereo.cas.client.authentication.AuthenticationFilter"); registrationBean.addInitParameter("config-prefix", "ui.filter.cas"); registrationBean.addInitParameter("casServerLoginUrl", "https://localhost:8443/cas/login"); registrationBean.addUrlPatterns("/login"); @@ -182,7 +182,7 @@ public FilterRegistrationBean casRequestWrapperFilter() { registrationBean.setFilter(new OnOffFilter()); registrationBean.setName("CasRequestWrapperFilter"); registrationBean.addInitParameter("inner-filter-class", - "org.jasig.cas.client.util.HttpServletRequestWrapperFilter"); + "org.apereo.cas.client.util.HttpServletRequestWrapperFilter"); registrationBean.addInitParameter("config-prefix", "ui.filter.cas"); registrationBean.addUrlPatterns("/*"); diff --git a/src/main/java/com/databasepreservation/common/api/v1/FileResource.java b/src/main/java/com/databasepreservation/common/api/v1/FileResource.java index d07af37b..9b478f5d 100644 --- a/src/main/java/com/databasepreservation/common/api/v1/FileResource.java +++ b/src/main/java/com/databasepreservation/common/api/v1/FileResource.java @@ -10,11 +10,14 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; +import java.io.FileOutputStream; import java.io.IOException; import java.nio.file.Paths; import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; import org.roda.core.data.exceptions.AlreadyExistsException; import org.roda.core.data.exceptions.GenericException; @@ -87,8 +90,12 @@ public ResponseEntity getSIARDFile(String filename) { java.nio.file.Path basePath = Paths.get(ViewerConfiguration.getInstance().getViewerConfigurationAsString("/", ViewerConfiguration.PROPERTY_BASE_UPLOAD_PATH)); java.nio.file.Path siardPath = siardFilesPath.resolve(filename); - if (java.nio.file.Files.exists(siardPath) && !java.nio.file.Files.isDirectory(siardPath) - && (ViewerConfiguration.checkPathIsWithin(siardPath, siardFilesPath) + + if (java.nio.file.Files.isDirectory(siardPath)) { + siardPath = zipDirectory(siardPath); + } + + if (java.nio.file.Files.exists(siardPath) && (ViewerConfiguration.checkPathIsWithin(siardPath, siardFilesPath) || ViewerConfiguration.checkPathIsWithin(siardPath, basePath))) { InputStreamResource resource = new InputStreamResource(new FileInputStream(siardPath.toFile())); @@ -101,12 +108,32 @@ public ResponseEntity getSIARDFile(String filename) { } catch (NotFoundException | FileNotFoundException e) { state = LogEntryState.FAILURE; throw new RESTException(e); + } catch (IOException e) { + throw new RESTException(e); } finally { // register action controllerAssistant.registerAction(user, state, ViewerConstants.CONTROLLER_FILENAME_PARAM, filename); } } + private java.nio.file.Path zipDirectory(java.nio.file.Path dirPath) throws IOException { + java.nio.file.Path zipFilePath = dirPath.resolveSibling(dirPath.getFileName().toString() + ".zip"); + try (FileOutputStream fos = new FileOutputStream(zipFilePath.toFile()); + ZipOutputStream zos = new ZipOutputStream(fos)) { + java.nio.file.Files.walk(dirPath).filter(path -> !java.nio.file.Files.isDirectory(path)).forEach(path -> { + ZipEntry zipEntry = new ZipEntry(dirPath.relativize(path).toString()); + try { + zos.putNextEntry(zipEntry); + java.nio.file.Files.copy(path, zos); + zos.closeEntry(); + } catch (IOException e) { + throw new RuntimeException(e); + } + }); + } + return zipFilePath; + } + @Override public void deleteSiardFile(String filename) { final ControllerAssistant controllerAssistant = new ControllerAssistant() {}; diff --git a/src/main/java/com/databasepreservation/common/transformers/DenormalizeTransformer.java b/src/main/java/com/databasepreservation/common/transformers/DenormalizeTransformer.java index f94f96c3..0e2c8dc5 100644 --- a/src/main/java/com/databasepreservation/common/transformers/DenormalizeTransformer.java +++ b/src/main/java/com/databasepreservation/common/transformers/DenormalizeTransformer.java @@ -265,6 +265,7 @@ private void createdNestedDocument(ViewerRow row, String parentUUID, Listcom.databasepreservation.common.filter.OnOffFilter inner-filter-class - org.jasig.cas.client.session.SingleSignOutFilter + org.apereo.cas.client.session.SingleSignOutFilter config-prefix @@ -100,7 +100,7 @@ - org.jasig.cas.client.session.SingleSignOutHttpSessionListener + org.apereo.cas.client.session.SingleSignOutHttpSessionListener @@ -109,7 +109,7 @@ com.databasepreservation.common.filter.OnOffFilter inner-filter-class - org.jasig.cas.client.validation.Cas30ProxyReceivingTicketValidationFilter + org.apereo.cas.client.validation.Cas30ProxyReceivingTicketValidationFilter config-prefix @@ -150,7 +150,7 @@ com.databasepreservation.common.filter.OnOffFilter inner-filter-class - org.jasig.cas.client.authentication.AuthenticationFilter + org.apereo.cas.client.authentication.AuthenticationFilter config-prefix @@ -175,7 +175,7 @@ com.databasepreservation.common.filter.OnOffFilter inner-filter-class - org.jasig.cas.client.util.HttpServletRequestWrapperFilter + org.apereo.cas.client.util.HttpServletRequestWrapperFilter config-prefix