Class CertificateContainer
- All Implemented Interfaces:
DisposableBean,InitializingBean,Lifecycle,Phased,SmartLifecycle,CertificateRegistry
CertificateContainer container = new CertificateContainer(vaultOperations.opsForPki());
RequestedCertificate cert = container
.register(RequestedCertificate.trustAnchor("vault-ca"));
container.addCertificateListener(new CertificateListenerAdapter() {
@Override
public void onCertificateEvent(CertificateEvent event) {
if (cert.equals(event.getSource())) {
if (event instanceof CertificateObtainedEvent) {
// certificate obtained
}
}
}
});
container.afterPropertiesSet();
container.start(); // events are triggered after starting the container
This container keeps track over RequestedCertificates and
obtains/issues certificates upon start(). The container manages
unique RequestedCertificate
registrations and so multiple registrations of the same
RequestedCertificate are considered as one registration.
The container dispatches certificate events to CertificateListener
and CertificateErrorListener. Event notifications are dispatched
either on the starting Thread or worker threads used
for background renewal.
Instances are thread-safe once initialized.
- Since:
- 4.1
- Author:
- Mark Paluch
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.springframework.vault.core.certificate.CertificateEventPublisher
CertificateEventPublisher.LoggingErrorListener -
Field Summary
Fields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE -
Constructor Summary
ConstructorsConstructorDescriptionCertificateContainer(CertificateAuthority certificateAuthority) Create a newCertificateContainergivenCertificateAuthority.CertificateContainer(CertificateAuthority certificateAuthority, TaskScheduler taskScheduler) CertificateContainer(VaultPkiOperations pkiOperations) Create a newCertificateContainergivenVaultPkiOperations. -
Method Summary
Modifier and TypeMethodDescriptionvoidvoiddestroy()Shutdown thisCertificateContainer, disable rotation of active certificates.intgetPhase()booleanvoidregister(RequestedCertificate certificate) Register aRequestedCertificatewith the registry.voidregister(RequestedCertificate certificate, CertificateListener listener) Register aRequestedCertificatewith the registry with an associatedCertificateListener.voidrotate(RequestedCertificate requestedCertificate) Force certificate rotation.voidsetExpiryThreshold(Duration expiryThreshold) Set the expiry threshold.voidsetTaskScheduler(TaskScheduler taskScheduler) Sets theTaskSchedulerto use for scheduling and execution of lease renewals.voidstart()Start theCertificateContainer.voidstop()Stop theCertificateContainer.booleanunregister(RequestedCertificate certificate) Unregister theRequestedCertificatefrom the registry.Methods inherited from class org.springframework.vault.core.certificate.CertificateEventPublisher
addCertificateListener, addErrorListener, onCertificateExpired, onCertificateObtained, onCertificateRotated, onError, removeCertificateErrorListener, removeCertificateListenerMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.context.SmartLifecycle
isAutoStartup, isPauseable, stop
-
Constructor Details
-
CertificateContainer
Create a newCertificateContainergivenVaultPkiOperations.- Parameters:
pkiOperations- must not be null.
-
CertificateContainer
Create a newCertificateContainergivenCertificateAuthority.- Parameters:
certificateAuthority- must not be null.
-
CertificateContainer
- Parameters:
certificateAuthority- must not be null.taskScheduler- must not be null.
-
-
Method Details
-
setTaskScheduler
Sets theTaskSchedulerto use for scheduling and execution of lease renewals.- Parameters:
taskScheduler- must not be null.
-
getExpiryThreshold
-
setExpiryThreshold
Set the expiry threshold. ACertificateis rotated the given time before it expires.- Parameters:
expiryThreshold- duration beforeCertificateexpiry, must not be null or negative.
-
register
Description copied from interface:CertificateRegistryRegister aRequestedCertificatewith the registry.Subsequent registrations of the same
RequestedCertificateare considered as a single registration and the secret will be managed only once.- Specified by:
registerin interfaceCertificateRegistry- Parameters:
certificate- the certificate to be managed.
-
register
Description copied from interface:CertificateRegistryRegister aRequestedCertificatewith the registry with an associatedCertificateListener.Subsequent registrations of the same
RequestedCertificateare considered as a single registration and the secret will be managed only once. A requested secret that has been already been registered and activated by the container will not lead to emission of a newSecretLeaseCreatedEventwith the previous secrets body but rather only to future events such as rotations or renewals.- Specified by:
registerin interfaceCertificateRegistry- Parameters:
certificate- the requested certificate to be managed.listener- listener to associate with the requested certificate. The listener will be notified only with events concerning the requested certificate.
-
unregister
Description copied from interface:CertificateRegistryUnregister theRequestedCertificatefrom the registry. Removing the certificate stops rotations, and it removes listener registrations that wereassociated with the certificate registration.- Specified by:
unregisterin interfaceCertificateRegistry- Parameters:
certificate- the certificate to be deregistered.- Returns:
- true if the certificate was registered before and has been removed; false otherwise.
-
rotate
Force certificate rotation.- Parameters:
requestedCertificate- the certificate to rotate.
-
start
public void start()Start theCertificateContainer. Starting the container will initially obtain certificates for the requested certificates. A started container publishes events throughCertificateListener. Additional certificates can be requested at any time.Multiple calls are synchronized to start the container only once. Container start requires
initializationand cannot be started once the container wasdestroyed. -
stop
public void stop()Stop theCertificateContainer. Stopping the container will stop certificate rotation and event publishing.Multiple calls are synchronized to stop the container only once.
-
isRunning
public boolean isRunning() -
getPhase
public int getPhase()- Specified by:
getPhasein interfacePhased- Specified by:
getPhasein interfaceSmartLifecycle
-
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSetin interfaceInitializingBean- Overrides:
afterPropertiesSetin classCertificateEventPublisher
-
destroy
Shutdown thisCertificateContainer, disable rotation of active certificates.- Specified by:
destroyin interfaceDisposableBean- Throws:
Exception- See Also:
-