spring-projects / spring-projects/spring-data-couchbase
Need repository mapping based on user - especially for scopes
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 284
- Forks
- 197
- PR merge metrics
- No merged PRs in 30d
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the AbstractCouchbaseConfiguration implementations under src/test/java/**, especially org.springframework.data.couchbase.domain.Config, and inspect configureRepositoryOperationsMapping(). Clarify how a user should be identified and how scopes, templates, and repository operations should map; done requires an agreed design that supports the requested user-specific repository mapping.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- backend, databases
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100