diff --git a/src/main/java/org/commonjava/util/sidecar/jaxrs/FoloContentAccessResource.java b/src/main/java/org/commonjava/util/sidecar/jaxrs/FoloContentAccessResource.java index a4ef1a9..8bfd758 100644 --- a/src/main/java/org/commonjava/util/sidecar/jaxrs/FoloContentAccessResource.java +++ b/src/main/java/org/commonjava/util/sidecar/jaxrs/FoloContentAccessResource.java @@ -22,6 +22,7 @@ import org.apache.commons.io.FileUtils; import org.commonjava.util.sidecar.services.ArchiveRetrieveService; import org.commonjava.util.sidecar.services.ProxyService; +import org.commonjava.util.sidecar.services.ReportService; import org.commonjava.util.sidecar.util.TransferStreamingOutput; import org.eclipse.microprofile.openapi.annotations.Operation; import org.eclipse.microprofile.openapi.annotations.media.Schema; @@ -65,6 +66,9 @@ public class FoloContentAccessResource @Inject ArchiveRetrieveService archiveService; + @Inject + ReportService reportService; + @Operation( description = "Retrieve Maven/NPM artifact content from historical archive or proxy" ) @APIResponse( responseCode = "200", description = "Content stream" ) @APIResponse( responseCode = "404", description = "Content is not available" ) @@ -86,7 +90,7 @@ public Uni get( @Parameter( in = PATH, required = true ) @PathParam( " } Optional download = archiveService.getLocally( path ); - if ( download.isPresent() && download.get().isFile() ) + if ( download.isPresent() && download.get().isFile() && reportService.checkValidHistoricalEntryMeta( path ) ) { Uni checksumValidation = proxyService.validateChecksum( id, packageType, type, name, path, request ); diff --git a/src/main/java/org/commonjava/util/sidecar/services/ReportService.java b/src/main/java/org/commonjava/util/sidecar/services/ReportService.java index 79cd7cc..6959ad7 100644 --- a/src/main/java/org/commonjava/util/sidecar/services/ReportService.java +++ b/src/main/java/org/commonjava/util/sidecar/services/ReportService.java @@ -109,17 +109,7 @@ public void storeTrackedDownload( JsonObject message ) logger.debug( "Consuming folo record seal event for path:{}, trackingId:{}", trackingPath, trackingId ); HistoricalEntryDTO entryDTO = historicalContentMap.get( trackingPath ); - if ( null == entryDTO ) - { - logger.warn( "No historical entry meta is found for tracking {}.", trackingPath ); - return; - } StoreKey storeKey = entryDTO.getStoreKey(); - if ( null == storeKey ) - { - logger.warn( "No StoreKey is found for tracking {} historical entry.", trackingPath ); - return; - } String originalUrl = entryDTO.getOriginUrl() == null ? "" : entryDTO.getOriginUrl(); boolean exception = false; try @@ -151,4 +141,21 @@ public HashMap getHistoricalContentMap() { return historicalContentMap; } + + public boolean checkValidHistoricalEntryMeta( String trackingPath ) + { + HistoricalEntryDTO entryDTO = historicalContentMap.get( trackingPath ); + if ( entryDTO == null ) + { + logger.warn( "Check no matched historical entry meta is found for tracking path: {}.", trackingPath ); + return false; + } + StoreKey storeKey = entryDTO.getStoreKey(); + if ( storeKey == null ) + { + logger.warn( "Check no valid historical StoreKey is found for tracking path: {}.", trackingPath ); + return false; + } + return true; + } }