Hi i am newbie to Couchbase and created a Springboot application with Couchbase 6.0.
When i installed Couchbase, it asked me to create username and password and i set username="admin" and password="password" and then i created "student" bucket.
I have done all the requisite config in application.properties file.
spring.couchbase.bootstrap-hosts=127.0.0.1
spring.couchbase.bucket.name=student
spring.couchbase.bucket.password=password
On server start, i am getting following error
Caused by: com.couchbase.client.java.error.InvalidPasswordException: null
Couchbase web console, there is a Security tab, I added, username "admin" (which i created during Couchbase server installation) over there and given full admin access
On server restart again, I have faced same issue
then i added one more user "student" (same as my bucket name) over there and given full admin access
this time my server started successfully and i did not get any exception
So i have two questions here,
1: Do i need to create as many as username as i have buckets in my Couchbase server in security tab ?.
2: Let say i want to use username "admin" only (which i created during Couchbase server installation), how would i achieve this ?.
Can someone throw some light on this behaviour ?
Pre couchbase 4.5, buckets had passwords, where if you need to access a bucket you'll have to supply the bucket name and its password. After 4.5 they implemented rbac (Role-Based Access Control) and dropped bucket-level passwords.
So for people that upgraded their couchbase but don't want to change their code or make a new release, a work-around was suggested, create a username per bucket, where the username is the bucket name and the password is the same for all users, that way spring-data-couchbase
still authenticates successfully when ran.
Now rbac is added to couchbase-java-client
& spring-data-couchbase
(considering you're using latest version, not sure at which specific version they added it), so if you want to use a single username to connect to all your buckets you will need a class that extends AbstractCouchbaseConfiguration
and then
@Override
protected String getUsername() {
return "admin";
}
And supply the password via the old bucketPassword()
method.
I don't think you can do it through application.properties
yet because the org.springframework.boot.autoconfigure
dependency is still not updated to accommodate for the latest spring-data-couchbase
changes.
Also a note, the username that you've created through the security tab have nothing to do with the user that you created through the installation wizard. The user you've created through the initial installation is a master user, can't be removed, you won't see it under the security tab and it have full admin privileges. You still can define a username with same name through the security tab (I just learned that) but then you'll have 2 accounts, same user, different pass (or maybe same pass even but I'm not even sure how it's handled by couchbase, I mean if we have 2 accounts called 'Administrator' with the same password and then a login happens on web console, which user is considered? Maybe someone can tell us.)
I got an alternative for this by overriding couchbaseClusterInfo() method in config class.
@Override
@Bean(name = BeanNames.COUCHBASE_CLUSTER_INFO)
public ClusterInfo couchbaseClusterInfo() throws Exception {
return couchbaseCluster().authenticate("admin","password").clusterManager().info();
}
this is working fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With