Search in sources :

Example 16 with ZoneConfiguration

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

the class ZoneConfigurationTest method invalidProvince.

@Test
@DisplayName("Invalid match in the state province")
void invalidProvince() throws VCertException {
    final ZoneConfiguration zoneConfiguration = getBaseZoneConfiguration();
    final CertificateRequest certificateRequest = getDefaultCertificateRequest();
    certificateRequest.subject().province(Arrays.asList("Test"));
    final Throwable exception = assertThrows(VCertException.class, () -> zoneConfiguration.validateCertificateRequest(certificateRequest));
    assertThat(exception.getMessage()).contains("does not match any of the allowed State/Province");
}
Also used : ZoneConfiguration(com.venafi.vcert.sdk.connectors.ZoneConfiguration) CertificateRequest(com.venafi.vcert.sdk.certificate.CertificateRequest) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 17 with ZoneConfiguration

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

the class TppTokenConnectorCertAT method retrieveCertificate.

@Test
void retrieveCertificate() throws VCertException, SocketException, UnknownHostException {
    TppTokenConnector connector = connectorResource.connector();
    ZoneConfiguration zoneConfiguration = connectorResource.zoneConfiguration();
    CertificateRequest certificateRequest = connectorResource.certificateRequest();
    certificateRequest = connector.generateRequest(zoneConfiguration, certificateRequest);
    String certificateId = connector.requestCertificate(certificateRequest, zoneConfiguration);
    assertThat(certificateId).isNotNull();
    PEMCollection pemCollection = connector.retrieveCertificate(certificateRequest);
    assertThat(pemCollection.certificate()).isNotNull();
    assertThat(pemCollection.privateKey()).isNotNull();
}
Also used : PEMCollection(com.venafi.vcert.sdk.certificate.PEMCollection) ZoneConfiguration(com.venafi.vcert.sdk.connectors.ZoneConfiguration) CertificateRequest(com.venafi.vcert.sdk.certificate.CertificateRequest) Test(org.junit.jupiter.api.Test)

Example 18 with ZoneConfiguration

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

the class CertificateIssuingTemplate method toZoneConfig.

public ZoneConfiguration toZoneConfig() {
    ZoneConfiguration zoneConfig = new ZoneConfiguration().customAttributeValues(new HashMap<>());
    if (recommendedSettings != null) {
        zoneConfig.country(recommendedSettings.subjectCValue).organization(recommendedSettings.subjectOValue).organizationalUnit(Collections.singletonList(recommendedSettings.subjectOUValue)).province(recommendedSettings.subjectSTValue).locality(recommendedSettings.subjectLValue);
        if (recommendedSettings.key() != null) {
            String type = recommendedSettings.key().type != null ? recommendedSettings.key().type : KeyType.defaultKeyType().name();
            Integer length = recommendedSettings.key().length != null ? recommendedSettings.key().length : KeyType.defaultRsaLength();
            zoneConfig.keyConfig(new AllowedKeyConfiguration(KeyType.from(type), Collections.singletonList(length), null));
        }
    }
    return zoneConfig;
}
Also used : ZoneConfiguration(com.venafi.vcert.sdk.connectors.ZoneConfiguration) AllowedKeyConfiguration(com.venafi.vcert.sdk.endpoint.AllowedKeyConfiguration)

Example 19 with ZoneConfiguration

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

the class TppConnector method readZoneConfiguration.

@Override
public ZoneConfiguration readZoneConfiguration(String zone) throws VCertException {
    VCertException.throwIfNull(zone, "empty zone");
    ReadZoneConfigurationRequest request = new ReadZoneConfigurationRequest(getPolicyDN(zone));
    ReadZoneConfigurationResponse response = tppAPI.readZoneConfiguration(request);
    ServerPolicy serverPolicy = response.policy();
    Policy policy = serverPolicy.toPolicy();
    ZoneConfiguration zoneConfig = serverPolicy.toZoneConfig();
    zoneConfig.policy(policy);
    zoneConfig.zoneId(zone);
    return zoneConfig;
}
Also used : TPPPolicy(com.venafi.vcert.sdk.policy.api.domain.TPPPolicy) ServerPolicy(com.venafi.vcert.sdk.connectors.ServerPolicy) Policy(com.venafi.vcert.sdk.connectors.Policy) ServerPolicy(com.venafi.vcert.sdk.connectors.ServerPolicy) ZoneConfiguration(com.venafi.vcert.sdk.connectors.ZoneConfiguration)

Example 20 with ZoneConfiguration

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

the class CloudConnector method readZoneConfiguration.

@Override
public ZoneConfiguration readZoneConfiguration(String zone) throws VCertException {
    String[] valies = StringUtils.split(zone, "\\");
    String appName = valies[0];
    String citAlias = valies[1];
    CertificateIssuingTemplate cit = null;
    if ((appName != null && !appName.equals("")) && (citAlias != null && !citAlias.equals(""))) {
        cit = cloud.certificateIssuingTemplateByAppNameAndCitAlias(appName, citAlias, auth.apiKey());
    } else {
        throw new ZoneFormatException("The parameters: appName, citAlias or both are empty");
    }
    // get application id.
    Application app = cloud.applicationByName(appName, auth.apiKey());
    String appId = app.id();
    ZoneConfiguration zoneConfig = cit.toZoneConfig();
    zoneConfig.policy(cit.toPolicy());
    zoneConfig.zoneId(zone);
    zoneConfig.applicationId(appId);
    zoneConfig.certificateIssuingTemplateId(cit.id());
    return zoneConfig;
}
Also used : ZoneConfiguration(com.venafi.vcert.sdk.connectors.ZoneConfiguration)

Aggregations

ZoneConfiguration (com.venafi.vcert.sdk.connectors.ZoneConfiguration)50 CertificateRequest (com.venafi.vcert.sdk.certificate.CertificateRequest)42 Test (org.junit.jupiter.api.Test)42 DisplayName (org.junit.jupiter.api.DisplayName)20 PEMCollection (com.venafi.vcert.sdk.certificate.PEMCollection)17 RenewalRequest (com.venafi.vcert.sdk.certificate.RenewalRequest)7 StringReader (java.io.StringReader)7 X509Certificate (java.security.cert.X509Certificate)7 RevocationRequest (com.venafi.vcert.sdk.certificate.RevocationRequest)5 Authentication (com.venafi.vcert.sdk.endpoint.Authentication)5 PEMParser (org.bouncycastle.openssl.PEMParser)4 PKCS10CertificationRequest (org.bouncycastle.pkcs.PKCS10CertificationRequest)4 Config (com.venafi.vcert.sdk.Config)3 TestUtils (com.venafi.vcert.sdk.TestUtils)3 VCertException (com.venafi.vcert.sdk.VCertException)3 CsrOriginOption (com.venafi.vcert.sdk.certificate.CsrOriginOption)3 DataFormat (com.venafi.vcert.sdk.certificate.DataFormat)3 ServerPolicy (com.venafi.vcert.sdk.connectors.ServerPolicy)3 FeignException (feign.FeignException)3 IOException (java.io.IOException)3