Example usage for org.springframework.vault.support VaultHealth getServerTimeUtc

List of usage examples for org.springframework.vault.support VaultHealth getServerTimeUtc

Introduction

In this page you can find the example usage for org.springframework.vault.support VaultHealth getServerTimeUtc.

Prototype

int getServerTimeUtc();

Source Link

Usage

From source file:example.pki.CertificateUtil.java

private static void storeCertificate(String cacheKey, VaultOperations vaultOperations, VaultHealth health,
        VaultCertificateResponse certificateResponse) {

    CertificateBundle certificateBundle = certificateResponse.getData();
    long expires = (health.getServerTimeUtc() + certificateResponse.getLeaseDuration())
            - REFRESH_PERIOD_BEFORE_EXPIRY;

    CachedCertificateBundle cachedCertificateBundle = new CachedCertificateBundle();

    cachedCertificateBundle.setExpires(expires);
    cachedCertificateBundle.setTimeRequested(health.getServerTimeUtc());
    cachedCertificateBundle.setPrivateKey(certificateBundle.getPrivateKey());
    cachedCertificateBundle.setCertificate(certificateBundle.getCertificate());
    cachedCertificateBundle.setIssuingCaCertificate(certificateBundle.getIssuingCaCertificate());
    cachedCertificateBundle.setSerialNumber(certificateBundle.getSerialNumber());

    vaultOperations.write(cacheKey, cachedCertificateBundle);
}

From source file:example.pki.CertificateUtil.java

private static boolean isValid(VaultHealth health, VaultResponseSupport<CachedCertificateBundle> readResponse) {

    if (readResponse != null) {

        CachedCertificateBundle cachedCertificateBundle = readResponse.getData();
        if (health.getServerTimeUtc() < cachedCertificateBundle.getExpires()) {
            return true;
        }//from w  w  w.j ava  2  s .  co  m
    }

    return false;
}