use of com.venafi.vcert.sdk.connectors.tpp.TokenInfo in project vcert-java by Venafi.
the class TestUtils method getAccessToken.
public static String getAccessToken() throws VCertException {
String accesToken = "";
String userName = TPP_USER;
String pass = TPP_PASSWORD;
String url = TPP_TOKEN_URL;
Authentication auth = Authentication.builder().user(userName).password(pass).build();
Config config = Config.builder().connectorType(ConnectorType.TPP_TOKEN).baseUrl(url).credentials(auth).build();
VCertTknClient client = new VCertTknClient(config);
TokenInfo tokeInfo = client.getAccessToken();
if (tokeInfo != null) {
return tokeInfo.accessToken();
}
return accesToken;
}
use of com.venafi.vcert.sdk.connectors.tpp.TokenInfo in project vcert-java by Venafi.
the class TppTokenClient method main.
public static void main(String[] args) throws VCertException, CertificateEncodingException, NoSuchAlgorithmException, KeyManagementException {
String url = System.getenv("TPP_TOKEN_URL");
String zone = System.getenv("TPPZONE");
String appInfo = System.getenv("PRODUCT");
String tpp_user = System.getenv("TPPUSER");
String tpp_passwd = System.getenv("TPPPASSWORD");
if (tpp_user == null)
tpp_user = "local:admin";
if (tpp_passwd == null)
tpp_passwd = "password";
if (url == null)
url = "https://tpp.venafi.example/vedsdk";
if (zone == null)
zone = "Certificates\\vcert\\";
if (appInfo == null)
appInfo = "CompanyName AppName";
// Configuration
Config config = Config.builder().connectorType(ConnectorType.TPP_TOKEN).baseUrl(url).appInfo(appInfo).build();
Authentication auth = Authentication.builder().user(tpp_user).password(tpp_passwd).build();
VCertTknClient client = new VCertTknClient(config);
TokenInfo tknInfo = client.getAccessToken(auth);
ZoneConfiguration zoneConfiguration = client.readZoneConfiguration(zone);
// Generate a certificate
CertificateRequest certificateRequest = new CertificateRequest().subject(new CertificateRequest.PKIXName().commonName("vcert-java.venafi.example").organization(Collections.singletonList("Venafi, Inc.")).organizationalUnit(Arrays.asList("Product Management")).country(Collections.singletonList("US")).locality(Collections.singletonList("Salt Lake City")).province(Collections.singletonList("Utah"))).keyType(KeyType.RSA).keyLength(2048);
certificateRequest = client.generateRequest(zoneConfiguration, certificateRequest);
// Submit the certificate request
client.requestCertificate(certificateRequest, zoneConfiguration);
// Retrieve PEM collection from Venafi
PEMCollection pemCollection = client.retrieveCertificate(certificateRequest);
System.out.println(pemCollection.certificate());
}
Aggregations