Skip to content

Add support for Couchbase's role based access #16389

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,14 @@ public DefaultCouchbaseEnvironment couchbaseEnvironment() {
@Bean
@Primary
public Cluster couchbaseCluster() {
return CouchbaseCluster.create(couchbaseEnvironment(), determineBootstrapHosts());
CouchbaseCluster couchbaseCluster = CouchbaseCluster
.create(couchbaseEnvironment(), determineBootstrapHosts());
if (this.properties.getUsername() != null
&& this.properties.getPassword() != null) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The username and password properties are initialized to empty string (""). Will they ever be null? A better check might be .isEmpty().

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opps how can ı miss 👎 Thanks for your awesome attention

return couchbaseCluster.authenticate(this.properties.getUsername(),
this.properties.getPassword());
}
return couchbaseCluster;
}

/**
Expand All @@ -79,6 +86,10 @@ public ClusterInfo couchbaseClusterInfo() {
@Bean
@Primary
public Bucket couchbaseClient() {
if (this.properties.getUsername() != null
&& this.properties.getPassword() != null) {
return couchbaseCluster().openBucket(this.properties.getBucket().getName());
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This condition should be inverted. If RBAC username or password are empty we should call the openBucket method that takes a bucket password.

Sorry if I missed this earlier.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This condition should be inverted. If RBAC username or password are empty we should call the openBucket method that takes a bucket password.

Sorry if I missed this earlier.

Thanks. I inverted it. 👍

}
return couchbaseCluster().openBucket(this.properties.getBucket().getName(),
this.properties.getBucket().getPassword());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.boot.autoconfigure.couchbase;

import java.time.Duration;
Expand Down Expand Up @@ -42,6 +41,16 @@ public class CouchbaseProperties {

private final Env env = new Env();

/**
* Password of the cluster on RBA(role base access).
*/
private String password = "";

/**
* Username of the cluster on RBA(role base access).
*/
private String username = "";

public List<String> getBootstrapHosts() {
return this.bootstrapHosts;
}
Expand All @@ -58,6 +67,22 @@ public Env getEnv() {
return this.env;
}

public String getPassword() {
return this.password;
}

public void setPassword(String password) {
this.password = password;
}

public String getUsername() {
return this.username;
}

public void setUsername(String username) {
this.username = username;
}

public static class Bucket {

/**
Expand Down