Package eu.europa.esig.dss.tsl.sha2
Class Sha2FileCacheDataLoader
java.lang.Object
eu.europa.esig.dss.tsl.sha2.Sha2FileCacheDataLoader
- All Implemented Interfaces:
DSSCacheFileLoader,DSSFileLoader,Serializable
This class implements a document loading logic, defined within ETSI TS 119 612 "6.1 TL publication"
for Trusted Lists.
The class will try to access a corresponding .sha2 file for every requested document available in the cache,
compare its digest, and will enforce a document update if the document has expired.
The class provides constructors allowing manual configuration of the object, as well as static methods
allowing to instantiate pre-configured objects for Trusted Lists validation. See:
-
#initSha2StrictDataLoader method to create a dataloader, enforcing refresh of a Trusted List
only when a new .sha2 document is obtained or NextUpdate has been reached;
- #initSha2DailyUpdateDataLoader method to create a dataloader, enforcing refresh of a Trusted List
when a new .sha2 document is obtained, NextUpdate has been reached or when the document
has not been updated for at least 24 hours;
- #initSha2CustomExpirationDataLoader method to create a dataloader, enforcing refresh of a Trusted List
when a new .sha2 document is obtained, NextUpdate has been reached or when the document
has not been updated for the indicated time period;
- #initSha2IgnoredDataLoader method to create a dataloader, enforcing refresh of a Trusted List
in all cases.- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCreates an object with an empty configuration (shall be provided with a setter)Sha2FileCacheDataLoader(DSSCacheFileLoader dataLoader) Creates an object with a definedDSSCacheFileLoader. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidThis method verifies whether the configuration of the class is complete to proceed with executionprotected voidassertExtensionIsSupported(String fileExtension) This method verifies whether the remote document'sfileExtensionis supported by the implementation.protected booleancheckRefreshRequired(DocumentWithSha2 documentWithSha2) This method checks whether the cached document should be refreshedReturns the file cache data loader used to load the documentsgetDocument(String url) Returns DSSDocument from the provided urlgetDocument(String url, boolean refresh) This method allows to download aDSSDocumentfrom a specifiedurlwith a custom setting indicating whether therefreshof the document's cache shall be enforced, when applicableAllows to load a document for a given url from the cache folder.protected DSSDocumentgetRefreshedDocument(String documentUrl) This method returns a document from cache, when applicable.protected DSSDocumentgetSha2File(String documentUrl) This method returns a sha2 file for the givendocumentUrl.protected StringgetSha2FileUrl(String documentUrl) Method transforms a givendocumentUrlto a corresponding URL location containing a sha2 documentstatic Sha2FileCacheDataLoaderinitSha2CustomExpirationDataLoader(DSSCacheFileLoader dataLoader, long cacheExpirationTime) This method instantiates a Sha2FileCacheDataLoader with a pre-configured predicate, forcing a Trusted List refresh in case of an updated .sha2 document, when a NextUpdate has been reached, or when the cached document expired according to the providedcacheExpirationTimevalue.static Sha2FileCacheDataLoaderinitSha2DailyUpdateDataLoader(DSSCacheFileLoader dataLoader) This method instantiates a Sha2FileCacheDataLoader with a pre-configured predicate, forcing a Trusted List refresh in case of an updated .sha2 document, when a NextUpdate has been reached, or when the document has not been re-downloaded for at least a day.static Sha2FileCacheDataLoaderinitSha2IgnoredDataLoader(DSSCacheFileLoader dataLoader) This method instantiates a Sha2FileCacheDataLoader with a pre-configured predicate, forcing a Trusted List refresh in all cases despite the .sha2 file document content.static Sha2FileCacheDataLoaderinitSha2StrictDataLoader(DSSCacheFileLoader dataLoader) This method instantiates a Sha2FileCacheDataLoader with a pre-configured predicate, forcing a Trusted List refresh in case of an updated .sha2 document, or when a NextUpdate has been reached.protected DocumentWithSha2mergeDocumentWithSha2(DSSDocument cachedDocument, DSSDocument sha2Document) This class creates aeu.europa.esig.dss.tsl.sha2.DocumentWithSha2object by merging acachedDocumentandsha2DocumenttogetherbooleanRemoves the file from cache with the given urlvoidsetDataLoader(DSSCacheFileLoader dataLoader) Sets the file cache data loader to be used to load the documentsvoidsetPredicate(Predicate<DocumentWithSha2> predicate) This method sets a predicate evaluating a condition for a document to be refreshed.
-
Constructor Details
-
Sha2FileCacheDataLoader
public Sha2FileCacheDataLoader()Creates an object with an empty configuration (shall be provided with a setter) -
Sha2FileCacheDataLoader
Creates an object with a definedDSSCacheFileLoader. Thepredicateshall be provided with a setter.- Parameters:
dataLoader-DSSCacheFileLoaderto use
-
-
Method Details
-
initSha2StrictDataLoader
This method instantiates a Sha2FileCacheDataLoader with a pre-configured predicate, forcing a Trusted List refresh in case of an updated .sha2 document, or when a NextUpdate has been reached. The created object does not enforce refresh after a specific time period.- Parameters:
dataLoader-DSSCacheFileLoaderto be used to load the document- Returns:
Sha2FileCacheDataLoader
-
initSha2DailyUpdateDataLoader
This method instantiates a Sha2FileCacheDataLoader with a pre-configured predicate, forcing a Trusted List refresh in case of an updated .sha2 document, when a NextUpdate has been reached, or when the document has not been re-downloaded for at least a day.- Parameters:
dataLoader-DSSCacheFileLoaderto be used to load the document- Returns:
Sha2FileCacheDataLoader
-
initSha2CustomExpirationDataLoader
public static Sha2FileCacheDataLoader initSha2CustomExpirationDataLoader(DSSCacheFileLoader dataLoader, long cacheExpirationTime) This method instantiates a Sha2FileCacheDataLoader with a pre-configured predicate, forcing a Trusted List refresh in case of an updated .sha2 document, when a NextUpdate has been reached, or when the cached document expired according to the providedcacheExpirationTimevalue.- Parameters:
dataLoader-DSSCacheFileLoaderto be used to load the documentcacheExpirationTime- value in milliseconds indicating a maximum time after which a document shall be re-downloaded- Returns:
Sha2FileCacheDataLoader
-
initSha2IgnoredDataLoader
This method instantiates a Sha2FileCacheDataLoader with a pre-configured predicate, forcing a Trusted List refresh in all cases despite the .sha2 file document content.- Parameters:
dataLoader-DSSCacheFileLoaderto be used to load the document- Returns:
Sha2FileCacheDataLoader
-
getDataLoader
Returns the file cache data loader used to load the documents- Returns:
DSSCacheFileLoader
-
setDataLoader
Sets the file cache data loader to be used to load the documents- Parameters:
dataLoader-DSSCacheFileLoader
-
setPredicate
This method sets a predicate evaluating a condition for a document to be refreshed. The predicate returns TRUE when the condition is valid and no document refresh is required, FALSE otherwise- Parameters:
predicate-Predicate
-
getDocument
Description copied from interface:DSSFileLoaderReturns DSSDocument from the provided url- Specified by:
getDocumentin interfaceDSSFileLoader- Parameters:
url-Stringurl of the document to obtain- Returns:
DSSDocumentretrieved document- Throws:
DSSException- in case of DataLoader error
-
getDocument
Description copied from interface:DSSCacheFileLoaderThis method allows to download aDSSDocumentfrom a specifiedurlwith a custom setting indicating whether therefreshof the document's cache shall be enforced, when applicable- Specified by:
getDocumentin interfaceDSSCacheFileLoader- Parameters:
url-Stringremote location of the document to downloadrefresh- indicates whether the refresh of the cached document shall be enforced- Returns:
DSSDocument
-
getRefreshedDocument
This method returns a document from cache, when applicable. If no document is available in the cache, returns NULL.- Parameters:
documentUrl-Stringrepresenting document's access point- Returns:
DSSDocument
-
getSha2File
This method returns a sha2 file for the givendocumentUrl. If not sha2 document found, returns NULL.- Parameters:
documentUrl-StringURL of the document, for which to retrieve a sha2 file- Returns:
DSSDocumentrepresenting a sha2 file
-
getSha2FileUrl
-
assertExtensionIsSupported
-
mergeDocumentWithSha2
protected DocumentWithSha2 mergeDocumentWithSha2(DSSDocument cachedDocument, DSSDocument sha2Document) This class creates aeu.europa.esig.dss.tsl.sha2.DocumentWithSha2object by merging acachedDocumentandsha2Documenttogether- Parameters:
cachedDocument-DSSDocumentrepresenting an original cached documentsha2Document-DSSDocumentrepresenting a sha2 document- Returns:
DocumentWithSha2
-
checkRefreshRequired
This method checks whether the cached document should be refreshed- Parameters:
documentWithSha2-DocumentWithSha2representing the original document with sha2 file content- Returns:
- TRUE if the document shall be refreshed, FALSE otherwise
-
getDocumentFromCache
Description copied from interface:DSSCacheFileLoaderAllows to load a document for a given url from the cache folder. If the document is not found in the cache, returns NULL.- Specified by:
getDocumentFromCachein interfaceDSSCacheFileLoader- Parameters:
url-Stringurl of the file- Returns:
DSSDocumentor NULL if the file does not exist
-
remove
Description copied from interface:DSSCacheFileLoaderRemoves the file from cache with the given url- Specified by:
removein interfaceDSSCacheFileLoader- Specified by:
removein interfaceDSSFileLoader- Parameters:
url-Stringurl of the remote file location (the same what was used on file saving)- Returns:
- TRUE when file was successfully deleted, FALSE otherwise
-
assertConfigurationIsValid
protected void assertConfigurationIsValid()This method verifies whether the configuration of the class is complete to proceed with execution
-