mirror of https://github.com/apache/jclouds.git
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.
This commit is contained in:
parent
0c054c1835
commit
2487b0c513
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
public static class CredentialsToJsonByteSource implements Function<Credentials, ByteSource> {
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue