Commit 9b73d656 authored by Stephane Nicoll's avatar Stephane Nicoll

Merge pull request #16389 from enesacikoglu

* pr/16389:
  Polish "Add support for Couchbase's role-based access"
  Add support for Couchbase's role-based access
parents f8eb230d 2949561b
......@@ -57,7 +57,13 @@ public class CouchbaseConfiguration {
@Bean
@Primary
public Cluster couchbaseCluster() {
return CouchbaseCluster.create(couchbaseEnvironment(), determineBootstrapHosts());
CouchbaseCluster couchbaseCluster = CouchbaseCluster
.create(couchbaseEnvironment(), determineBootstrapHosts());
if (isRoleBasedAccessControlEnabled()) {
return couchbaseCluster.authenticate(this.properties.getUsername(),
this.properties.getPassword());
}
return couchbaseCluster;
}
/**
......@@ -79,10 +85,18 @@ public class CouchbaseConfiguration {
@Bean
@Primary
public Bucket couchbaseClient() {
if (isRoleBasedAccessControlEnabled()) {
return couchbaseCluster().openBucket(this.properties.getBucket().getName());
}
return couchbaseCluster().openBucket(this.properties.getBucket().getName(),
this.properties.getBucket().getPassword());
}
private boolean isRoleBasedAccessControlEnabled() {
return this.properties.getUsername() != null
&& this.properties.getPassword() != null;
}
/**
* Initialize an environment builder based on the specified settings.
* @param properties the couchbase properties to use
......
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -38,6 +38,16 @@ public class CouchbaseProperties {
*/
private List<String> bootstrapHosts;
/**
* Cluster username when using role based access.
*/
private String username;
/**
* Cluster password when using role based access.
*/
private String password;
private final Bucket bucket = new Bucket();
private final Env env = new Env();
......@@ -50,6 +60,22 @@ public class CouchbaseProperties {
this.bootstrapHosts = bootstrapHosts;
}
public String getUsername() {
return this.username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return this.password;
}
public void setPassword(String password) {
this.password = password;
}
public Bucket getBucket() {
return this.bucket;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment