diff --git a/src/main/java/net/snowflake/client/core/CredentialManager.java b/src/main/java/net/snowflake/client/core/CredentialManager.java index 0cd91f9ce..a5b919d3d 100644 --- a/src/main/java/net/snowflake/client/core/CredentialManager.java +++ b/src/main/java/net/snowflake/client/core/CredentialManager.java @@ -40,6 +40,7 @@ private void initSecureStorageManager() { /** Helper function for tests to go back to normal settings. */ void resetSecureStorageManager() { + logger.debug("Resetting the secure storage manager"); initSecureStorageManager(); } @@ -49,6 +50,7 @@ void resetSecureStorageManager() { * @param manager */ void injectSecureStorageManager(SecureStorageManager manager) { + logger.debug("Injecting secure storage manager"); secureStorageManager = manager; } @@ -66,6 +68,10 @@ public static CredentialManager getInstance() { * @param loginInput login input to attach id token */ void fillCachedIdToken(SFLoginInput loginInput) throws SFException { + logger.debug( + "Looking for cached id token for user: {}, host: {}", + loginInput.getUserName(), + loginInput.getHostFromServerUrl()); fillCachedCredential(loginInput, ID_TOKEN); } @@ -75,6 +81,10 @@ void fillCachedIdToken(SFLoginInput loginInput) throws SFException { * @param loginInput login input to attach mfa token */ void fillCachedMfaToken(SFLoginInput loginInput) throws SFException { + logger.debug( + "Looking for cached mfa token for user: {}, host: {}", + loginInput.getUserName(), + loginInput.getHostFromServerUrl()); fillCachedCredential(loginInput, MFA_TOKEN); } @@ -106,16 +116,26 @@ synchronized void fillCachedCredential(SFLoginInput loginInput, String credType) } if (cred == null) { - logger.debug("retrieved %s is null", credType); + logger.debug("Retrieved {} is null", credType); } // cred can be null if (credType == ID_TOKEN) { + logger.debug( + "Setting {}id token for user: {}, host: {}", + cred == null ? "null " : "", + loginInput.getUserName(), + loginInput.getHostFromServerUrl()); loginInput.setIdToken(cred); } else if (credType == MFA_TOKEN) { + logger.debug( + "Setting {}mfa token for user: {}, host: {}", + cred == null ? "null " : "", + loginInput.getUserName(), + loginInput.getHostFromServerUrl()); loginInput.setMfaToken(cred); } else { - logger.debug("unrecognized type %s for local cached credential", credType); + logger.debug("Unrecognized type {} for local cached credential", credType); } return; } @@ -127,6 +147,10 @@ synchronized void fillCachedCredential(SFLoginInput loginInput, String credType) * @param loginOutput loginOutput to denote to the cache */ void writeIdToken(SFLoginInput loginInput, SFLoginOutput loginOutput) throws SFException { + logger.debug( + "Caching id token in a secure storage for user: {}, host: {}", + loginInput.getUserName(), + loginInput.getHostFromServerUrl()); writeTemporaryCredential(loginInput, loginOutput.getIdToken(), ID_TOKEN); } @@ -137,6 +161,10 @@ void writeIdToken(SFLoginInput loginInput, SFLoginOutput loginOutput) throws SFE * @param loginOutput loginOutput to denote to the cache */ void writeMfaToken(SFLoginInput loginInput, SFLoginOutput loginOutput) throws SFException { + logger.debug( + "Caching mfa token in a secure storage for user: {}, host: {}", + loginInput.getUserName(), + loginInput.getHostFromServerUrl()); writeTemporaryCredential(loginInput, loginOutput.getMfaToken(), MFA_TOKEN); } @@ -150,7 +178,7 @@ void writeMfaToken(SFLoginInput loginInput, SFLoginOutput loginOutput) throws SF synchronized void writeTemporaryCredential(SFLoginInput loginInput, String cred, String credType) throws SFException { if (Strings.isNullOrEmpty(cred)) { - logger.debug("no %s is given.", credType); + logger.debug("No {} is given.", credType); return; // no credential } @@ -173,11 +201,15 @@ synchronized void writeTemporaryCredential(SFLoginInput loginInput, String cred, /** Delete the id token cache */ void deleteIdTokenCache(String host, String user) { + logger.debug( + "Removing cached id token from a secure storage for user: {}, host: {}", user, host); deleteTemporaryCredential(host, user, ID_TOKEN); } /** Delete the mfa token cache */ void deleteMfaTokenCache(String host, String user) { + logger.debug( + "Removing cached mfa token from a secure storage for user: {}, host: {}", user, host); deleteTemporaryCredential(host, user, MFA_TOKEN); } diff --git a/src/main/java/net/snowflake/client/core/FileCacheManager.java b/src/main/java/net/snowflake/client/core/FileCacheManager.java index e635796c0..2c472f476 100644 --- a/src/main/java/net/snowflake/client/core/FileCacheManager.java +++ b/src/main/java/net/snowflake/client/core/FileCacheManager.java @@ -317,4 +317,8 @@ private static long fileCreationTime(File targetFile) { } return -1; } + + String getCacheFilePath() { + return cacheFile.getAbsolutePath(); + } } diff --git a/src/main/java/net/snowflake/client/core/SecureStorageAppleManager.java b/src/main/java/net/snowflake/client/core/SecureStorageAppleManager.java index 144caefec..5030e4603 100644 --- a/src/main/java/net/snowflake/client/core/SecureStorageAppleManager.java +++ b/src/main/java/net/snowflake/client/core/SecureStorageAppleManager.java @@ -22,6 +22,7 @@ private SecureStorageAppleManager() { } public static SecureStorageAppleManager builder() { + logger.info("Using Apple Keychain as a token cache storage"); return new SecureStorageAppleManager(); } diff --git a/src/main/java/net/snowflake/client/core/SecureStorageLinuxManager.java b/src/main/java/net/snowflake/client/core/SecureStorageLinuxManager.java index e1f352187..7663147b3 100644 --- a/src/main/java/net/snowflake/client/core/SecureStorageLinuxManager.java +++ b/src/main/java/net/snowflake/client/core/SecureStorageLinuxManager.java @@ -41,6 +41,8 @@ private SecureStorageLinuxManager() { .setCacheExpirationInSeconds(CACHE_EXPIRATION_IN_SECONDS) .setCacheFileLockExpirationInSeconds(CACHE_FILE_LOCK_EXPIRATION_IN_SECONDS) .build(); + logger.info( + "Using temporary file: {} as a token cache storage", fileCacheManager.getCacheFilePath()); } private static class SecureStorageLinuxManagerHolder { diff --git a/src/main/java/net/snowflake/client/core/SecureStorageWindowsManager.java b/src/main/java/net/snowflake/client/core/SecureStorageWindowsManager.java index f43952023..f38c1570b 100644 --- a/src/main/java/net/snowflake/client/core/SecureStorageWindowsManager.java +++ b/src/main/java/net/snowflake/client/core/SecureStorageWindowsManager.java @@ -33,6 +33,7 @@ private SecureStorageWindowsManager() { } public static SecureStorageWindowsManager builder() { + logger.info("Using Windows Credential Manager as a token cache storage"); return new SecureStorageWindowsManager(); }