Skip to content
Permalink
Browse files

oxCouchbase should use SSL trust cert to check server authority #78

  • Loading branch information...
yurem committed May 8, 2019
1 parent 70d574f commit c3aacd3c09b611a3807a2e4effabad56fac37cc5
@@ -7,18 +7,27 @@

package org.gluu.persist.couchbase.impl;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

import javax.annotation.PostConstruct;
import javax.enterprise.context.ApplicationScoped;

import org.apache.commons.io.IOUtils;
import org.gluu.persist.PersistenceEntryManagerFactory;
import org.gluu.persist.couchbase.operation.impl.CouchbaseConnectionProvider;
import org.gluu.persist.couchbase.operation.impl.CouchbaseOperationsServiceImpl;
import org.gluu.persist.exception.operation.ConfigurationException;
import org.gluu.util.FileUtil;
import org.gluu.util.init.Initializable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.couchbase.client.java.Bucket;
import com.couchbase.client.java.CouchbaseCluster;
import com.couchbase.client.java.env.CouchbaseEnvironment;
import com.couchbase.client.java.env.DefaultCouchbaseEnvironment;

@@ -28,17 +37,36 @@
* @author Yuriy Movchan Date: 05/31/2018
*/
@ApplicationScoped
public class CouchbaseEntryManagerFactory implements PersistenceEntryManagerFactory {
public class CouchbaseEntryManagerFactory extends Initializable implements PersistenceEntryManagerFactory{

private static final Logger LOG = LoggerFactory.getLogger(CouchbaseEntryManagerFactory.class);

private DefaultCouchbaseEnvironment.Builder builder;
private CouchbaseEnvironment couchbaseEnvironment;

private Properties couchbaseConnectionProperties;

@PostConstruct
public void create() {
this.couchbaseEnvironment = DefaultCouchbaseEnvironment.create();
this.builder = DefaultCouchbaseEnvironment.builder().mutationTokensEnabled(true).computationPoolSize(5);
}

@Override
protected void initInternal() {
// SSL settings
boolean useSSL = Boolean.valueOf(couchbaseConnectionProperties.getProperty("ssl.trustStore.enable")).booleanValue();
if (useSSL) {
String sslTrustStoreFile = couchbaseConnectionProperties.getProperty("ssl.trustStore.file");
String sslTrustStorePin = couchbaseConnectionProperties.getProperty("ssl.trustStore.pin");

this.couchbaseEnvironment = builder.sslEnabled(true).sslTruststoreFile(sslTrustStoreFile).sslTruststorePassword(sslTrustStorePin).build();
} else {
this.couchbaseEnvironment = builder.sslEnabled(false).build();
}

this.builder = null;
}

@Override
public String getPersistenceType() {
return "couchbase";
@@ -55,7 +83,14 @@ public CouchbaseEnvironment getCouchbaseEnvironment() {

@Override
public CouchbaseEntryManager createEntryManager(Properties conf) {
CouchbaseConnectionProvider connectionProvider = new CouchbaseConnectionProvider(conf, couchbaseEnvironment);
this.couchbaseConnectionProperties = conf;
init();

if (!isInitialized()) {
throw new ConfigurationException("Failed to create Couchbase environment !");
}

CouchbaseConnectionProvider connectionProvider = new CouchbaseConnectionProvider(conf, couchbaseEnvironment);
connectionProvider.create();
if (!connectionProvider.isCreated()) {
throw new ConfigurationException(
@@ -68,5 +103,18 @@ public CouchbaseEntryManager createEntryManager(Properties conf) {

return couchbaseEntryManager;
}

/*
public static void main(String[] args) throws FileNotFoundException, IOException {
Properties prop = new Properties();
prop.load(new FileInputStream(new File("D:/Temp/gluu-couchbase.properties")));
CouchbaseEntryManagerFactory cemf = new CouchbaseEntryManagerFactory();
cemf.create();
CouchbaseEntryManager cem = cemf.createEntryManager(prop);
System.out.println(cem.getOperationService().getConnectionProvider().isCreated());
}
*/
}
@@ -22,6 +22,7 @@
import org.slf4j.LoggerFactory;

import com.couchbase.client.core.CouchbaseException;
import com.couchbase.client.core.RequestCancelledException;
import com.couchbase.client.java.Bucket;
import com.couchbase.client.java.CouchbaseCluster;
import com.couchbase.client.java.env.CouchbaseEnvironment;
@@ -79,6 +80,7 @@ public void create() {
}

LOG.error("Failed to create connection with properties: '{}'. Exception: {}", clonedProperties, ex);
ex.printStackTrace();
}
}

@@ -298,17 +300,5 @@ public boolean isCertificateAttribute(String attributeName) {
public PasswordEncryptionMethod getPasswordEncryptionMethod() {
return passwordEncryptionMethod;
}

public static void main(String[] args) {
com.couchbase.client.java.env.DefaultCouchbaseEnvironment.Builder builder = com.couchbase.client.java.env.DefaultCouchbaseEnvironment.builder().bootstrapHttpDirectPort(38091);

com.couchbase.client.java.env.DefaultCouchbaseEnvironment couchbaseEnvironment = builder.build();
CouchbaseCluster cluster = CouchbaseCluster.create(couchbaseEnvironment, "u164.gluu.info");
cluster.authenticate("admin", "secret");

Bucket bucket = cluster.openBucket("gluu");
System.out.println(bucket.exists("_"));

}
}

0 comments on commit c3aacd3

Please sign in to comment.
You can’t perform that action at this time.