You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by sv...@apache.org on 2017/07/27 11:59:15 UTC
jclouds git commit: Use separate credential stores per context
Repository: jclouds
Updated Branches:
refs/heads/master 0c054c183 -> 2487b0c51
Use separate credential stores per context
With a shared credential store the configuration of one compute service leaks in all others, causing the wrong credentials to be used when not overriden.
Project: http://git-wip-us.apache.org/repos/asf/jclouds/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds/commit/2487b0c5
Tree: http://git-wip-us.apache.org/repos/asf/jclouds/tree/2487b0c5
Diff: http://git-wip-us.apache.org/repos/asf/jclouds/diff/2487b0c5
Branch: refs/heads/master
Commit: 2487b0c5132191de5e68413e33dfa551b5679ebb
Parents: 0c054c1
Author: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Authored: Tue Jul 11 12:03:47 2017 +0300
Committer: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Committed: Thu Jul 27 14:57:06 2017 +0300
----------------------------------------------------------------------
.../rest/config/CredentialStoreModule.java | 12 ++----
.../jclouds/rest/CredentialStoreModuleTest.java | 42 +++++++++++---------
2 files changed, 26 insertions(+), 28 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jclouds/blob/2487b0c5/core/src/main/java/org/jclouds/rest/config/CredentialStoreModule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/jclouds/rest/config/CredentialStoreModule.java b/core/src/main/java/org/jclouds/rest/config/CredentialStoreModule.java
index cd5481a..2f4ffc8 100644
--- a/core/src/main/java/org/jclouds/rest/config/CredentialStoreModule.java
+++ b/core/src/main/java/org/jclouds/rest/config/CredentialStoreModule.java
@@ -42,7 +42,6 @@ import com.google.inject.TypeLiteral;
@Beta
@ConfiguresCredentialStore
public class CredentialStoreModule extends AbstractModule {
- private static final Map<String, ByteSource> BACKING = new ConcurrentHashMap<String, ByteSource>();
private final Map<String, ByteSource> backing;
public CredentialStoreModule(Map<String, ByteSource> backing) {
@@ -50,7 +49,7 @@ public class CredentialStoreModule extends AbstractModule {
}
public CredentialStoreModule() {
- this(null);
+ this(new ConcurrentHashMap<String, ByteSource>());
}
@Override
@@ -59,13 +58,8 @@ public class CredentialStoreModule extends AbstractModule {
}).to(CredentialsToJsonByteSource.class);
bind(new TypeLiteral<Function<ByteSource, Credentials>>() {
}).to(CredentialsFromJsonByteSource.class);
- if (backing != null) {
- bind(new TypeLiteral<Map<String, ByteSource>>() {
- }).toInstance(backing);
- } else {
- bind(new TypeLiteral<Map<String, ByteSource>>() {
- }).toInstance(BACKING);
- }
+ bind(new TypeLiteral<Map<String, ByteSource>>() {
+ }).toInstance(backing);
}
public static class CredentialsToJsonByteSource implements Function<Credentials, ByteSource> {
http://git-wip-us.apache.org/repos/asf/jclouds/blob/2487b0c5/core/src/test/java/org/jclouds/rest/CredentialStoreModuleTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/jclouds/rest/CredentialStoreModuleTest.java b/core/src/test/java/org/jclouds/rest/CredentialStoreModuleTest.java
index 9e4635b..d928722 100644
--- a/core/src/test/java/org/jclouds/rest/CredentialStoreModuleTest.java
+++ b/core/src/test/java/org/jclouds/rest/CredentialStoreModuleTest.java
@@ -95,34 +95,38 @@ public class CredentialStoreModuleTest {
}
- public void testDefaultConsistentAcrossMultipleInjectors() throws IOException {
- Map<String, ByteSource> map = getMap(createInjector());
-
- put(map, getStore(createInjector()), "test", new Credentials("user", "pass"));
- checkConsistent(map, getStore(createInjector()), "test", new Credentials("user", "pass"));
- checkConsistent(map, getStore(createInjector()), "test", new Credentials("user", "pass"));
- remove(map, getStore(createInjector()), "test");
+ public void testDefaultDifferentAcrossMultipleInjectors() throws IOException {
+ Injector injector = createInjector();
+ Map<String, ByteSource> map = getMap(injector);
+ put(map, getStore(injector), "test", new Credentials("user", "pass"));
+ Map<String, Credentials> anotherStore = getStore(createInjector());
+ assertEquals(anotherStore.size(), 0);
+ assertFalse(anotherStore.containsKey("test"));
}
- public void testLoginConsistentAcrossMultipleInjectorsAndLooksNice() throws IOException {
- Map<String, ByteSource> map = getMap(createInjector());
+ public void testLoginDifferentAcrossMultipleInjectorsAndLooksNice() throws IOException {
+ Injector injector = createInjector();
+ Map<String, ByteSource> map = getMap(injector);
LoginCredentials creds = LoginCredentials.builder().user("user").password("pass").build();
- put(map, getStore(createInjector()), "test", creds);
- checkConsistent(map, getStore(createInjector()), "test", creds, "{\"user\":\"user\",\"password\":\"pass\"}");
- checkConsistent(map, getStore(createInjector()), "test", creds, "{\"user\":\"user\",\"password\":\"pass\"}");
- remove(map, getStore(createInjector()), "test");
+ Map<String, Credentials> store = getStore(injector);
+ put(map, store, "test", creds);
+ checkConsistent(map, store, "test", creds, "{\"user\":\"user\",\"password\":\"pass\"}");
+ checkConsistent(map, store, "test", creds, "{\"user\":\"user\",\"password\":\"pass\"}");
+ remove(map, store, "test");
}
- public void testLoginConsistentAcrossMultipleInjectorsAndLooksNiceWithSudo() throws IOException {
- Map<String, ByteSource> map = getMap(createInjector());
+ public void testLoginDifferentAcrossMultipleInjectorsAndLooksNiceWithSudo() throws IOException {
+ Injector injector = createInjector();
+ Map<String, ByteSource> map = getMap(injector);
LoginCredentials creds = LoginCredentials.builder().user("user").password("pass").authenticateSudo(true).build();
- put(map, getStore(createInjector()), "test", creds);
- checkConsistent(map, getStore(createInjector()), "test", creds,
+ Map<String, Credentials> store = getStore(injector);
+ put(map, store, "test", creds);
+ checkConsistent(map, store, "test", creds,
"{\"user\":\"user\",\"password\":\"pass\",\"authenticateSudo\":true}");
- checkConsistent(map, getStore(createInjector()), "test", creds,
+ checkConsistent(map, store, "test", creds,
"{\"user\":\"user\",\"password\":\"pass\",\"authenticateSudo\":true}");
- remove(map, getStore(createInjector()), "test");
+ remove(map, store, "test");
}
public void testCredentialsToByteSourceConversion() throws Exception {