Class LotlService

java.lang.Object
com.itextpdf.signatures.validation.lotl.LotlService
All Implemented Interfaces:
AutoCloseable

public class LotlService extends Object implements AutoCloseable
This class provides services for managing the List of Trusted Lists (Lotl) and related resources. It includes methods for fetching, validating, and caching Lotl data, as well as managing the European Resource Fetcher and Country-Specific Lotl Fetcher. It also allows for setting custom resource retrievers and cache timeouts.
  • Constructor Details

  • Method Details

    • initializeGlobalCache

      public static void initializeGlobalCache (LotlFetchingProperties lotlFetchingProperties)
      Initializes the global cache with the provided LotlFetchingProperties. This method must be called before using the LotlService to ensure that the cache is set up.

      If you are using a custom implementation of LotlService you can use the instance method.

      Parameters:
      lotlFetchingProperties - the LotlFetchingProperties to use for initializing the cache
    • getGlobalService

      public static LotlService getGlobalService()
      Gets global static instance of LotlService.
      Returns:
      global static instance of LotlService
    • withLotlServiceCache

      public LotlService withLotlServiceCache (LotlServiceCache cache)
      Sets the cache for the LotlService.

      This method allows you to provide a custom implementation of LotlServiceCache to be used for caching Lotl data, pivot files, and country-specific Lotls.

      Parameters:
      cache - the custom cache to be used for caching Lotl data
      Returns:
      the current instance of LotlService for method chaining
    • withCustomResourceRetriever

      public final LotlService withCustomResourceRetriever (IResourceRetriever resourceRetriever)
      Sets a custom resource retriever for fetching resources.

      This method allows you to provide a custom implementation of IResourceRetriever to be used for fetching resources such as the Lotl XML, pivot files, and country-specific Lotls.

      Parameters:
      resourceRetriever - the custom resource retriever to be used for fetching resources
      Returns:
      the current instance of LotlService for method chaining
    • initializeCache

      public void initializeCache()
      Initializes the cache with the latest Lotl data and related resources.
    • withPivotFetcher

      public LotlService withPivotFetcher (PivotFetcher pivotFetcher)
      Sets the pivot fetcher for the Lotl service.
      Parameters:
      pivotFetcher - the pivot fetcher to be used for fetching and validating pivot files
      Returns:
      the current instance of LotlService for method chaining
    • withCountrySpecificLotlFetcher

      public LotlService withCountrySpecificLotlFetcher (CountrySpecificLotlFetcher countrySpecificLotlFetcher)
      Sets the country-specific Lotl fetcher for the Lotl service.
      Parameters:
      countrySpecificLotlFetcher - the country-specific Lotl fetcher to be used for fetching and validating country-specific Lotls
      Returns:
      the current instance of LotlService for method chaining
    • withEuropeanLotlFetcher

      public LotlService withEuropeanLotlFetcher (EuropeanLotlFetcher fetcher)
      Sets the European List of Trusted Lists (Lotl) byte fetcher for the Lotl service.
      Parameters:
      fetcher - the fetcher to be used for fetching the Lotl XML data
      Returns:
      the current instance of LotlService for method chaining
    • withXmlSignatureValidator

      public LotlService withXmlSignatureValidator (Function<TrustedCertificatesStore,XmlSignatureValidator> xmlSignatureValidatorFactory)
      Sets up factory which is responsible for XmlSignatureValidator creation.
      Parameters:
      xmlSignatureValidatorFactory - factory responsible for XmlSignatureValidator creation
      Returns:
      the current instance of LotlService for method chaining
    • withLotlValidator

      public LotlService withLotlValidator (Supplier<LotlValidator> lotlValidatorFactory)
      Sets up factory which is responsible for LotlValidator creation.
      Parameters:
      lotlValidatorFactory - factory responsible for LotlValidator creation
      Returns:
      this same instance of LotlService
    • withEuropeanResourceFetcher

      public LotlService withEuropeanResourceFetcher (EuropeanResourceFetcher europeanResourceFetcher)
      Sets the European Resource Fetcher for the LotlService.
      Parameters:
      europeanResourceFetcher - the European Resource Fetcher to be used for fetching EU journal certificates
      Returns:
      the current instance of LotlService for method chaining
    • close

      public void close()
      .
      Specified by:
      close in interface AutoCloseable
    • setupTimer

      protected void setupTimer()
      Sets up a timer to periodically refresh the LOTL cache.

      The timer will use the refresh interval calculated based on the stale-ness of the cache. If the cache is null, it will create a new instance of InMemoryLotlServiceCache.

    • cancelTimer

      protected void cancelTimer()
      Cancels timer, if it was already set up.
    • tryAndRefreshCache

      protected void tryAndRefreshCache()
      This method is intended to refresh the cache, it will try to download the latest LOTL data and update the cache accordingly.

      The rules taken into account are: Country specific LOTL files will be fetched, validated and updated per country. If country fails to fetch, LotlFetchingProperties.getOnCountryFetchFailureStrategy() will be used to perform corresponding action.

      For the main LOTL file, if the fetch fails, the cache will not be updated. Also, we will NOT proceed to update the pivot files. If the main LOTL file is fetched successfully, the pivot files will be fetched, validated and stored in the cache.