com.couchbase.client.java.auth.CertAuthenticator Java Examples

The following examples show how to use com.couchbase.client.java.auth.CertAuthenticator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CouchbaseWriter.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
public CouchbaseWriter(CouchbaseEnvironment couchbaseEnvironment, Config config) {

    List<String> hosts = ConfigUtils.getStringList(config, CouchbaseWriterConfigurationKeys.BOOTSTRAP_SERVERS);
    boolean usesCertAuth = ConfigUtils.getBoolean(config, CouchbaseWriterConfigurationKeys.CERT_AUTH_ENABLED, false);
    String password = ConfigUtils.getString(config, CouchbaseWriterConfigurationKeys.PASSWORD, "");

    log.info("Using hosts hosts: {}", hosts.stream().collect(Collectors.joining(",")));

    _documentTTL = ConfigUtils.getInt(config, CouchbaseWriterConfigurationKeys.DOCUMENT_TTL, 0);
    _documentTTLTimeUnits =
        ConfigUtils.getTimeUnit(config, CouchbaseWriterConfigurationKeys.DOCUMENT_TTL_UNIT, CouchbaseWriterConfigurationKeys.DOCUMENT_TTL_UNIT_DEFAULT);
    _documentTTLOriginField =
        ConfigUtils.getString(config, CouchbaseWriterConfigurationKeys.DOCUMENT_TTL_ORIGIN_FIELD, null);
    _documentTTLOriginUnits =
        ConfigUtils.getTimeUnit(config, CouchbaseWriterConfigurationKeys.DOCUMENT_TTL_ORIGIN_FIELD_UNITS,
            CouchbaseWriterConfigurationKeys.DOCUMENT_TTL_ORIGIN_FIELD_UNITS_DEFAULT);

    String bucketName = ConfigUtils.getString(config, CouchbaseWriterConfigurationKeys.BUCKET,
        CouchbaseWriterConfigurationKeys.BUCKET_DEFAULT);

    _cluster = CouchbaseCluster.create(couchbaseEnvironment, hosts);

    if (usesCertAuth) {
      _cluster.authenticate(CertAuthenticator.INSTANCE);
      _bucket = _cluster.openBucket(bucketName, Collections.singletonList(_tupleDocumentTranscoder));
    } else if (password.isEmpty()) {
      _bucket = _cluster.openBucket(bucketName, Collections.singletonList(_tupleDocumentTranscoder));
    } else {
      _bucket = _cluster.openBucket(bucketName, password, Collections.singletonList(_tupleDocumentTranscoder));
    }
    _operationTimeout = ConfigUtils.getLong(config, CouchbaseWriterConfigurationKeys.OPERATION_TIMEOUT_MILLIS,
        CouchbaseWriterConfigurationKeys.OPERATION_TIMEOUT_DEFAULT);
    _operationTimeunit = TimeUnit.MILLISECONDS;

    _defaultWriteResponseMapper = new GenericWriteResponseWrapper<>();

    log.info("Couchbase writer configured with: hosts: {}, bucketName: {}, operationTimeoutInMillis: {}", hosts,
        bucketName, _operationTimeout);
  }
 
Example #2
Source File: CouchbaseCacheDAO.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize connection to Couchbase and open bucket where data is stored.
 */
private void createDataStoreConnection() {
  CacheDataSource dataSource = CacheConfig.getInstance().getCentralizedCacheSettings().getDataSourceConfig();
  Map<String, Object> config = dataSource.getConfig();
  List<String> hosts = ConfigUtils.getList(config.get(HOSTS));

  Cluster cluster;
  if (MapUtils.getBoolean(config, USE_CERT_BASED_AUTH)) {
    CouchbaseEnvironment env = DefaultCouchbaseEnvironment
        .builder()
        .sslEnabled(true)
        .certAuthEnabled(true)
        .dnsSrvEnabled(MapUtils.getBoolean(config, ENABLE_DNS_SRV))
        .sslKeystoreFile(MapUtils.getString(config, KEY_STORE_FILE_PATH))
        .sslKeystorePassword(MapUtils.getString(config, KEY_STORE_PASSWORD))
        .sslTruststoreFile(MapUtils.getString(config, TRUST_STORE_FILE_PATH))
        .sslTruststorePassword(MapUtils.getString(config, TRUST_STORE_PASSWORD))
        .build();

    cluster = CouchbaseCluster.create(env, CacheUtils.getBootstrapHosts(hosts));
    cluster.authenticate(CertAuthenticator.INSTANCE);
  } else {
    cluster = CouchbaseCluster.create(hosts);
    cluster.authenticate(MapUtils.getString(config, AUTH_USERNAME), MapUtils.getString(config, AUTH_PASSWORD));
  }

  this.bucket = cluster.openBucket(CacheUtils.getBucketName());
}
 
Example #3
Source File: CouchbaseBucketRegistry.java    From samza with Apache License 2.0 4 votes vote down vote up
/**
 * Helper method to open a cluster given cluster nodes and environment configurations.
 */
private Cluster openCluster(List<String> clusterNodes, CouchbaseEnvironmentConfigs configs) {
  DefaultCouchbaseEnvironment.Builder envBuilder = new DefaultCouchbaseEnvironment.Builder();
  if (configs.sslEnabled != null) {
    envBuilder.sslEnabled(configs.sslEnabled);
  }
  if (configs.certAuthEnabled != null) {
    envBuilder.certAuthEnabled(configs.certAuthEnabled);
  }
  if (configs.sslKeystoreFile != null) {
    envBuilder.sslKeystoreFile(configs.sslKeystoreFile);
  }
  if (configs.sslKeystorePassword != null) {
    envBuilder.sslKeystorePassword(configs.sslKeystorePassword);
  }
  if (configs.sslTruststoreFile != null) {
    envBuilder.sslTruststoreFile(configs.sslTruststoreFile);
  }
  if (configs.sslTruststorePassword != null) {
    envBuilder.sslTruststorePassword(configs.sslTruststorePassword);
  }
  if (configs.bootstrapCarrierDirectPort != null) {
    envBuilder.bootstrapCarrierDirectPort(configs.bootstrapCarrierDirectPort);
  }
  if (configs.bootstrapCarrierSslPort != null) {
    envBuilder.bootstrapCarrierSslPort(configs.bootstrapCarrierSslPort);
  }
  if (configs.bootstrapHttpDirectPort != null) {
    envBuilder.bootstrapHttpDirectPort(configs.bootstrapHttpDirectPort);
  }
  if (configs.bootstrapHttpSslPort != null) {
    envBuilder.bootstrapHttpSslPort(configs.bootstrapHttpSslPort);
  }
  CouchbaseEnvironment env = envBuilder.build();
  Cluster cluster = CouchbaseCluster.create(env, clusterNodes);
  if (configs.sslEnabled != null && configs.sslEnabled) {
    cluster.authenticate(CertAuthenticator.INSTANCE);
  } else if (configs.username != null) {
    cluster.authenticate(configs.username, configs.password);
  } else {
    LOGGER.warn("No authentication is enabled for cluster: {}. This is not recommended except for test cases.",
        clusterNodes);
  }
  return cluster;
}