Class Sha2FileCacheDataLoader

java.lang.Object
eu.europa.esig.dss.tsl.sha2.Sha2FileCacheDataLoader
All Implemented Interfaces:
DSSCacheFileLoader, DSSFileLoader, Serializable

public class Sha2FileCacheDataLoader extends Object implements DSSCacheFileLoader
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 Details

    • Sha2FileCacheDataLoader

      public Sha2FileCacheDataLoader()
      Creates an object with an empty configuration (shall be provided with a setter)
    • Sha2FileCacheDataLoader

      public Sha2FileCacheDataLoader(DSSCacheFileLoader dataLoader)
      Creates an object with a defined DSSCacheFileLoader. The predicate shall be provided with a setter.
      Parameters:
      dataLoader - DSSCacheFileLoader to use
  • Method Details

    • initSha2StrictDataLoader

      public static Sha2FileCacheDataLoader initSha2StrictDataLoader(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. The created object does not enforce refresh after a specific time period.
      Parameters:
      dataLoader - DSSCacheFileLoader to be used to load the document
      Returns:
      Sha2FileCacheDataLoader
    • initSha2DailyUpdateDataLoader

      public static Sha2FileCacheDataLoader initSha2DailyUpdateDataLoader(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.
      Parameters:
      dataLoader - DSSCacheFileLoader to 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 provided cacheExpirationTime value.
      Parameters:
      dataLoader - DSSCacheFileLoader to be used to load the document
      cacheExpirationTime - value in milliseconds indicating a maximum time after which a document shall be re-downloaded
      Returns:
      Sha2FileCacheDataLoader
    • initSha2IgnoredDataLoader

      public static Sha2FileCacheDataLoader initSha2IgnoredDataLoader(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.
      Parameters:
      dataLoader - DSSCacheFileLoader to be used to load the document
      Returns:
      Sha2FileCacheDataLoader
    • getDataLoader

      public DSSCacheFileLoader getDataLoader()
      Returns the file cache data loader used to load the documents
      Returns:
      DSSCacheFileLoader
    • setDataLoader

      public void setDataLoader(DSSCacheFileLoader dataLoader)
      Sets the file cache data loader to be used to load the documents
      Parameters:
      dataLoader - DSSCacheFileLoader
    • setPredicate

      public void setPredicate(Predicate<DocumentWithSha2> predicate)
      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

      public DSSDocument getDocument(String url) throws DSSException
      Description copied from interface: DSSFileLoader
      Returns DSSDocument from the provided url
      Specified by:
      getDocument in interface DSSFileLoader
      Parameters:
      url - String url of the document to obtain
      Returns:
      DSSDocument retrieved document
      Throws:
      DSSException - in case of DataLoader error
    • getDocument

      public DSSDocument getDocument(String url, boolean refresh)
      Description copied from interface: DSSCacheFileLoader
      This method allows to download a DSSDocument from a specified url with a custom setting indicating whether the refresh of the document's cache shall be enforced, when applicable
      Specified by:
      getDocument in interface DSSCacheFileLoader
      Parameters:
      url - String remote location of the document to download
      refresh - indicates whether the refresh of the cached document shall be enforced
      Returns:
      DSSDocument
    • getRefreshedDocument

      protected DSSDocument getRefreshedDocument(String documentUrl)
      This method returns a document from cache, when applicable. If no document is available in the cache, returns NULL.
      Parameters:
      documentUrl - String representing document's access point
      Returns:
      DSSDocument
    • getSha2File

      protected DSSDocument getSha2File(String documentUrl)
      This method returns a sha2 file for the given documentUrl. If not sha2 document found, returns NULL.
      Parameters:
      documentUrl - String URL of the document, for which to retrieve a sha2 file
      Returns:
      DSSDocument representing a sha2 file
    • getSha2FileUrl

      protected String getSha2FileUrl(String documentUrl)
      Method transforms a given documentUrl to a corresponding URL location containing a sha2 document
      Parameters:
      documentUrl - String URL of the document to be retrieved
      Returns:
      String URL of the sha2 corresponding to the document to be retrieved
    • assertExtensionIsSupported

      protected void assertExtensionIsSupported(String fileExtension)
      This method verifies whether the remote document's fileExtension is supported by the implementation. The Trusted Lists distribution points shall end with ".xml" or ".xtsl" strings
      Parameters:
      fileExtension - String to check
    • mergeDocumentWithSha2

      protected DocumentWithSha2 mergeDocumentWithSha2(DSSDocument cachedDocument, DSSDocument sha2Document)
      This class creates a eu.europa.esig.dss.tsl.sha2.DocumentWithSha2 object by merging a cachedDocument and sha2Document together
      Parameters:
      cachedDocument - DSSDocument representing an original cached document
      sha2Document - DSSDocument representing a sha2 document
      Returns:
      DocumentWithSha2
    • checkRefreshRequired

      protected boolean checkRefreshRequired(DocumentWithSha2 documentWithSha2)
      This method checks whether the cached document should be refreshed
      Parameters:
      documentWithSha2 - DocumentWithSha2 representing the original document with sha2 file content
      Returns:
      TRUE if the document shall be refreshed, FALSE otherwise
    • getDocumentFromCache

      public DSSDocument getDocumentFromCache(String url)
      Description copied from interface: DSSCacheFileLoader
      Allows 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:
      getDocumentFromCache in interface DSSCacheFileLoader
      Parameters:
      url - String url of the file
      Returns:
      DSSDocument or NULL if the file does not exist
    • remove

      public boolean remove(String url)
      Description copied from interface: DSSCacheFileLoader
      Removes the file from cache with the given url
      Specified by:
      remove in interface DSSCacheFileLoader
      Parameters:
      url - String url 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