Class CertificateManagementServiceImpl
java.lang.Object
de.xima.fc.certificate.mgmt.internal.CertificateManagementServiceImpl
- All Implemented Interfaces:
CertificateManagementService
@ApplicationScoped
public class CertificateManagementServiceImpl
extends Object
implements CertificateManagementService
- Since:
- 30.01.26
- Author:
- Norman Lorenz
-
Method Summary
Modifier and TypeMethodDescriptionvoiddeleteCertificate(Long id, CertificateManagementUser user) Deletes a certificate from the system.voidexportCertificate(Long certificateId, OutputStream os, ECertificateFileType fileType, CertificateManagementUser user) Exports a certificate to the specified output stream.voidexportCSR(Long certificateId, OutputStream os, ECsrFileType fileType, CertificateManagementUser user) Exports a Certificate Signing Request (CSR) to the specified output stream.voidexportKeyPair(Long certificateId, OutputStream os, char[] password, EKeyPairFileType fileType, CertificateManagementUser user) Exports a key pair (both public and private keys) of a certificate to the specified output stream.voidexportPrivateKey(Long certificateId, OutputStream os, char[] password, EPrivateKeyFileType fileType, CertificateManagementUser user) Exports the private key of a certificate to the specified output stream.voidexportPublicKey(Long certificateId, OutputStream os, EPublicKeyFileType fileType, CertificateManagementUser user) Exports the public key of a certificate to the specified output stream.findById(Long certificateId, CertificateManagementUser user) Retrieves the certificate with the specified ID.findValidCertificatesForSubject(CertificateSelectionBySubjectQuery query, CertificateManagementUser user) Retrieves all valid certificates for a given subject within a defined scope.findValidCertificatesForUsageSubject(CertificateSelectionByUsageSubjectQuery query, CertificateManagementUser user) Retrieves all valid client certificates for a given usage subject within a defined scope.generateCertificate(X501DistinguishedName certificateSubject, Duration certificateValidity, IKeyPairGenerationSpec keyPairGenerationSpec, List<ICertificateUsageSpecification> certificateUsageSpecifications, KeyStoreSelector keyStoreSelector, boolean autoRenew, CertificateManagementUser user) Generates a self-signed certificate with the given specifications.generateCertificate(X501DistinguishedName certificateSubject, Duration certificateValidity, IKeyPairGenerationSpec keyPairGenerationSpec, List<ICertificateUsageSpecification> certificateUsageSpecifications, Long signingAuthorityId, KeyStoreSelector keyStoreSelector, boolean autoRenew, CertificateManagementUser user) Generates a certificate with the given specifications.getCurrentValidCertificateForSubject(CertificateSelectionBySubjectQuery query, CertificateManagementUser user) Retrieves the current valid certificate for the given subject within a defined scope.getCurrentValidCertificateForUsageSubject(CertificateSelectionByUsageSubjectQuery query, CertificateManagementUser user) Retrieves the current valid certificate for the given usage subject within a defined scope.importCryptographicCredentials(InputStream is, FileImportSpecification fileImportSpecification, KeyStoreSelector keyStoreSelector, CertificateManagementUser user) Universal method to import a file into the keystore.importCryptographicCredentials(InputStream is, KeyStoreSelector keyStoreSelector, CertificateManagementUser user) Universal method to import a file into the keystore.renewCertificate(Long certificateId, CertificateManagementUser user) Renews a certificate by generating a new certificate with the same subject and key pair.update(CertificateInfoDTO certificate, CertificateManagementUser user) Updates the metadata of a certificate.
-
Method Details
-
deleteCertificate
public void deleteCertificate(Long id, CertificateManagementUser user) throws FcCertificateManagementException Description copied from interface:CertificateManagementServiceDeletes a certificate from the system.Note: This method will also delete the keystore it is assigned to if it is the last entry in the keystore.
- Specified by:
deleteCertificatein interfaceCertificateManagementService- Parameters:
id- the ID of the certificate to delete.user- the user deleting the certificate.- Throws:
FcCertificateManagementException- if an error occurs during certificate deletion or the user does not have permission to delete the certificate.
-
exportCSR
public void exportCSR(Long certificateId, OutputStream os, ECsrFileType fileType, CertificateManagementUser user) throws IOException, FcCertificateManagementException Description copied from interface:CertificateManagementServiceExports a Certificate Signing Request (CSR) to the specified output stream.- Specified by:
exportCSRin interfaceCertificateManagementService- Parameters:
certificateId- the ID of the certificate for which the CSR will be exported.os- the output stream to write the CSR data to.fileType- the file type to export the CSR as.user- the user who is exporting the CSR.- Throws:
IOException- if an I/O error occurs during export.FcCertificateManagementException- if an error occurs during CSR export (e.g. the certificate could not be found or has no CSR, which is the case for externally imported certificates) or the user does not have permission to export the CSR.
-
exportCertificate
public void exportCertificate(Long certificateId, OutputStream os, ECertificateFileType fileType, CertificateManagementUser user) throws IOException, FcCertificateManagementException Description copied from interface:CertificateManagementServiceExports a certificate to the specified output stream.- Specified by:
exportCertificatein interfaceCertificateManagementService- Parameters:
certificateId- the ID of the certificate to export.os- the output stream to write the certificate data to.fileType- the file type to export the certificate as.user- the user who is exporting the certificate.- Throws:
IOException- if an I/O error occurs during export.FcCertificateManagementException- if an error occurs during certificate export (e.g. the certificate could not be found or the user does not have permission to export the certificate).
-
exportKeyPair
public void exportKeyPair(Long certificateId, OutputStream os, char[] password, EKeyPairFileType fileType, CertificateManagementUser user) throws IOException, FcCertificateManagementException Description copied from interface:CertificateManagementServiceExports a key pair (both public and private keys) of a certificate to the specified output stream.- Specified by:
exportKeyPairin interfaceCertificateManagementService- Parameters:
certificateId- the ID of the certificate whose key pair will be exported.os- the output stream to write the key pair data to.password- the password to protect the exported key pair.fileType- the file type to export the key pair as.user- the user who is exporting the key pair.- Throws:
IOException- if an I/O error occurs during export.FcCertificateManagementException- if an error occurs during key pair export (e.g. the certificate could not be found or the user does not have permission to export the key pair).
-
exportPrivateKey
public void exportPrivateKey(Long certificateId, OutputStream os, char[] password, EPrivateKeyFileType fileType, CertificateManagementUser user) throws IOException, FcCertificateManagementException Description copied from interface:CertificateManagementServiceExports the private key of a certificate to the specified output stream.- Specified by:
exportPrivateKeyin interfaceCertificateManagementService- Parameters:
certificateId- the ID of the certificate whose private key will be exported.os- the output stream to write the private key data to.password- the password to protect the exported private key.fileType- the file type to export the private key as.user- the user who is exporting the private key.- Throws:
IOException- if an I/O error occurs during export.FcCertificateManagementException- if an error occurs during private key export (e.g. the certificate could not be or the user does not have permission to export the private key).
-
exportPublicKey
public void exportPublicKey(Long certificateId, OutputStream os, EPublicKeyFileType fileType, CertificateManagementUser user) throws IOException, FcCertificateManagementException Description copied from interface:CertificateManagementServiceExports the public key of a certificate to the specified output stream.- Specified by:
exportPublicKeyin interfaceCertificateManagementService- Parameters:
certificateId- the ID of the certificate whose public key will be exported.os- the output stream to write the public key data to.fileType- the file type to export the public key as.user- the user who is exporting the public key.- Throws:
IOException- if an I/O error occurs during export.FcCertificateManagementException- if an error occurs during public key export (e.g. the certificate could not be found or the user does not have permission to export the public key).
-
findById
public Optional<CertificateInfoDTO> findById(Long certificateId, CertificateManagementUser user) throws FcCertificateManagementException Description copied from interface:CertificateManagementServiceRetrieves the certificate with the specified ID.- Specified by:
findByIdin interfaceCertificateManagementService- Parameters:
certificateId- the ID of the certificate to retrieve.user- the user who is requesting the certificate.- Returns:
- an
Optionalcontaining theCertificateInfoDTOobject with the specified ID. - Throws:
FcCertificateManagementException- if the user does not have permission to access the certificate.
-
findValidCertificatesForSubject
public List<CertificateInfoDTO> findValidCertificatesForSubject(CertificateSelectionBySubjectQuery query, CertificateManagementUser user) throws FcCertificateManagementException Description copied from interface:CertificateManagementServiceRetrieves all valid certificates for a given subject within a defined scope.- Specified by:
findValidCertificatesForSubjectin interfaceCertificateManagementService- Parameters:
query- theCertificateSelectionBySubjectQuerydefining the subject, scope and optionally further criteria to filter the certificates (e.g. usage types, algorithms, etc.).user- the user requesting the certificates.- Returns:
- a list of
CertificateInfoDTOobjects representing the valid client certificates that match the given criteria. - Throws:
FcCertificateManagementException- if an error occurs during the search or the user does not have permission to access the certificates.
-
findValidCertificatesForUsageSubject
public List<CertificateInfoDTO> findValidCertificatesForUsageSubject(CertificateSelectionByUsageSubjectQuery query, CertificateManagementUser user) throws FcCertificateManagementException Description copied from interface:CertificateManagementServiceRetrieves all valid client certificates for a given usage subject within a defined scope. This is in contrast toCertificateManagementService.findValidCertificatesForSubject(CertificateSelectionBySubjectQuery, CertificateManagementUser), which retrieves the certificates by their subject, and not by their usage subject.- Specified by:
findValidCertificatesForUsageSubjectin interfaceCertificateManagementService- Parameters:
query- theCertificateSelectionByUsageSubjectQuerydefining the usage subject, scope and optionally further criteria to filter the certificates (e.g. key algorithm, private key presence, etc.).user- the user requesting the certificates.- Returns:
- a list of
CertificateInfoDTOobjects representing the valid client certificates that match the given criteria. - Throws:
FcCertificateManagementException- if an error occurs during the search or the user does not have permission to access the certificates.
-
generateCertificate
public CertificateInfoDTO generateCertificate(X501DistinguishedName certificateSubject, Duration certificateValidity, IKeyPairGenerationSpec keyPairGenerationSpec, List<ICertificateUsageSpecification> certificateUsageSpecifications, Long signingAuthorityId, KeyStoreSelector keyStoreSelector, boolean autoRenew, CertificateManagementUser user) throws FcCertificateManagementException Description copied from interface:CertificateManagementServiceGenerates a certificate with the given specifications.- Specified by:
generateCertificatein interfaceCertificateManagementService- Parameters:
certificateSubject- the subject information for the certificate.certificateValidity- the validity period of the certificate.keyPairGenerationSpec- the specifications for generating the key pair, including the algorithm and algorithm-specific settings.certificateUsageSpecifications- the (optional) usage specification the certificate will be used (e.g. SMIME certificate with email addresses).signingAuthorityId- the ID of the signing authority that will sign the certificate.keyStoreSelector- the keystore selector, defining the keystore where the key pair will be stored.autoRenew- whether the certificate should be automatically renewed before it expires.user- the user generating the key pair and certificate.- Returns:
- a
CertificateInfoDTOobject containing information about the generated certificate. - Throws:
FcCertificateManagementException- if an error occurs during certificate generation or the user does not have permission to generate the certificate.
-
generateCertificate
public CertificateInfoDTO generateCertificate(X501DistinguishedName certificateSubject, Duration certificateValidity, IKeyPairGenerationSpec keyPairGenerationSpec, List<ICertificateUsageSpecification> certificateUsageSpecifications, KeyStoreSelector keyStoreSelector, boolean autoRenew, CertificateManagementUser user) throws FcCertificateManagementException Description copied from interface:CertificateManagementServiceGenerates a self-signed certificate with the given specifications.- Specified by:
generateCertificatein interfaceCertificateManagementService- Parameters:
certificateSubject- the subject information for the certificate.certificateValidity- the validity period of the certificate.keyPairGenerationSpec- the specifications for generating the key pair, including the algorithm and algorithm-specific settings.certificateUsageSpecifications- the (optional) usage specification the certificate will be used (e.g. SMIME certificate with email addresses).keyStoreSelector- the keystore selector, defining the keystore where the key pair will be stored.autoRenew- whether the certificate should be automatically renewed before it expires.user- the user generating the key pair and certificate.- Returns:
- a
CertificateInfoDTOobject containing information about the generated certificate. - Throws:
FcCertificateManagementException- if an error occurs during certificate generation or the user does not have permission to generate the certificate.
-
getCurrentValidCertificateForSubject
public Optional<CertificateInfoDTO> getCurrentValidCertificateForSubject(CertificateSelectionBySubjectQuery query, CertificateManagementUser user) throws FcCertificateManagementException Description copied from interface:CertificateManagementServiceRetrieves the current valid certificate for the given subject within a defined scope.CertificateSelectionBySubjectQuery.isPartialMatch()does not apply in this method; only exact matches are considered.- Specified by:
getCurrentValidCertificateForSubjectin interfaceCertificateManagementService- Parameters:
query- theCertificateSelectionBySubjectQuerydefining the subject, scope and optionally further criteria to filter the certificates (e.g. usage types, algorithms, etc.).user- the user requesting the certificate.- Returns:
- an
Optionalcontaining theCertificateInfoDTOobject if the certificate exists. - Throws:
FcCertificateManagementException- if an error occurs during the search or the user does not have permission to access the certificate.
-
getCurrentValidCertificateForUsageSubject
public Optional<CertificateInfoDTO> getCurrentValidCertificateForUsageSubject(CertificateSelectionByUsageSubjectQuery query, CertificateManagementUser user) throws FcCertificateManagementException Description copied from interface:CertificateManagementServiceRetrieves the current valid certificate for the given usage subject within a defined scope. This is in contrast toCertificateManagementService.getCurrentValidCertificateForSubject(CertificateSelectionBySubjectQuery, CertificateManagementUser), which retrieves the certificate by its subject, and not by its usage subject.CertificateSelectionByUsageSubjectQuery.isPartialMatch()does not apply in this method; only exact matches are considered.- Specified by:
getCurrentValidCertificateForUsageSubjectin interfaceCertificateManagementService- Parameters:
query- theCertificateSelectionByUsageSubjectQuerydefining the usage subject, scope and optionally further criteria to filter the certificates (e.g. key algorithm, private key presence, etc.).user- the user requesting the certificate.- Returns:
- an
Optionalcontaining theCertificateInfoDTOobject if the certificate exists. - Throws:
FcCertificateManagementException- if an error occurs during the search or the user does not have permission to access the certificate.
-
importCryptographicCredentials
public FileImportResult importCryptographicCredentials(InputStream is, KeyStoreSelector keyStoreSelector, CertificateManagementUser user) throws IOException, FcCertificateManagementException Description copied from interface:CertificateManagementServiceUniversal method to import a file into the keystore. The method will automatically detect the type of the file and import it accordingly. It is capable of importing all file types specified in the enumECryptoFileFormat- Specified by:
importCryptographicCredentialsin interfaceCertificateManagementService- Parameters:
is- the input stream containing the file datakeyStoreSelector- the selector, defining the keystore to import the file intouser- the user who is importing the file- Returns:
- a
FileImportResultobject containing information about the imported file - Throws:
IOException- if an I/O error occurs during importFcCertificateManagementException- if the file data has an invalid or unknown format or if a custom keystore could not be created
-
importCryptographicCredentials
public FileImportResult importCryptographicCredentials(InputStream is, FileImportSpecification fileImportSpecification, KeyStoreSelector keyStoreSelector, CertificateManagementUser user) throws IOException, FcCertificateManagementException Description copied from interface:CertificateManagementServiceUniversal method to import a file into the keystore. The method will automatically detect the type of the file and import it accordingly. It is capable of importing all file types specified in the enumECryptoFileFormat- Specified by:
importCryptographicCredentialsin interfaceCertificateManagementService- Parameters:
is- the input stream containing the file datafileImportSpecification- the credentials for the import (e.g. in case of an encrypted file, where the file itself and/or the entries from the files are protected)keyStoreSelector- the selector, defining the keystore to import the file intouser- the user who is importing the file- Returns:
- a
FileImportResultobject containing information about the imported file - Throws:
IOException- if an I/O error occurs during importFcCertificateManagementException- if the file data has an invalid or unknown format or if a custom keystore could not be created
-
renewCertificate
public CertificateInfoDTO renewCertificate(Long certificateId, CertificateManagementUser user) throws FcCertificateManagementException Description copied from interface:CertificateManagementServiceRenews a certificate by generating a new certificate with the same subject and key pair. This method will only succeed if the certificate has a private key associated with it!If the certificate to be renewed is expired already, the new certificate will become the new default certificate for the associated key. Otherwise, the new certificate will be listed as the prepared replacement certificate.
- Specified by:
renewCertificatein interfaceCertificateManagementService- Parameters:
certificateId- the ID of the certificate to renew.user- the user renewing the certificate.- Returns:
- a
CertificateInfoDTOobject containing information about the renewed certificate. - Throws:
FcCertificateManagementException- if an error occurs during certificate renewal (e.g. the certificate has no private key or could not be found in the database) or the user does not have permission to renew the certificate.
-
update
public CertificateInfoDTO update(CertificateInfoDTO certificate, CertificateManagementUser user) throws FcCertificateManagementException Description copied from interface:CertificateManagementServiceUpdates the metadata of a certificate. Only certain fields can be updated, such as the renewal strategy.- Specified by:
updatein interfaceCertificateManagementService- Parameters:
certificate- theCertificateInfoDTOobject containing the updated certificate information. The ID field must be set to identify the certificate to update.user- the user updating the certificate.- Returns:
- a
CertificateInfoDTOobject containing information about the updated certificate. - Throws:
FcCertificateManagementException- if an error occurs during certificate update (e.g. the certificate could not be found in the database) or the user does not have permission to update the certificate.
-