Search in sources :

Example 1 with CertificateDNOrThumbprintWasNotProvidedException

use of com.venafi.vcert.sdk.connectors.ConnectorException.CertificateDNOrThumbprintWasNotProvidedException in project vcert-java by Venafi.

the class TppConnectorTest method renewCertificateWithEmptyRequest.

@Test
@DisplayName("Renew Certificate with an empty request")
void renewCertificateWithEmptyRequest() throws VCertException {
    final RenewalRequest renewalRequest = mock(RenewalRequest.class);
    final Throwable throwable = assertThrows(VCertException.class, () -> classUnderTest.renewCertificate(renewalRequest));
    assertThat(throwable instanceof CertificateDNOrThumbprintWasNotProvidedException);
}
Also used : RenewalRequest(com.venafi.vcert.sdk.certificate.RenewalRequest) CertificateDNOrThumbprintWasNotProvidedException(com.venafi.vcert.sdk.connectors.ConnectorException.CertificateDNOrThumbprintWasNotProvidedException) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 2 with CertificateDNOrThumbprintWasNotProvidedException

use of com.venafi.vcert.sdk.connectors.ConnectorException.CertificateDNOrThumbprintWasNotProvidedException in project vcert-java by Venafi.

the class TppTokenConnectorTest method renewCertificateWithEmptyRequest.

@Test
@DisplayName("Renew Certificate with an empty request")
void renewCertificateWithEmptyRequest() throws VCertException {
    final RenewalRequest renewalRequest = mock(RenewalRequest.class);
    final Throwable throwable = assertThrows(VCertException.class, () -> classUnderTest.renewCertificate(renewalRequest));
    assertThat(throwable instanceof CertificateDNOrThumbprintWasNotProvidedException);
}
Also used : RenewalRequest(com.venafi.vcert.sdk.certificate.RenewalRequest) CertificateDNOrThumbprintWasNotProvidedException(com.venafi.vcert.sdk.connectors.ConnectorException.CertificateDNOrThumbprintWasNotProvidedException) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 3 with CertificateDNOrThumbprintWasNotProvidedException

use of com.venafi.vcert.sdk.connectors.ConnectorException.CertificateDNOrThumbprintWasNotProvidedException in project vcert-java by Venafi.

the class TppConnector method renewCertificate.

@Override
public String renewCertificate(RenewalRequest request) throws VCertException {
    String certificateDN;
    if (isNotBlank(request.thumbprint()) && isBlank(request.certificateDN())) {
        Tpp.CertificateSearchResponse searchResult = searchCertificatesByFingerprint(request.thumbprint());
        if (searchResult.certificates().isEmpty())
            throw new CertificateNotFoundByThumbprintException(request.thumbprint());
        if (searchResult.certificates().size() > 1)
            throw new MoreThanOneCertificateWithSameThumbprintException(request.thumbprint());
        certificateDN = searchResult.certificates().get(0).certificateRequestId();
    } else {
        certificateDN = request.certificateDN();
    }
    if (isNull(certificateDN))
        throw new CertificateDNOrThumbprintWasNotProvidedException();
    final CertificateRenewalRequest renewalRequest = new CertificateRenewalRequest();
    renewalRequest.certificateDN(certificateDN);
    if (nonNull(request.request()) && nonNull(request.request().csr()) && request.request().csr().length > 0) {
        String pkcs10 = org.bouncycastle.util.Strings.fromByteArray(request.request().csr());
        renewalRequest.PKCS10(pkcs10);
    }
    final Tpp.CertificateRenewalResponse response = tppAPI.renewCertificate(renewalRequest);
    if (!response.success())
        throw new RenewFailureException(response.error());
    return certificateDN;
}
Also used : CertificateNotFoundByThumbprintException(com.venafi.vcert.sdk.connectors.ConnectorException.CertificateNotFoundByThumbprintException) CertificateSearchResponse(com.venafi.vcert.sdk.connectors.tpp.Tpp.CertificateSearchResponse) CertificateDNOrThumbprintWasNotProvidedException(com.venafi.vcert.sdk.connectors.ConnectorException.CertificateDNOrThumbprintWasNotProvidedException) RenewFailureException(com.venafi.vcert.sdk.connectors.ConnectorException.RenewFailureException) CertificateRenewalResponse(com.venafi.vcert.sdk.connectors.tpp.Tpp.CertificateRenewalResponse) MoreThanOneCertificateWithSameThumbprintException(com.venafi.vcert.sdk.connectors.ConnectorException.MoreThanOneCertificateWithSameThumbprintException)

Aggregations

CertificateDNOrThumbprintWasNotProvidedException (com.venafi.vcert.sdk.connectors.ConnectorException.CertificateDNOrThumbprintWasNotProvidedException)3 RenewalRequest (com.venafi.vcert.sdk.certificate.RenewalRequest)2 DisplayName (org.junit.jupiter.api.DisplayName)2 Test (org.junit.jupiter.api.Test)2 CertificateNotFoundByThumbprintException (com.venafi.vcert.sdk.connectors.ConnectorException.CertificateNotFoundByThumbprintException)1 MoreThanOneCertificateWithSameThumbprintException (com.venafi.vcert.sdk.connectors.ConnectorException.MoreThanOneCertificateWithSameThumbprintException)1 RenewFailureException (com.venafi.vcert.sdk.connectors.ConnectorException.RenewFailureException)1 CertificateRenewalResponse (com.venafi.vcert.sdk.connectors.tpp.Tpp.CertificateRenewalResponse)1 CertificateSearchResponse (com.venafi.vcert.sdk.connectors.tpp.Tpp.CertificateSearchResponse)1