diff --git a/peppol-commons/src/main/java/com/helger/peppol/servicedomain/EPeppolServiceDomain.java b/peppol-commons/src/main/java/com/helger/peppol/servicedomain/EPeppolServiceDomain.java index 02a5739f..a42fa6da 100644 --- a/peppol-commons/src/main/java/com/helger/peppol/servicedomain/EPeppolServiceDomain.java +++ b/peppol-commons/src/main/java/com/helger/peppol/servicedomain/EPeppolServiceDomain.java @@ -16,19 +16,102 @@ */ package com.helger.peppol.servicedomain; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import com.helger.commons.annotation.Nonempty; +import com.helger.commons.id.IHasID; +import com.helger.commons.lang.EnumHelper; +import com.helger.peppol.utils.PeppolCAChecker; +import com.helger.peppol.utils.PeppolCertificateChecker; + /** - * This enum lists all the Peppol Service Domains + * This enum lists all the Peppol Service Domains. The additional information + * are primarily around the required certificates. * * @author Philip Helger + * @since 9.6.0 */ -public enum EPeppolServiceDomain +public enum EPeppolServiceDomain implements IHasID { /** * Managed by PoAC */ - POST_AWARD (), + POST_AWARD ("post-award", + PeppolCertificateChecker.peppolPilotAP (), + PeppolCertificateChecker.peppolProductionAP (), + PeppolCertificateChecker.peppolPilotSMP (), + PeppolCertificateChecker.peppolProductionSMP ()), + /** + * Managed by PrAC + */ + PRE_AWARD ("pre-award", + PeppolCertificateChecker.peppolPilotAP (), + PeppolCertificateChecker.peppolProductionAP (), + PeppolCertificateChecker.peppolPilotSMP (), + PeppolCertificateChecker.peppolProductionSMP ()), /** * Enhanced B2B for Peppol-GENA bridge */ - ENHANCED_B2B; + ENHANCED_B2B ("eb2b", + PeppolCertificateChecker.peppolPilotEb2bAP (), + null, + PeppolCertificateChecker.peppolPilotSMP (), + null); + + private final String m_sID; + private final PeppolCAChecker m_aPilotAPChecker; + private final PeppolCAChecker m_aProdAPChecker; + private final PeppolCAChecker m_aPilotSMPChecker; + private final PeppolCAChecker m_aProdSMPChecker; + + EPeppolServiceDomain (@Nonnull @Nonempty final String sID, + @Nullable final PeppolCAChecker aPilotAPChecker, + @Nullable final PeppolCAChecker aProdAPChecker, + @Nullable final PeppolCAChecker aPilotSMPChecker, + @Nullable final PeppolCAChecker aProdSMPChecker) + { + m_sID = sID; + m_aPilotAPChecker = aPilotAPChecker; + m_aProdAPChecker = aProdAPChecker; + m_aPilotSMPChecker = aPilotSMPChecker; + m_aProdSMPChecker = aProdSMPChecker; + } + + @Nonnull + @Nonempty + public String getID () + { + return m_sID; + } + + @Nullable + public final PeppolCAChecker getPilotAPChecker () + { + return m_aPilotAPChecker; + } + + @Nullable + public final PeppolCAChecker getProdAPChecker () + { + return m_aProdAPChecker; + } + + @Nullable + public final PeppolCAChecker getPilotSMPChecker () + { + return m_aPilotSMPChecker; + } + + @Nullable + public final PeppolCAChecker getProdSMPChecker () + { + return m_aProdSMPChecker; + } + + @Nullable + public static EPeppolServiceDomain getFromIDOrNull (@Nullable final String sID) + { + return EnumHelper.getFromIDOrNull (EPeppolServiceDomain.class, sID); + } } diff --git a/peppol-commons/src/main/java/com/helger/peppol/utils/PeppolCAChecker.java b/peppol-commons/src/main/java/com/helger/peppol/utils/PeppolCAChecker.java index 82045492..1b6f437d 100644 --- a/peppol-commons/src/main/java/com/helger/peppol/utils/PeppolCAChecker.java +++ b/peppol-commons/src/main/java/com/helger/peppol/utils/PeppolCAChecker.java @@ -23,6 +23,7 @@ import javax.annotation.Nullable; import com.helger.commons.ValueEnforcer; +import com.helger.commons.annotation.ReturnsMutableCopy; import com.helger.commons.datetime.PDTFactory; import com.helger.commons.state.EChange; import com.helger.commons.state.ETriState; @@ -60,6 +61,38 @@ public PeppolCAChecker (@Nonnull final X509Certificate... aCACerts) CertificateRevocationCheckerDefaults.DEFAULT_REVOCATION_CHECK_CACHING_DURATION); } + /** + * @return A copy of the trusted CA certificates object used internally. Never + * null. + */ + @Nonnull + @ReturnsMutableCopy + public TrustedCACertificates getAllTrustedAPCertificates () + { + return new TrustedCACertificates (m_aTrustedCAs); + } + + /** + * @return The internal revocation cache that is used. Never + * null. + */ + @Nonnull + public PeppolRevocationCache getRevocationCache () + { + return m_aRevocationCache; + } + + /** + * Remove all elements from the this revocation check result cache. + * + * @return {@link EChange#CHANGED} if at least one entry was removed + */ + @Nonnull + public EChange clearRevocationCache () + { + return m_aRevocationCache.clearCache (); + } + /** * Check if the provided certificate is a valid Peppol certificate according * to the configured CA. @@ -127,10 +160,4 @@ public EPeppolCertificateCheckResult checkCertificate (@Nullable final X509Certi .validCAs (m_aTrustedCAs.getAllTrustedCACertificates ()) .checkMode (eCheckMode)); } - - @Nonnull - public EChange clearRevocationCache () - { - return m_aRevocationCache.clearCache (); - } } diff --git a/peppol-commons/src/main/java/com/helger/peppol/utils/PeppolRevocationCache.java b/peppol-commons/src/main/java/com/helger/peppol/utils/PeppolRevocationCache.java index 0c8369ae..367ae43c 100644 --- a/peppol-commons/src/main/java/com/helger/peppol/utils/PeppolRevocationCache.java +++ b/peppol-commons/src/main/java/com/helger/peppol/utils/PeppolRevocationCache.java @@ -54,11 +54,18 @@ private static String _getKey (@Nonnull final X509Certificate aCert) public PeppolRevocationCache (@Nonnull final Function aRevocationChecker, @Nonnull final Duration aCachingDuration) + { + this (aRevocationChecker, aCachingDuration, 1_000); + } + + public PeppolRevocationCache (@Nonnull final Function aRevocationChecker, + @Nonnull final Duration aCachingDuration, + final int nMaxSize) { super (PeppolRevocationCache::_getKey, cert -> { final ERevoked eRevoked = aRevocationChecker.apply (cert); return ExpiringObject.ofDuration (eRevoked, aCachingDuration); - }, 1_000, "CertificateRevocationCache", false); + }, nMaxSize, "CertificateRevocationCache", false); ValueEnforcer.notNull (aCachingDuration, "CachingDuration"); ValueEnforcer.isFalse (aCachingDuration::isNegative, "CachingDuration must not be negative"); m_aRevocationChecker = aRevocationChecker; diff --git a/peppol-commons/src/main/java/com/helger/peppol/utils/TrustedCACertificates.java b/peppol-commons/src/main/java/com/helger/peppol/utils/TrustedCACertificates.java index f069b227..6c1d6091 100644 --- a/peppol-commons/src/main/java/com/helger/peppol/utils/TrustedCACertificates.java +++ b/peppol-commons/src/main/java/com/helger/peppol/utils/TrustedCACertificates.java @@ -50,6 +50,13 @@ public class TrustedCACertificates public TrustedCACertificates () {} + public TrustedCACertificates (@Nonnull final TrustedCACertificates aSrc) + { + ValueEnforcer.notNull (aSrc, "Src"); + m_aCerts.addAll (aSrc.m_aCerts); + m_aIssuers.addAll (aSrc.m_aIssuers); + } + /** * Register a trusted CA Certificate *