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
This commit is contained in:
commit
9b73d6567e
|
|
@ -57,7 +57,13 @@ public class CouchbaseConfiguration {
|
||||||
@Bean
|
@Bean
|
||||||
@Primary
|
@Primary
|
||||||
public Cluster couchbaseCluster() {
|
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
|
@Bean
|
||||||
@Primary
|
@Primary
|
||||||
public Bucket couchbaseClient() {
|
public Bucket couchbaseClient() {
|
||||||
|
if (isRoleBasedAccessControlEnabled()) {
|
||||||
|
return couchbaseCluster().openBucket(this.properties.getBucket().getName());
|
||||||
|
}
|
||||||
return couchbaseCluster().openBucket(this.properties.getBucket().getName(),
|
return couchbaseCluster().openBucket(this.properties.getBucket().getName(),
|
||||||
this.properties.getBucket().getPassword());
|
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.
|
* Initialize an environment builder based on the specified settings.
|
||||||
* @param properties the couchbase properties to use
|
* @param properties the couchbase properties to use
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* 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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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;
|
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 Bucket bucket = new Bucket();
|
||||||
|
|
||||||
private final Env env = new Env();
|
private final Env env = new Env();
|
||||||
|
|
@ -50,6 +60,22 @@ public class CouchbaseProperties {
|
||||||
this.bootstrapHosts = bootstrapHosts;
|
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() {
|
public Bucket getBucket() {
|
||||||
return this.bucket;
|
return this.bucket;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue