Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ hs_err_pid*

.idea/
*.iml
target/
target/
/.settings/
/.classpath
/.factorypath
/.project
4 changes: 2 additions & 2 deletions examples/com/venafi/vcert/sdk/example/TppClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static void main(String[] args) throws VCertException, CertificateEncodin
appInfo = "CompanyName AppName";

// Configuration
Config config = Config.builder().connectorType(ConnectorType.TPP).baseUrl(url).appInfo(appInfo)
Config config = Config.builder().connectorType(ConnectorType.TPP_VEDAUTH).baseUrl(url).appInfo(appInfo)
// To use proxy uncomment the lines below
// .proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 8888)))
// .proxyUser("myUser")
Expand All @@ -61,7 +61,7 @@ public static void main(String[] args) throws VCertException, CertificateEncodin
.province(Collections.singletonList("Utah")))
.keyType(KeyType.RSA).keyLength(2048);

certificateRequest = client.generateRequest(zoneConfiguration, certificateRequest);
certificateRequest = client.generateRequest(zoneConfiguration, certificateRequest, access_token);

// Submit the certificate request
client.requestCertificate(certificateRequest, zoneConfiguration);
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/com/venafi/vcert/sdk/VCertClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
import com.venafi.vcert.sdk.endpoint.ConnectorType;

public class VCertClient implements Connector {
private static final String DEFAULT_VENDOR_AND_PRODUCT_NAME = "Venafi VCert-Java";

private Connector connector;
private static final String defaultVendorAndProductName = "Venafi VCert-Java";

public VCertClient(Config config) throws VCertException {
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
Expand All @@ -42,7 +42,7 @@ public VCertClient(Config config) throws VCertException {
throw new VCertException("ConnectorType is not defined");
}

connector.setVendorAndProductName(isBlank(config.appInfo()) ? defaultVendorAndProductName : config.appInfo());
connector.setVendorAndProductName(isBlank(config.appInfo()) ? DEFAULT_VENDOR_AND_PRODUCT_NAME : config.appInfo());
}

@VisibleForTesting
Expand Down Expand Up @@ -245,5 +245,4 @@ public Policy readPolicyConfiguration(String zone) throws VCertException {
}
return null;
}

}
247 changes: 247 additions & 0 deletions src/main/java/com/venafi/vcert/sdk/VCertTknClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,247 @@
package com.venafi.vcert.sdk;

import com.google.common.annotations.VisibleForTesting;
import com.venafi.vcert.sdk.certificate.*;
import com.venafi.vcert.sdk.connectors.Policy;
import com.venafi.vcert.sdk.connectors.TokenConnector;
import com.venafi.vcert.sdk.connectors.ZoneConfiguration;
import com.venafi.vcert.sdk.connectors.tpp.TokenInfo;
import com.venafi.vcert.sdk.connectors.tpp.Tpp;
import com.venafi.vcert.sdk.connectors.tpp.TppTokenConnector;
import com.venafi.vcert.sdk.endpoint.Authentication;
import com.venafi.vcert.sdk.endpoint.ConnectorType;
import feign.FeignException;

import java.security.Security;

import static org.apache.commons.lang3.StringUtils.isBlank;

public class VCertTknClient implements TokenConnector {
private static final String defaultVendorAndProductName = "Venafi VCert-Java";

private TokenConnector connector;

public VCertTknClient(Config config) throws VCertException {
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
switch (config.connectorType()) {
case TPP_TOKEN:
connector = new TppTokenConnector(Tpp.connect(config));
break;
default:
throw new VCertException("ConnectorType is not defined");
}
connector.setVendorAndProductName(isBlank(config.appInfo()) ? defaultVendorAndProductName : config.appInfo());
}

@VisibleForTesting
VCertTknClient(TokenConnector connector) {
this.connector = connector;
}

/**
* {@inheritDoc}
*/
@Override
public ConnectorType getType() {
return connector.getType();
}

/**
* {@inheritDoc}
*/
@Override
public void setBaseUrl(String url) throws VCertException {
connector.setBaseUrl(url);
}

/**
* {@inheritDoc}
*/
@Override
public void setZone(String zone) {
connector.setZone(zone);
}

/**
* {@inheritDoc}
*/
@Override
public void setVendorAndProductName(String vendorAndProductName) {
connector.setVendorAndProductName(vendorAndProductName);
}

/**
* {@inheritDoc}
*/
@Override
public String getVendorAndProductName() {
return connector.getVendorAndProductName();
}

//=========================================================================================\\
//=============================== VENAFI 20.2 OAUTH METHODS ===============================\\
//=========================================================================================\\

@Override
public TokenInfo getAccessToken(Authentication auth) throws VCertException{
try {
return connector.getAccessToken(auth);
} catch (FeignException e) {
throw VCertException.fromFeignException(e);
} catch (Exception e) {
throw new VCertException("Unexpected exception", e);
}
}

@Override
public TokenInfo refreshAccessToken(String refreshToken, String applicationId) throws VCertException{
return connector.refreshAccessToken(refreshToken, applicationId);
}

@Override
public int revokeAccessToken(String accessToken) throws VCertException {
return connector.revokeAccessToken(accessToken);
}

/**
* {@inheritDoc}
*/
@Override
public void ping(String accessToken) throws VCertException {
try {
connector.ping(accessToken);
} catch (FeignException e) {
throw VCertException.fromFeignException(e);
} catch (Exception e) {
throw new VCertException("Unexpected exception", e);
}
}

/**
* {@inheritDoc}
*/
@Override
public ZoneConfiguration readZoneConfiguration(String zone, String accessToken) throws VCertException {
try {
return connector.readZoneConfiguration(zone, accessToken);
} catch (FeignException e) {
throw VCertException.fromFeignException(e);
} catch (Exception e) {
throw new VCertException("Unexpected exception", e);
}
}

/**
* {@inheritDoc}
*/
@Override
public CertificateRequest generateRequest(ZoneConfiguration config, CertificateRequest request, String accessToken)
throws VCertException {
try {
return connector.generateRequest(config, request, accessToken);
} catch (FeignException e) {
throw VCertException.fromFeignException(e);
} catch (Exception e) {
throw new VCertException("Unexpected exception", e);
}
}

@Override
public String requestCertificate(CertificateRequest request, String zone, String accessToken) throws VCertException {
try {
return connector.requestCertificate(request, zone, accessToken);
} catch (FeignException e) {
throw VCertException.fromFeignException(e);
} catch (Exception e) {
throw new VCertException("Unexpected exception", e);
}
}

/**
* {@inheritDoc}
*/
@Override
public String requestCertificate(CertificateRequest request, ZoneConfiguration zoneConfiguration, String accessToken)
throws VCertException {
try {
return connector.requestCertificate(request, zoneConfiguration, accessToken);
} catch (FeignException e) {
throw VCertException.fromFeignException(e);
} catch (Exception e) {
throw new VCertException("Unexpected exception", e);
}
}

/**
* {@inheritDoc}
*/
@Override
public PEMCollection retrieveCertificate(CertificateRequest request, String accessToken) throws VCertException {
try {
return connector.retrieveCertificate(request, accessToken);
} catch (FeignException e) {
throw VCertException.fromFeignException(e);
} catch (Exception e) {
throw new VCertException("Unexpected exception", e);
}
}

/**
* {@inheritDoc}
*/
@Override
public void revokeCertificate(RevocationRequest request, String accessToken) throws VCertException {
try {
connector.revokeCertificate(request, accessToken);
} catch (FeignException e) {
throw VCertException.fromFeignException(e);
} catch (Exception e) {
throw new VCertException("Unexpected exception", e);
}
}

/**
* {@inheritDoc}
*/
@Override
public String renewCertificate(RenewalRequest request, String accessToken) throws VCertException {
try {
connector.renewCertificate(request, accessToken);
} catch (FeignException e) {
throw VCertException.fromFeignException(e);
} catch (Exception e) {
throw new VCertException("Unexpected exception", e);
}
return null;
}

/**
* {@inheritDoc}
*/
@Override
public ImportResponse importCertificate(ImportRequest request, String accessToken) throws VCertException {
try {
connector.importCertificate(request, accessToken);
} catch (FeignException e) {
throw VCertException.fromFeignException(e);
} catch (Exception e) {
throw new VCertException("Unexpected exception", e);
}
return null;
}

/**
* {@inheritDoc}
*/
@Override
public Policy readPolicyConfiguration(String zone, String accessToken) throws VCertException {
try {
connector.readPolicyConfiguration(zone, accessToken);
} catch (FeignException e) {
throw VCertException.fromFeignException(e);
} catch (Exception e) {
throw new VCertException("Unexpected exception", e);
}
return null;
}
}
Loading