Skip to content

Commit 3386856

Browse files
Enes Açıkoğlusnicoll
authored andcommitted
Add support for Couchbase's role-based access
See gh-16389
1 parent f8eb230 commit 3386856

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/couchbase/CouchbaseConfiguration.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,14 @@ public DefaultCouchbaseEnvironment couchbaseEnvironment() {
5757
@Bean
5858
@Primary
5959
public Cluster couchbaseCluster() {
60-
return CouchbaseCluster.create(couchbaseEnvironment(), determineBootstrapHosts());
60+
CouchbaseCluster couchbaseCluster = CouchbaseCluster
61+
.create(couchbaseEnvironment(), determineBootstrapHosts());
62+
if (this.properties.getUsername().isEmpty()
63+
|| this.properties.getPassword().isEmpty()) {
64+
return couchbaseCluster;
65+
}
66+
return couchbaseCluster.authenticate(this.properties.getUsername(),
67+
this.properties.getPassword());
6168
}
6269

6370
/**
@@ -79,8 +86,12 @@ public ClusterInfo couchbaseClusterInfo() {
7986
@Bean
8087
@Primary
8188
public Bucket couchbaseClient() {
82-
return couchbaseCluster().openBucket(this.properties.getBucket().getName(),
83-
this.properties.getBucket().getPassword());
89+
if (this.properties.getUsername().isEmpty()
90+
|| this.properties.getPassword().isEmpty()) {
91+
return couchbaseCluster().openBucket(this.properties.getBucket().getName(),
92+
this.properties.getBucket().getPassword());
93+
}
94+
return couchbaseCluster().openBucket(this.properties.getBucket().getName());
8495
}
8596

8697
/**

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/couchbase/CouchbaseProperties.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
1716
package org.springframework.boot.autoconfigure.couchbase;
1817

1918
import java.time.Duration;
@@ -42,6 +41,16 @@ public class CouchbaseProperties {
4241

4342
private final Env env = new Env();
4443

44+
/**
45+
* Password of the cluster on RBA(role base access).
46+
*/
47+
private String password = "";
48+
49+
/**
50+
* Username of the cluster on RBA(role base access).
51+
*/
52+
private String username = "";
53+
4554
public List<String> getBootstrapHosts() {
4655
return this.bootstrapHosts;
4756
}
@@ -58,6 +67,22 @@ public Env getEnv() {
5867
return this.env;
5968
}
6069

70+
public String getPassword() {
71+
return this.password;
72+
}
73+
74+
public void setPassword(String password) {
75+
this.password = password;
76+
}
77+
78+
public String getUsername() {
79+
return this.username;
80+
}
81+
82+
public void setUsername(String username) {
83+
this.username = username;
84+
}
85+
6186
public static class Bucket {
6287

6388
/**

0 commit comments

Comments
 (0)