Class LotlService
- All Implemented Interfaces:
-
AutoCloseable
- Direct Known Subclasses:
-
EuropeanLotlService,SingleFileLotlService
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionLotlService(LotlFetchingProperties lotlFetchingProperties) Creates a new instance ofLotlService. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidCancels timer, if it was already set up.voidclose()static LotlServiceGets global static instance ofLotlService.Retrieves national trusted certificates.Get the validation results for the List of Trusted Lists (LOTL).voidInitializes the cache with the latest LOTL data and related resources.voidinitializeCache(InputStream stream) Initializes the cache with the latest LOTL data and related resources.static voidinitializeGlobalCache(LotlFetchingProperties lotlFetchingProperties) Initializes the global service with the providedLotlFetchingProperties.voidloadFromCache(InputStream stream) Loads the cache from the provided input stream.protected voidLoads the cache from the network by fetching the latest LOTL data and related resources.voidserializeCache(OutputStream outputStream) Serializes the current state of the cache to the provided output stream.protected voidSets up a timer to periodically refresh the LOTL cache.protected voidThis method is intended to refresh the cache, it will try to download the latest LOTL data and update the cache accordingly.withCountrySpecificLotlFetcher(CountrySpecificLotlFetcher countrySpecificLotlFetcher) Sets the country-specific LOTL fetcher for the LOTL service.final LotlServicewithCustomResourceRetriever(IResourceRetriever resourceRetriever) Sets a custom resource retriever for fetching resources.Sets the European List of Trusted Lists (LOTL) byte fetcher for the LOTL service.withEuropeanResourceFetcher(EuropeanResourceFetcher europeanResourceFetcher) Sets the European Resource Fetcher for theLotlService.Sets the cache for theLotlService.withLotlValidator(Supplier<LotlValidator> lotlValidatorFactory) Sets up factory which is responsible forLotlValidatorcreation.withPivotFetcher(PivotFetcher pivotFetcher) Sets the pivot fetcher for the LOTL service.withXmlSignatureValidator(Function<TrustedCertificatesStore, XmlSignatureValidator> xmlSignatureValidatorFactory) Sets up factory which is responsible forXmlSignatureValidatorcreation.
-
Field Details
-
lotlFetchingProperties
-
-
Constructor Details
-
LotlService
Creates a new instance ofLotlService.- Parameters:
-
lotlFetchingProperties-LotlFetchingPropertiesto configure the way in which LOTL will be fetched
-
-
Method Details
-
initializeGlobalCache
Initializes the global service with the providedLotlFetchingProperties. This method must be called before using theLotlServiceto ensure that the cache is set up.If you are using a custom implementation of
LotlServiceyou can use the instance method.- Parameters:
-
lotlFetchingProperties- theLotlFetchingPropertiesto use for initializing the cache
-
getGlobalService
Gets global static instance ofLotlService.- Returns:
-
global static instance of
LotlService
-
withLotlServiceCache
Sets the cache for theLotlService.This method allows you to provide a custom implementation of
LotlServiceCacheto 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
LotlServicefor method chaining
-
withCustomResourceRetriever
Sets a custom resource retriever for fetching resources.This method allows you to provide a custom implementation of
IResourceRetrieverto be used for fetching resources such as the LOTL XML, pivot files, and country-specific LOTLs.Multiple LOTL endpoints require a userAgent header to be sent. This should be taken into account when providing a custom
IResourceRetriever.- Parameters:
-
resourceRetriever- the custom resource retriever to be used for fetching resources - Returns:
-
the current instance of
LotlServicefor method chaining
-
initializeCache
public void initializeCache()Initializes the cache with the latest LOTL data and related resources. -
loadFromCache
Loads the cache from the provided input stream.The input stream should contain serialized cache data, which can be created using the
serializeCache(OutputStream)method.- Parameters:
-
stream- the input stream to read the cached data from
-
getValidationResult
Get the validation results for the List of Trusted Lists (LOTL).- Returns:
-
a
ValidationReportcontaining the results of the LOTL validation
-
getNationalTrustedCertificates
Retrieves national trusted certificates.- Returns:
- the list of the national trusted certificates
-
initializeCache
Initializes the cache with the latest LOTL data and related resources.Important: By default when providing a stream, we will still set up a timer to refresh the cache periodically. If you don't want this behavior, please set
LotlFetchingProperties.setRefreshIntervalCalculator(LongUnaryOperator)to int.Max.- Parameters:
-
stream- InputStream to read the cached data from. If null, the data will be fetched from the network. The data can be serialized usingserializeCache(OutputStream)method.
-
withPivotFetcher
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
LotlServicefor 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
LotlServicefor method chaining
-
withEuropeanLotlFetcher
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
LotlServicefor method chaining
-
withXmlSignatureValidator
public LotlService withXmlSignatureValidator(Function<TrustedCertificatesStore, XmlSignatureValidator> xmlSignatureValidatorFactory) Sets up factory which is responsible forXmlSignatureValidatorcreation.- Parameters:
-
xmlSignatureValidatorFactory- factory responsible forXmlSignatureValidatorcreation - Returns:
-
the current instance of
LotlServicefor method chaining
-
withLotlValidator
Sets up factory which is responsible forLotlValidatorcreation.- Parameters:
-
lotlValidatorFactory- factory responsible forLotlValidatorcreation - Returns:
-
this same instance of
LotlService
-
withEuropeanResourceFetcher
Sets the European Resource Fetcher for theLotlService.- Parameters:
-
europeanResourceFetcher- the European Resource Fetcher to be used for fetching EU journal certificates - Returns:
-
the current instance of
LotlServicefor method chaining
-
close
public void close()- Specified by:
-
closein interfaceAutoCloseable
-
serializeCache
Serializes the current state of the cache to the provided output stream.- Parameters:
-
outputStream- the output stream to which the cache will be serialized - Throws:
-
IOException- if an I/O error occurs during serialization
-
loadFromNetwork
protected void loadFromNetwork()Loads the cache from the network by fetching the latest LOTL data and related resources.This method fetches the main LOTL file, EU journal certificates, pivot files, and country-specific LOTLs, validates them, and stores them in the cache.
Note: This method is called during cache initialization and should not be called directly in normal operation.
-
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. -
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.
-