Package com.helger.as2lib.cert
Class AbstractCertificateFactory
java.lang.Object
com.helger.as2lib.AbstractDynamicComponent
com.helger.as2lib.cert.AbstractCertificateFactory
- All Implemented Interfaces:
IAliasedCertificateFactory
,ICertificateFactory
,IKeyStoreCertificateFactory
,IDynamicComponent
- Direct Known Subclasses:
CertificateFactory
,PredefinedCertificateFactory
@ThreadSafe
public abstract class AbstractCertificateFactory
extends AbstractDynamicComponent
implements IKeyStoreCertificateFactory, IAliasedCertificateFactory
Abstract base implementation of a read-only Certificate factory that operates
on a
KeyStore
object. The only method to be implemented is
IKeyStoreCertificateFactory.reinitKeyStore()
which is responsible for setting the keystore. The
protected method setKeyStore(KeyStore)
may be used to work
around the default behaviour and provide an arbitrary implementation.- Since:
- 4.6.4
- Author:
- Philip Helger
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
static final String
Key store type; since 4.0.0static final com.helger.security.keystore.EKeyStoreType
Fields inherited from class com.helger.as2lib.AbstractDynamicComponent
m_aRWLock
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addCertificate
(String sAlias, X509Certificate aCert, boolean bOverwrite) void
addPrivateKey
(String sAlias, Key aKey, String sPassword) void
protected KeyStore
createNewKeyStore
(com.helger.security.keystore.EKeyStoreType eKeyStoreType) protected final void
boolean
getAlias
(Partnership aPartnership, ECertificatePartnershipType ePartnershipType) getCertificate
(IBaseMessage aMsg, ECertificatePartnershipType ePartnershipType) Get the certificate of the specified type for the partnership defined in the provided messagegetCertificate
(String sAlias) com.helger.commons.collection.impl.ICommonsOrderedMap<String,
X509Certificate> final String
char[]
getPrivateKey
(X509Certificate aCert) protected String
getUnifiedAlias
(String sAlias) Overridable method to perform unifications on aliases, e.g. for lower casing when using Oracle JDKs PKCS12 implementation.int
hashCode()
void
initDynamicComponent
(IAS2Session aSession, com.helger.commons.collection.attr.IStringMap aOptions) After creating a Component object, this method should be called to set any parameters used by the component.protected void
This method is responsible to create a new empty keystore based on the configured type.protected X509Certificate
internalGetCertificate
(String sAlias, ECertificatePartnershipType ePartnershipType) final boolean
void
load
(InputStream aIS, char[] aPassword) protected void
onChange()
Custom callback method that is invoked if something changes in the key store.void
removeCertificate
(String sAlias) void
removeCertificate
(X509Certificate aCert) void
save
(OutputStream aOS, char[] aPassword) final void
setDebugLogEnaled
(boolean bDebugLog) protected final void
setKeyStore
(KeyStore aKeyStore) Internal method to set theKeyStore
used internally.final void
setKeyStoreType
(com.helger.security.keystore.IKeyStoreType aKeyStoreType) final void
setKeyStoreType
(String sKeyStoreType) void
setPassword
(String sPassword) Methods inherited from class com.helger.as2lib.AbstractDynamicComponent
attrs, getAttributeAsIntRequired, getAttributeAsStringRequired, getName, getSession, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.helger.as2lib.cert.ICertificateFactory
getCertificateOrNull
Methods inherited from interface com.helger.as2lib.IDynamicComponent
attrs, getName, getSession
Methods inherited from interface com.helger.as2lib.cert.IKeyStoreCertificateFactory
reinitKeyStore
-
Field Details
-
DEFAULT_KEY_STORE_TYPE
public static final com.helger.security.keystore.EKeyStoreType DEFAULT_KEY_STORE_TYPE -
ATTR_TYPE
Key store type; since 4.0.0- See Also:
-
ATTR_PASSWORD
- See Also:
-
-
Constructor Details
-
AbstractCertificateFactory
public AbstractCertificateFactory()
-
-
Method Details
-
isDebugLogEnabled
public final boolean isDebugLogEnabled() -
setDebugLogEnaled
public final void setDebugLogEnaled(boolean bDebugLog) -
debugLog
-
getKeyStoreType
-
setKeyStoreType
public final void setKeyStoreType(@Nullable com.helger.security.keystore.IKeyStoreType aKeyStoreType) -
setKeyStoreType
-
setPassword
-
getPassword
-
createNewKeyStore
@Nonnull @OverrideOnDemand protected KeyStore createNewKeyStore(@Nonnull com.helger.security.keystore.EKeyStoreType eKeyStoreType) throws GeneralSecurityException - Throws:
GeneralSecurityException
-
initDynamicComponent
public void initDynamicComponent(@Nonnull IAS2Session aSession, @Nullable com.helger.commons.collection.attr.IStringMap aOptions) throws AS2Exception Description copied from interface:IDynamicComponent
After creating a Component object, this method should be called to set any parameters used by the component. Component implementations typically have required parameter checking and code to start timers and threads within this method.- Specified by:
initDynamicComponent
in interfaceIDynamicComponent
- Overrides:
initDynamicComponent
in classAbstractDynamicComponent
- Parameters:
aSession
- the component uses this object to access other componentsaOptions
- configuration values for the component. All parameters will be stored as attributes of this component. All attributes existing before this method is called will be removed!- Throws:
AS2Exception
- If an error occurs while initializing the componentAS2InvalidParameterException
- If a required parameter is null in the parameters Map- See Also:
-
getKeyStore
- Specified by:
getKeyStore
in interfaceIKeyStoreCertificateFactory
- Returns:
- The key store this certificate factory deals with. May not be
null
.
-
setKeyStore
Internal method to set theKeyStore
used internally.- Parameters:
aKeyStore
- The key store to use. May not benull
.
-
initEmptyKeyStore
This method is responsible to create a new empty keystore based on the configured type.- Throws:
AS2Exception
- In case of error- See Also:
-
getUnifiedAlias
Overridable method to perform unifications on aliases, e.g. for lower casing when using Oracle JDKs PKCS12 implementation.- Parameters:
sAlias
- Source alias. May benull
.- Returns:
null
if the source wasnull
.- Since:
- 4.0.2
-
getAlias
@Nonnull public String getAlias(@Nonnull Partnership aPartnership, @Nonnull ECertificatePartnershipType ePartnershipType) throws AS2Exception - Throws:
AS2Exception
-
internalGetCertificate
@Nonnull protected X509Certificate internalGetCertificate(@Nullable String sAlias, @Nullable ECertificatePartnershipType ePartnershipType) throws AS2Exception - Throws:
AS2Exception
-
getCertificate
- Specified by:
getCertificate
in interfaceIAliasedCertificateFactory
- Throws:
AS2Exception
-
getCertificate
@Nonnull public X509Certificate getCertificate(@Nonnull IBaseMessage aMsg, @Nonnull ECertificatePartnershipType ePartnershipType) throws AS2Exception Description copied from interface:ICertificateFactory
Get the certificate of the specified type for the partnership defined in the provided message- Specified by:
getCertificate
in interfaceICertificateFactory
- Parameters:
aMsg
- Message to get the partnership from. May not benull
.ePartnershipType
- Sender or receiver?- Returns:
- Never
null
- - Throws:
AS2Exception
- In case of errorAS2CertificateNotFoundException
- If no certificate is present
-
getCertificates
@Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsOrderedMap<String,X509Certificate> getCertificates() throws AS2Exception- Specified by:
getCertificates
in interfaceIAliasedCertificateFactory
- Throws:
AS2Exception
-
onChange
Custom callback method that is invoked if something changes in the key store. By default the changes are written back to disk.- Throws:
AS2Exception
- In case saving fails.
-
getPrivateKey
- Specified by:
getPrivateKey
in interfaceICertificateFactory
- Throws:
AS2Exception
-
addCertificate
public void addCertificate(@Nonnull @Nonempty String sAlias, @Nonnull X509Certificate aCert, boolean bOverwrite) throws AS2Exception - Specified by:
addCertificate
in interfaceIAliasedCertificateFactory
- Throws:
AS2Exception
-
addPrivateKey
public void addPrivateKey(@Nonnull @Nonempty String sAlias, @Nonnull Key aKey, @Nonnull String sPassword) throws AS2Exception - Specified by:
addPrivateKey
in interfaceIAliasedCertificateFactory
- Throws:
AS2Exception
-
clearCertificates
- Specified by:
clearCertificates
in interfaceIAliasedCertificateFactory
- Throws:
AS2Exception
-
removeCertificate
- Specified by:
removeCertificate
in interfaceIAliasedCertificateFactory
- Throws:
AS2Exception
-
removeCertificate
- Specified by:
removeCertificate
in interfaceIAliasedCertificateFactory
- Throws:
AS2Exception
-
load
public void load(@Nonnull @WillClose InputStream aIS, @Nonnull char[] aPassword) throws AS2Exception - Throws:
AS2Exception
-
save
public void save(@Nonnull @WillClose OutputStream aOS, @Nonnull char[] aPassword) throws AS2Exception - Throws:
AS2Exception
-
equals
- Overrides:
equals
in classAbstractDynamicComponent
-
hashCode
public int hashCode()- Overrides:
hashCode
in classAbstractDynamicComponent
-