Skip to content

Commit

Permalink
Merge pull request #1105 from paulcwarren/feat/client-side-encryption
Browse files Browse the repository at this point in the history
Getting a resource's lastModified is safe
  • Loading branch information
paulcwarren authored Oct 6, 2022
2 parents 3b08ab1 + a007c8d commit eff6da9
Showing 1 changed file with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package internal.org.springframework.content.rest.controllers;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.FileSystemNotFoundException;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;
Expand Down Expand Up @@ -84,12 +86,7 @@ public void getContent(HttpServletRequest request,

StoreResource storeResource = (StoreResource)resource;

long lastModified = -1;
try {
lastModified = storeResource.lastModified();
} catch (IOException e) {}

if(new ServletWebRequest(request, response).checkNotModified(storeResource.getETag() != null ? storeResource.getETag().toString() : null, lastModified)) {
if(new ServletWebRequest(request, response).checkNotModified(storeResource.getETag() != null ? storeResource.getETag().toString() : null, resolveLastModified(storeResource))) {
return;
}

Expand Down Expand Up @@ -184,7 +181,7 @@ public void deleteContent(@RequestHeader HttpHeaders headers, HttpServletRespons
if (!resource.exists()) {
throw new ResourceNotFoundException();
} else {
HeaderUtils.evaluateHeaderConditions(headers, storeResource.getETag() != null ? storeResource.getETag().toString() : null, new Date(storeResource.lastModified()));
HeaderUtils.evaluateHeaderConditions(headers, storeResource.getETag() != null ? storeResource.getETag().toString() : null, new Date(resolveLastModified(storeResource)));
}

ContentService contentService = contentServiceFactory.getContentService(storeResource);
Expand All @@ -205,7 +202,7 @@ protected void handleMultipart(HttpServletRequest request, HttpServletResponse r
boolean isNew = false;

if (target.exists()) {
HeaderUtils.evaluateHeaderConditions(headers, targetETag != null ? targetETag.toString() : null, new Date(target.lastModified()));
HeaderUtils.evaluateHeaderConditions(headers, targetETag != null ? targetETag.toString() : null, new Date(resolveLastModified(target)));
} else {
isNew = true;
}
Expand All @@ -220,6 +217,15 @@ protected void handleMultipart(HttpServletRequest request, HttpServletResponse r
}
}

protected static long resolveLastModified(StoreResource storeResource) {
long lastModified = -1L;
try {
lastModified = storeResource.lastModified();
} catch (FileSystemNotFoundException fnfe) {
} catch (IOException e) {}
return lastModified;
}

@Override
public void afterPropertiesSet() throws Exception {

Expand All @@ -236,4 +242,4 @@ public void afterPropertiesSet() throws Exception {

contentServiceFactory = new ContentServiceFactory(config, repositories, repoInvokerFactory, stores, mappingContext, byteRangeRestRequestHandler);
}
}
}

0 comments on commit eff6da9

Please sign in to comment.