Class Sha2FileCacheDataLoader

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

public class Sha2FileCacheDataLoader extends Object implements eu.europa.esig.dss.spi.client.http.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 Summary

    Constructors
    Constructor
    Description
    Creates an object with an empty configuration (shall be provided with a setter)
    Sha2FileCacheDataLoader(eu.europa.esig.dss.spi.client.http.DSSCacheFileLoader dataLoader)
    Creates an object with a defined DSSCacheFileLoader.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    This method verifies whether the configuration of the class is complete to proceed with execution
    protected void
    This method verifies whether the remote document's fileExtension is supported by the implementation.
    protected boolean
    This method checks whether the cached document should be refreshed
    eu.europa.esig.dss.spi.client.http.DSSCacheFileLoader
    Returns the file cache data loader used to load the documents
    eu.europa.esig.dss.model.DSSDocument
     
    eu.europa.esig.dss.model.DSSDocument
    getDocument(String url, boolean refresh)
     
    eu.europa.esig.dss.model.DSSDocument
     
    protected eu.europa.esig.dss.model.DSSDocument
    This method returns a document from cache, when applicable.
    protected eu.europa.esig.dss.model.DSSDocument
    getSha2File(String documentUrl)
    This method returns a sha2 file for the given documentUrl.
    protected String
    getSha2FileUrl(String documentUrl)
    Method transforms a given documentUrl to a corresponding URL location containing a sha2 document
    initSha2CustomExpirationDataLoader(eu.europa.esig.dss.spi.client.http.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.
    initSha2DailyUpdateDataLoader(eu.europa.esig.dss.spi.client.http.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.
    initSha2IgnoredDataLoader(eu.europa.esig.dss.spi.client.http.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.
    initSha2StrictDataLoader(eu.europa.esig.dss.spi.client.http.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.
    mergeDocumentWithSha2(eu.europa.esig.dss.model.DSSDocument cachedDocument, eu.europa.esig.dss.model.DSSDocument sha2Document)
    This class creates a eu.europa.esig.dss.tsl.sha2.DocumentWithSha2 object by merging a cachedDocument and sha2Document together
    boolean
     
    void
    setDataLoader(eu.europa.esig.dss.spi.client.http.DSSCacheFileLoader dataLoader)
    Sets the file cache data loader to be used to load the documents
    void
    This method sets a predicate evaluating a condition for a document to be refreshed.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Sha2FileCacheDataLoader

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

      public Sha2FileCacheDataLoader(eu.europa.esig.dss.spi.client.http.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(eu.europa.esig.dss.spi.client.http.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(eu.europa.esig.dss.spi.client.http.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(eu.europa.esig.dss.spi.client.http.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(eu.europa.esig.dss.spi.client.http.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 eu.europa.esig.dss.spi.client.http.DSSCacheFileLoader getDataLoader()
      Returns the file cache data loader used to load the documents
      Returns:
      DSSCacheFileLoader
    • setDataLoader

      public void setDataLoader(eu.europa.esig.dss.spi.client.http.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 eu.europa.esig.dss.model.DSSDocument getDocument(String url) throws eu.europa.esig.dss.model.DSSException
      Specified by:
      getDocument in interface eu.europa.esig.dss.spi.client.http.DSSFileLoader
      Throws:
      eu.europa.esig.dss.model.DSSException
    • getDocument

      public eu.europa.esig.dss.model.DSSDocument getDocument(String url, boolean refresh)
      Specified by:
      getDocument in interface eu.europa.esig.dss.spi.client.http.DSSCacheFileLoader
    • getRefreshedDocument

      protected eu.europa.esig.dss.model.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 eu.europa.esig.dss.model.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(eu.europa.esig.dss.model.DSSDocument cachedDocument, eu.europa.esig.dss.model.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 eu.europa.esig.dss.model.DSSDocument getDocumentFromCache(String url)
      Specified by:
      getDocumentFromCache in interface eu.europa.esig.dss.spi.client.http.DSSCacheFileLoader
    • remove

      public boolean remove(String url)
      Specified by:
      remove in interface eu.europa.esig.dss.spi.client.http.DSSCacheFileLoader
    • assertConfigurationIsValid

      protected void assertConfigurationIsValid()
      This method verifies whether the configuration of the class is complete to proceed with execution