Skip to content

Commit

Permalink
Added additional APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
phax committed Nov 10, 2024
1 parent 333d1d1 commit 60e729b
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 <String>
{
/**
* 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
* <code>null</code>.
*/
@Nonnull
@ReturnsMutableCopy
public TrustedCACertificates getAllTrustedAPCertificates ()
{
return new TrustedCACertificates (m_aTrustedCAs);
}

/**
* @return The internal revocation cache that is used. Never
* <code>null</code>.
*/
@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.
Expand Down Expand Up @@ -127,10 +160,4 @@ public EPeppolCertificateCheckResult checkCertificate (@Nullable final X509Certi
.validCAs (m_aTrustedCAs.getAllTrustedCACertificates ())
.checkMode (eCheckMode));
}

@Nonnull
public EChange clearRevocationCache ()
{
return m_aRevocationCache.clearCache ();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,18 @@ private static String _getKey (@Nonnull final X509Certificate aCert)

public PeppolRevocationCache (@Nonnull final Function <X509Certificate, ERevoked> aRevocationChecker,
@Nonnull final Duration aCachingDuration)
{
this (aRevocationChecker, aCachingDuration, 1_000);
}

public PeppolRevocationCache (@Nonnull final Function <X509Certificate, ERevoked> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down

0 comments on commit 60e729b

Please sign in to comment.