From 946b53544a30ed5a2333e2a1abc79b1090d9be45 Mon Sep 17 00:00:00 2001 From: Devin Nusbaum Date: Fri, 30 Aug 2024 10:29:18 -0400 Subject: [PATCH] Rename tokenExpiry field to prevent Folders corruption issues when upgrading from old versions of this plugin (#336) --- .../AbstractVaultTokenCredentialWithExpiration.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/datapipe/jenkins/vault/credentials/AbstractVaultTokenCredentialWithExpiration.java b/src/main/java/com/datapipe/jenkins/vault/credentials/AbstractVaultTokenCredentialWithExpiration.java index 0cf695fe..cb330c87 100644 --- a/src/main/java/com/datapipe/jenkins/vault/credentials/AbstractVaultTokenCredentialWithExpiration.java +++ b/src/main/java/com/datapipe/jenkins/vault/credentials/AbstractVaultTokenCredentialWithExpiration.java @@ -44,13 +44,14 @@ public void setUsePolicies(Boolean usePolicies) { this.usePolicies = usePolicies; } - private transient Map tokenExpiry; + // Renamed from tokenExpiry to prevent XStream from attempting to deserialize old instances of this class which had the type `Calendar` prior to https://github.com/jenkinsci/hashicorp-vault-plugin/pull/223. + private transient Map tokenExpiryCache; private transient Map tokenCache; protected AbstractVaultTokenCredentialWithExpiration(CredentialsScope scope, String id, String description) { super(scope, id, description); - tokenExpiry = new HashMap<>(); + tokenExpiryCache = new HashMap<>(); tokenCache = new HashMap<>(); } @@ -108,7 +109,7 @@ public Vault authorizeWithVault(VaultConfig config, List policies) { // Upgraded instances can have these not initialized in the constructor (serialized jobs possibly) if (tokenCache == null) { tokenCache = new HashMap<>(); - tokenExpiry = new HashMap<>(); + tokenExpiryCache = new HashMap<>(); } String cacheKey = getCacheKey(policies); @@ -150,11 +151,11 @@ private void setTokenExpiry(Vault vault, String cacheKey) { } Calendar expiry = Calendar.getInstance(); expiry.add(Calendar.SECOND, tokenTTL); - tokenExpiry.put(cacheKey, expiry); + tokenExpiryCache.put(cacheKey, expiry); } private boolean tokenExpired(String cacheKey) { - Calendar expiry = tokenExpiry.get(cacheKey); + Calendar expiry = tokenExpiryCache.get(cacheKey); if (expiry == null) { return true; }