use of com.venafi.vcert.sdk.endpoint.Authentication in project vcert-java by Venafi.
the class TppTokenConnectorResource method authenticate.
private void authenticate() throws Exception {
Authentication authentication = Authentication.builder().user(TestUtils.TPP_USER).password(TestUtils.TPP_PASSWORD).scope("certificate:manage,revoke,discover;configuration:manage").build();
connector = new TppTokenConnector(Tpp.connect(TestUtils.TPP_TOKEN_URL));
TokenInfo info = connector.getAccessToken(authentication);
assertThat(info).isNotNull();
assertThat(info.authorized()).isTrue();
assertThat(info.errorMessage()).isNull();
assertThat(info.accessToken()).isNotNull();
assertThat(info.refreshToken()).isNotNull();
this.info = info;
}
use of com.venafi.vcert.sdk.endpoint.Authentication 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.endpoint.Authentication in project vcert-java by Venafi.
the class SshCertificateRequestRetrieveWithOutKeyPairProvided method main.
/**
* @param args
*/
public static void main(String[] args) {
try {
// replace it by the key id value
String keyId = "<KEY_ID>";
// replace it by the CADN or the CA Name
String template = "<TPP_SSH_CA>";
// replace it by the TPP User
String user = "<TPPUSER>";
// replace it by the TPP Password
String password = "<TPPPASSWORD>";
// replace it by the TPP URL
String baseUri = "<TPP_URL>";
// 1. Get a VCertClient for TPP setting the scope to "ssh:manage"
Authentication auth = Authentication.builder().user(user).password(password).scope("ssh:manage").build();
Config config = Config.builder().connectorType(ConnectorType.TPP_TOKEN).baseUrl(baseUri).build();
VCertTknClient client = new VCertTknClient(config);
client.getAccessToken(auth);
// 2. Get an instance of com.venafi.vcert.sdk.certificate.SshCertificateRequest class.
SshCertificateRequest req = new SshCertificateRequest().keyId(keyId).validityPeriod(// if you omit it, then the validity period of the CIT will be used
"4h").template(template);
// 3. Use the VCertClient method requestSshCertificate() to request the creation of a new
// SSH Certificate on TPP. This will return the DN of the created SSH Certificate which
// will be used to retrieve the created SSH Certificate.
String pickUpID = client.requestSshCertificate(req);
// 4. Set the pickUp ID to the SshCertificateRequest created. You can create a new one
// but in order to avoid the boilerplate, it's preferable to use the already one created.
req.pickupID(pickUpID);
// 4a. you can set a passphrase for the Private Key of the KeyPair that will be generated by TPP.
req.privateKeyPassphrase("my-passphrase");
// 5. Use the VCertClient method retrieveSshCertificate() to retrieve the created
// SSH Certificate on TPP. It will return an instance of SshCertRetrieveDetails which
// will contain the Ssh Certificate Data, the Public and Private Keys, etc.
SshCertRetrieveDetails sshCertRetrieveDetails = client.retrieveSshCertificate(req);
client.revokeAccessToken();
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.venafi.vcert.sdk.endpoint.Authentication in project vcert-java by Venafi.
the class TppClient method main.
public static void main(String[] args) throws VCertException, CertificateEncodingException, NoSuchAlgorithmException, KeyManagementException {
String url = System.getenv("TPPURL");
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).baseUrl(url).appInfo(appInfo).build();
Authentication auth = Authentication.builder().user(tpp_user).password(tpp_passwd).build();
VCertClient client = new VCertClient(config);
client.authenticate(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());
}
use of com.venafi.vcert.sdk.endpoint.Authentication 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