Search in sources :

Example 1 with TokenInfo

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;
}
Also used : Authentication(com.venafi.vcert.sdk.endpoint.Authentication) TokenInfo(com.venafi.vcert.sdk.connectors.tpp.TokenInfo)

Example 2 with TokenInfo

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());
}
Also used : VCertTknClient(com.venafi.vcert.sdk.VCertTknClient) PEMCollection(com.venafi.vcert.sdk.certificate.PEMCollection) Config(com.venafi.vcert.sdk.Config) Authentication(com.venafi.vcert.sdk.endpoint.Authentication) ZoneConfiguration(com.venafi.vcert.sdk.connectors.ZoneConfiguration) CertificateRequest(com.venafi.vcert.sdk.certificate.CertificateRequest) TokenInfo(com.venafi.vcert.sdk.connectors.tpp.TokenInfo)

Aggregations

TokenInfo (com.venafi.vcert.sdk.connectors.tpp.TokenInfo)2 Authentication (com.venafi.vcert.sdk.endpoint.Authentication)2 Config (com.venafi.vcert.sdk.Config)1 VCertTknClient (com.venafi.vcert.sdk.VCertTknClient)1 CertificateRequest (com.venafi.vcert.sdk.certificate.CertificateRequest)1 PEMCollection (com.venafi.vcert.sdk.certificate.PEMCollection)1 ZoneConfiguration (com.venafi.vcert.sdk.connectors.ZoneConfiguration)1