Description
All the configuration trickery that we test (and some that we don’t test) can be found in various implementations of AbstractCouchbaseConfiguration in src/test/java/**. The most complete is the org.springframework.data.couchbase.domain.Config
I find a method that uses an authenticator() (username/password) to create a client factory. That method could be modified to take connectionString and authenticator as an argument. NOTE: for your purpose, these two methods should not be in the Config class, and the mappingCouchbaseConverter should come from the bean.
// do not use couchbaseClientFactory for the name of this method, otherwise the value of that bean will
// will be used instead of this call being made ( bucketname is an arg here, instead of using bucketName() )
public CouchbaseClientFactory myCouchbaseClientFactory(String connectionString, Authenticator authenticator, String bucketName) {
return new SimpleCouchbaseClientFactory(connectionString, authenticator, bucketName);
}
The resulting couchbaseClient factory is in turn would be used to create a template.
// do not use couchbaseTemplate for the name of this method, otherwise the value of that been
// will be used instead of the result from this call (the client factory arg is different)
public CouchbaseTemplate myCouchbaseTemplate(CouchbaseClientFactory couchbaseClientFactory,
MappingCouchbaseConverter mappingCouchbaseConverter) {
return new CouchbaseTemplate(couchbaseClientFactory, mappingCouchbaseConverter, new JacksonTranslationService(),
getDefaultConsistency());
}
authenticator = PasswordAuthenticator.create("user1", "password1");
templateForUser = myCouchbaseTemplate( myCouchbaseClientFactory(connectionString, authenticator, bucketName), mappingCouchbaseConverter /* <- this should be the bean */, new JacksonTranslationService(), getDefaultConsistency());
In the spring data collections presentation, I just say that if you are using different scopes, that the user must have access to all the scopes. (which kind of ruins the idea of using scopes for multi-user tenancy).
I don’t have a solution for repositories. Although there is a method configureRepositoryOperationsMapping(), it only allows mapping entity classes to templates (there is a commented-out example in org.springframework.data.couchbase.domain.Config). There is no means to map a user to a template. Although that would not take much to implement. What would be difficult is indicating which “user” to use for mapping, since the calls don’t have any indication of who the “user” is.