Skip to content

Commit 8b7aa40

Browse files
refactor convertTarget name
1 parent 4bee3f1 commit 8b7aa40

File tree

5 files changed

+15
-15
lines changed

5 files changed

+15
-15
lines changed

src/main/java/net/snowflake/client/core/SecureStorageAppleManager.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public SecureStorageStatus setCredential(String host, String user, String type,
3232
return SecureStorageStatus.SUCCESS;
3333
}
3434

35-
String target = SecureStorageManager.convertTarget(host, user, type);
35+
String target = SecureStorageManager.buildCredentialsKey(host, user, type);
3636
byte[] targetBytes = target.getBytes(StandardCharsets.UTF_8);
3737
byte[] userBytes = user.toUpperCase().getBytes(StandardCharsets.UTF_8);
3838
byte[] credBytes = cred.getBytes(StandardCharsets.UTF_8);
@@ -92,7 +92,7 @@ public SecureStorageStatus setCredential(String host, String user, String type,
9292
}
9393

9494
public String getCredential(String host, String user, String type) {
95-
String target = SecureStorageManager.convertTarget(host, user, type);
95+
String target = SecureStorageManager.buildCredentialsKey(host, user, type);
9696
byte[] targetBytes = target.getBytes(StandardCharsets.UTF_8);
9797
byte[] userBytes = user.toUpperCase().getBytes(StandardCharsets.UTF_8);
9898

@@ -141,7 +141,7 @@ public String getCredential(String host, String user, String type) {
141141
}
142142

143143
public SecureStorageStatus deleteCredential(String host, String user, String type) {
144-
String target = SecureStorageManager.convertTarget(host, user, type);
144+
String target = SecureStorageManager.buildCredentialsKey(host, user, type);
145145
byte[] targetBytes = target.getBytes(StandardCharsets.UTF_8);
146146
byte[] userBytes = user.toUpperCase().getBytes(StandardCharsets.UTF_8);
147147

src/main/java/net/snowflake/client/core/SecureStorageLinuxManager.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public synchronized SecureStorageStatus setCredential(
6363
}
6464
localCredCache.computeIfAbsent(CACHE_FILE_TOKENS_OBJECT_NAME, tokensMap -> new HashMap<>());
6565
Map<String, String> tokensMap = localCredCache.get(CACHE_FILE_TOKENS_OBJECT_NAME);
66-
tokensMap.put(SecureStorageManager.convertTarget(host, user, type), token);
66+
tokensMap.put(SecureStorageManager.buildCredentialsKey(host, user, type), token);
6767
fileCacheManager.writeCacheFile(localCacheToJson());
6868
return SecureStorageStatus.SUCCESS;
6969
}
@@ -74,14 +74,14 @@ public synchronized String getCredential(String host, String user, String type)
7474
if (tokensMap == null) {
7575
return null;
7676
}
77-
return tokensMap.get(SecureStorageManager.convertTarget(host, user, type));
77+
return tokensMap.get(SecureStorageManager.buildCredentialsKey(host, user, type));
7878
}
7979

8080
/** May delete credentials which doesn't belong to this process */
8181
public synchronized SecureStorageStatus deleteCredential(String host, String user, String type) {
8282
Map<String, String> tokensMap = localCredCache.get(CACHE_FILE_TOKENS_OBJECT_NAME);
8383
if (tokensMap != null) {
84-
tokensMap.remove(SecureStorageManager.convertTarget(host, user, type));
84+
tokensMap.remove(SecureStorageManager.buildCredentialsKey(host, user, type));
8585
if (tokensMap.isEmpty()) {
8686
localCredCache.remove(CACHE_FILE_TOKENS_OBJECT_NAME);
8787
}

src/main/java/net/snowflake/client/core/SecureStorageManager.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ interface SecureStorageManager {
2020

2121
SecureStorageStatus deleteCredential(String host, String user, String type);
2222

23-
static String convertTarget(String host, String user, String type) {
23+
static String buildCredentialsKey(String host, String user, String type) {
2424
StringBuilder target =
2525
new StringBuilder(host.length() + user.length() + type.length() + 3 * COLON_CHAR_LENGTH);
2626

src/main/java/net/snowflake/client/core/SecureStorageWindowsManager.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public SecureStorageStatus setCredential(String host, String user, String type,
4747
Memory credBlobMem = new Memory(credBlob.length);
4848
credBlobMem.write(0, credBlob, 0, credBlob.length);
4949

50-
String target = SecureStorageManager.convertTarget(host, user, type);
50+
String target = SecureStorageManager.buildCredentialsKey(host, user, type);
5151

5252
SecureStorageWindowsCredential cred = new SecureStorageWindowsCredential();
5353
cred.Type = SecureStorageWindowsCredentialType.CRED_TYPE_GENERIC.getType();
@@ -76,7 +76,7 @@ public SecureStorageStatus setCredential(String host, String user, String type,
7676

7777
public String getCredential(String host, String user, String type) {
7878
PointerByReference pCredential = new PointerByReference();
79-
String target = SecureStorageManager.convertTarget(host, user, type);
79+
String target = SecureStorageManager.buildCredentialsKey(host, user, type);
8080

8181
try {
8282
boolean ret = false;
@@ -127,7 +127,7 @@ public String getCredential(String host, String user, String type) {
127127
}
128128

129129
public SecureStorageStatus deleteCredential(String host, String user, String type) {
130-
String target = SecureStorageManager.convertTarget(host, user, type);
130+
String target = SecureStorageManager.buildCredentialsKey(host, user, type);
131131

132132
boolean ret = false;
133133
synchronized (advapi32Lib) {

src/test/java/net/snowflake/client/core/SecureStorageManagerTest.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -226,27 +226,27 @@ public class SecureStorageManagerTest {
226226
private static final String MFA_TOKEN = "MFATOKEN";
227227

228228
@Test
229-
public void testConvertTarget() {
229+
public void testBuildCredentialsKey() {
230230
// hex values obtained using https://emn178.github.io/online-tools/sha256.html
231231
String hashedKey =
232-
SecureStorageManager.convertTarget(
232+
SecureStorageManager.buildCredentialsKey(
233233
host, user, CachedCredentialType.OAUTH_ACCESS_TOKEN.getValue());
234234
Assertions.assertEquals(
235235
"A7C7EBB89312E88552CD00664A0E20929801FACFBD682BF7C2363FB6EC8F914E", hashedKey);
236236

237237
hashedKey =
238-
SecureStorageManager.convertTarget(
238+
SecureStorageManager.buildCredentialsKey(
239239
host, user, CachedCredentialType.OAUTH_REFRESH_TOKEN.getValue());
240240
Assertions.assertEquals(
241241
"DB37028833FA02B125FBD6DE8CE679C7E62E7D38FAC585E98060E00987F96772", hashedKey);
242242

243243
hashedKey =
244-
SecureStorageManager.convertTarget(host, user, CachedCredentialType.ID_TOKEN.getValue());
244+
SecureStorageManager.buildCredentialsKey(host, user, CachedCredentialType.ID_TOKEN.getValue());
245245
Assertions.assertEquals(
246246
"6AA3F783E07D1D2182DAB59442806E2433C55C2BD4D9240790FD5B4B91FD4FDB", hashedKey);
247247

248248
hashedKey =
249-
SecureStorageManager.convertTarget(host, user, CachedCredentialType.MFA_TOKEN.getValue());
249+
SecureStorageManager.buildCredentialsKey(host, user, CachedCredentialType.MFA_TOKEN.getValue());
250250
Assertions.assertEquals(
251251
"9D10D4EFE45605D85993C6AC95334F1B63D36611B83615656EC7F277A947BF4B", hashedKey);
252252
}

0 commit comments

Comments
 (0)