Search in sources :

Example 1 with ServerPolicy

use of com.venafi.vcert.sdk.connectors.ServerPolicy 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 2 with ServerPolicy

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

the class TppTokenConnectorTest method requestCertificate.

@Test
@DisplayName("Request a certificate from TPP")
void requestCertificate() throws VCertException {
    Security.addProvider(new BouncyCastleProvider());
    TppTokenConnector.ReadZoneConfigurationRequest expectedRZCRequest = new TppTokenConnector.ReadZoneConfigurationRequest("\\VED\\Policy\\myZone");
    when(tpp.readZoneConfigurationToken(eq(expectedRZCRequest), eq(HEADER_AUTHORIZATION))).thenReturn(new TppTokenConnector.ReadZoneConfigurationResponse().policy(new ServerPolicy().subject(new ServerPolicy.Subject().organizationalUnit(new LockableValues<String>(false, Collections.singletonList("OU"))).state(new LockableValue<>(false, "state")).city(new LockableValue<>(false, "city")).country(new LockableValue<>(false, "country")).organization(new LockableValue<>(false, "organization"))).keyPair(new ServerPolicy.KeyPair(new LockableValue<>(false, "keyAlgo"), new LockableValue<>(false, 1024), null))));
    when(tpp.requestCertificateToken(any(TppTokenConnector.CertificateRequestsPayload.class), eq(HEADER_AUTHORIZATION))).thenReturn(new Tpp.CertificateRequestResponse().certificateDN("reqId"));
    String zoneTag = "myZone";
    ZoneConfiguration zoneConfig = classUnderTest.readZoneConfiguration(classUnderTest.getPolicyDN(zoneTag));
    String cn = String.format("t%d-%s.venafi.xample.com", Instant.now().getEpochSecond(), RandomStringUtils.randomAlphabetic(4).toLowerCase());
    CertificateRequest request = new CertificateRequest().subject(new CertificateRequest.PKIXName().commonName(cn).organization(Collections.singletonList("Venafi, Inc.")).organizationalUnit(Collections.singletonList("Automated Tests")).locality(Collections.singletonList("Las Vegas")).province(Collections.singletonList("Nevada")).country(Collections.singletonList("US"))).friendlyName(cn).keyLength(512);
    classUnderTest.generateRequest(zoneConfig, request);
    logger.info("getPolicyDN(ZoneTag) = %s", classUnderTest.getPolicyDN(zoneTag));
    ZoneConfiguration zoneConfiguration = new ZoneConfiguration();
    zoneConfiguration.zoneId(classUnderTest.getPolicyDN(zoneTag));
    String requestId = classUnderTest.requestCertificate(request, zoneConfiguration);
    assertEquals("reqId", requestId);
}
Also used : ServerPolicy(com.venafi.vcert.sdk.connectors.ServerPolicy) ZoneConfiguration(com.venafi.vcert.sdk.connectors.ZoneConfiguration) LockableValue(com.venafi.vcert.sdk.connectors.LockableValue) CertificateRequest(com.venafi.vcert.sdk.certificate.CertificateRequest) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 3 with ServerPolicy

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

the class TppConnectorTest method requestCertificate.

@Test
@DisplayName("Request a certificate from TPP")
void requestCertificate() throws VCertException {
    Security.addProvider(new BouncyCastleProvider());
    TppConnector.ReadZoneConfigurationRequest expectedRZCRequest = new TppConnector.ReadZoneConfigurationRequest("\\VED\\Policy\\myZone");
    when(tpp.readZoneConfiguration(eq(expectedRZCRequest), eq(API_KEY))).thenReturn(new TppConnector.ReadZoneConfigurationResponse().policy(new ServerPolicy().subject(new ServerPolicy.Subject().organizationalUnit(new LockableValues<String>(false, Collections.singletonList("OU"))).state(new LockableValue<>(false, "state")).city(new LockableValue<>(false, "city")).country(new LockableValue<>(false, "country")).organization(new LockableValue<>(false, "organization"))).keyPair(new ServerPolicy.KeyPair(new LockableValue<>(false, "keyAlgo"), new LockableValue<>(false, 1024), null))));
    when(tpp.requestCertificate(any(TppConnector.CertificateRequestsPayload.class), eq(API_KEY))).thenReturn(new Tpp.CertificateRequestResponse().certificateDN("reqId"));
    String zoneTag = "myZone";
    ZoneConfiguration zoneConfig = classUnderTest.readZoneConfiguration(classUnderTest.getPolicyDN(zoneTag));
    String cn = String.format("t%d-%s.venafi.xample.com", Instant.now().getEpochSecond(), RandomStringUtils.randomAlphabetic(4).toLowerCase());
    CertificateRequest request = new CertificateRequest().subject(new CertificateRequest.PKIXName().commonName(cn).organization(Collections.singletonList("Venafi, Inc.")).organizationalUnit(Collections.singletonList("Automated Tests")).locality(Collections.singletonList("Las Vegas")).province(Collections.singletonList("Nevada")).country(Collections.singletonList("US"))).friendlyName(cn).keyLength(512);
    classUnderTest.generateRequest(zoneConfig, request);
    logger.info("getPolicyDN(ZoneTag) = %s", classUnderTest.getPolicyDN(zoneTag));
    ZoneConfiguration zoneConfiguration = new ZoneConfiguration();
    zoneConfiguration.zoneId(classUnderTest.getPolicyDN(zoneTag));
    String requestId = classUnderTest.requestCertificate(request, zoneConfiguration);
    assertEquals("reqId", requestId);
}
Also used : ServerPolicy(com.venafi.vcert.sdk.connectors.ServerPolicy) ZoneConfiguration(com.venafi.vcert.sdk.connectors.ZoneConfiguration) LockableValue(com.venafi.vcert.sdk.connectors.LockableValue) CertificateRequest(com.venafi.vcert.sdk.certificate.CertificateRequest) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

ServerPolicy (com.venafi.vcert.sdk.connectors.ServerPolicy)3 ZoneConfiguration (com.venafi.vcert.sdk.connectors.ZoneConfiguration)3 CertificateRequest (com.venafi.vcert.sdk.certificate.CertificateRequest)2 LockableValue (com.venafi.vcert.sdk.connectors.LockableValue)2 BouncyCastleProvider (org.bouncycastle.jce.provider.BouncyCastleProvider)2 DisplayName (org.junit.jupiter.api.DisplayName)2 Test (org.junit.jupiter.api.Test)2 Policy (com.venafi.vcert.sdk.connectors.Policy)1 TPPPolicy (com.venafi.vcert.sdk.policy.api.domain.TPPPolicy)1