Search in sources :

Example 21 with NoSQLConnection

use of org.talend.repository.model.nosql.NoSQLConnection in project tbd-studio-se by Talend.

the class CassandraConnForm method collectNoSqlAttributesForContext.

/*
     * (non-Javadoc)
     *
     * @see org.talend.repository.nosql.ui.common.AbstractNoSQLConnForm#collectAttributesForContext()
     */
@Override
protected void collectNoSqlAttributesForContext() {
    NoSQLConnection conn = getConnection();
    conn.getAttributes().put(INoSQLCommonAttributes.HOST, serverText.getText());
    conn.getAttributes().put(INoSQLCommonAttributes.PORT, portText.getText());
    conn.getAttributes().put(INoSQLCommonAttributes.DATABASE, databaseText.getText());
    if (checkRequireAuthBtn.getSelection()) {
        conn.getAttributes().put(INoSQLCommonAttributes.USERNAME, userText.getText());
        conn.getAttributes().put(INoSQLCommonAttributes.PASSWORD, pwdText.getText());
    }
}
Also used : NoSQLConnection(org.talend.repository.model.nosql.NoSQLConnection)

Example 22 with NoSQLConnection

use of org.talend.repository.model.nosql.NoSQLConnection in project tbd-studio-se by Talend.

the class MongoDBConnForm method saveAttributes.

@Override
protected void saveAttributes() {
    super.saveAttributes();
    NoSQLConnection conn = getConnection();
    conn.getAttributes().put(INoSQLCommonAttributes.DB_VERSION, repositoryTranslator.getValue(dbVersionCombo.getText()));
    conn.getAttributes().put(INoSQLCommonAttributes.HOST, serverText.getText());
    conn.getAttributes().put(INoSQLCommonAttributes.PORT, portText.getText());
    conn.getAttributes().put(INoSQLCommonAttributes.DATABASE, databaseText.getText());
    conn.getAttributes().put(IMongoDBAttributes.USE_CONN_STRING, String.valueOf(checkUseConnStringBtn.getSelection()));
    conn.getAttributes().put(IMongoDBAttributes.CONN_STRING, connStringText.getText());
    conn.getAttributes().put(INoSQLCommonAttributes.REQUIRED_AUTHENTICATION, String.valueOf(checkRequireAuthBtn.getSelection()));
    conn.getAttributes().put(INoSQLCommonAttributes.USERNAME, userText.getText());
    conn.getAttributes().put(INoSQLCommonAttributes.PASSWORD, conn.getValue(pwdText.getText(), true));
    conn.getAttributes().put(IMongoDBAttributes.REQUIRED_ENCRYPTION, String.valueOf(checkRequireEncryptionBtn.getSelection()));
    conn.getAttributes().put(IMongoDBAttributes.USE_REPLICA_SET, String.valueOf(checkUseReplicaBtn.getSelection()));
    conn.getAttributes().put(IMongoDBAttributes.AUTHENTICATION_MECHANISM, getAuthMechanismValue(authMechanismCombo.getText()));
    conn.getAttributes().put(IMongoDBAttributes.SET_AUTHENTICATION_DATABASE, String.valueOf(checkSetAuthDatabaseBtn.getSelection()));
    conn.getAttributes().put(IMongoDBAttributes.AUTHENTICATION_DATABASE, authDatabaseText.getText());
    conn.getAttributes().put(IMongoDBAttributes.KRB_USER_PRINCIPAL, authKrbUserPrincipalText.getText());
    conn.getAttributes().put(IMongoDBAttributes.KRB_REALM, authKrbRealmText.getText());
    conn.getAttributes().put(IMongoDBAttributes.KRB_KDC, authKrbKdcText.getText());
    conn.getAttributes().put(IMongoDBAttributes.X509_CERT, certificateField.getText());
    conn.getAttributes().put(IMongoDBAttributes.X509_CERT_KEYSTORE_PASSWORD, conn.getValue(keyStorePassText.getText(), true));
    conn.getAttributes().put(IMongoDBAttributes.X509_USE_CERT_AUTH, String.valueOf(checkUseCertAuthBtn.getSelection()));
    conn.getAttributes().put(IMongoDBAttributes.X509_CERT_AUTH, authCertificateField.getText());
    conn.getAttributes().put(IMongoDBAttributes.X509_CERT_AUTH_TRUSTSTORE_PASSWORD, conn.getValue(trustStorePassText.getText(), true));
    saveReplicaModel();
}
Also used : NoSQLConnection(org.talend.repository.model.nosql.NoSQLConnection)

Example 23 with NoSQLConnection

use of org.talend.repository.model.nosql.NoSQLConnection in project tbd-studio-se by Talend.

the class MongoDBConnectionUtilTest method testIsUpgradeVersion.

@Test
public void testIsUpgradeVersion() {
    NoSQLConnection connection = NosqlFactory.eINSTANCE.createNoSQLConnection();
    connection.getAttributes().put(INoSQLCommonAttributes.DB_VERSION, VersionUtils.DEFAULT_VERSION);
    Assert.assertFalse(MongoDBConnectionUtil.isUpgradeVersion(connection));
    connection.getAttributes().put(INoSQLCommonAttributes.DB_VERSION, "MONGODB_2_5_X");
    Assert.assertFalse(MongoDBConnectionUtil.isUpgradeVersion(connection));
    connection.getAttributes().put(INoSQLCommonAttributes.DB_VERSION, "MONGODB_2_6_X");
    Assert.assertFalse(MongoDBConnectionUtil.isUpgradeVersion(connection));
    connection.getAttributes().put(INoSQLCommonAttributes.DB_VERSION, "MONGODB_3_2_X");
    Assert.assertFalse(MongoDBConnectionUtil.isUpgradeVersion(connection));
    connection.getAttributes().put(INoSQLCommonAttributes.DB_VERSION, "MONGODB_3_5_X");
    Assert.assertTrue(MongoDBConnectionUtil.isUpgradeVersion(connection));
    connection.getAttributes().put(INoSQLCommonAttributes.DB_VERSION, "MONGODB_4_5_X");
    Assert.assertTrue(MongoDBConnectionUtil.isUpgradeVersion(connection));
}
Also used : NoSQLConnection(org.talend.repository.model.nosql.NoSQLConnection) Test(org.junit.Test)

Example 24 with NoSQLConnection

use of org.talend.repository.model.nosql.NoSQLConnection in project tbd-studio-se by Talend.

the class MongoDBConnectionUtil method getMongo4ConnStringVersion.

public static synchronized Object getMongo4ConnStringVersion(NoSQLConnection connection, ContextType contextType, ClassLoader classLoader, boolean requireAuth, boolean requireEncryption) throws NoSQLServerException {
    Object mongo = null;
    String user = connection.getAttributes().get(IMongoDBAttributes.USERNAME);
    String pass = connection.getAttributes().get(IMongoDBAttributes.PASSWORD);
    if (contextType != null) {
        user = ContextParameterUtils.getOriginalValue(contextType, user);
        pass = ContextParameterUtils.getOriginalValue(contextType, pass);
    } else {
        pass = connection.getValue(pass, false);
    }
    try {
        String connString = extractFromContext(connection, IMongoDBAttributes.CONN_STRING);
        Object clientSettingsBuilder = // $NON-NLS-1$ //$NON-NLS-2$
        NoSQLReflection.invokeStaticMethod(// $NON-NLS-1$ //$NON-NLS-2$
        "com.mongodb.MongoClientSettings", // $NON-NLS-1$ //$NON-NLS-2$
        "builder", new Object[0], classLoader);
        Object connectionString = NoSQLReflection.newInstance("com.mongodb.ConnectionString", new Object[] { connString }, classLoader, String.class);
        clientSettingsBuilder = NoSQLReflection.invokeMethod(clientSettingsBuilder, "applyConnectionString", new Object[] { connectionString }, connectionString.getClass());
        Object mongoCredential = getCredential(connection, contextType, user, pass, classLoader);
        clientSettingsBuilder = NoSQLReflection.invokeMethod(clientSettingsBuilder, "credential", new Object[] { mongoCredential }, Class.forName("com.mongodb.MongoCredential", true, classLoader));
        String authMechanism = connection.getAttributes().get(IMongoDBAttributes.AUTHENTICATION_MECHANISM);
        // 
        if ((requireAuth && authMechanism.equals(IMongoConstants.X509)) || requireEncryption) {
            // enable ssl & context
            // $NON-NLS-1$
            Class<?> blockClasszz = Class.forName("com.mongodb.Block", false, classLoader);
            Class[] interfaces = new Class[1];
            interfaces[0] = blockClasszz;
            Object block = Proxy.newProxyInstance(classLoader, interfaces, (proxy, method, args) -> {
                switch(method.getName()) {
                    case // $NON-NLS-1$
                    "apply":
                        if (args[0] != null) {
                            SSLContext sslContext = null;
                            if (requireAuth && authMechanism.equals(IMongoConstants.X509)) {
                                sslContext = mongoX509SSLContext(connection);
                            } else if (requireEncryption) {
                                sslContext = StudioSSLContextProvider.getContext();
                            }
                            // $NON-NLS-1$
                            NoSQLReflection.invokeMethod(// $NON-NLS-1$
                            args[0], // $NON-NLS-1$
                            "context", // $NON-NLS-1$
                            new Object[] { sslContext }, // $NON-NLS-1$
                            SSLContext.class);
                        }
                        return null;
                    default:
                        throw new NoSQLServerException(// $NON-NLS-1$
                        Messages.getString("MongoDBConnectionUtil.CannotFindMethod", method.getName()));
                }
            });
            clientSettingsBuilder = NoSQLReflection.invokeMethod(clientSettingsBuilder, "applyToSslSettings", new Object[] { block }, blockClasszz);
            // $NON-NLS-1$
            blockClasszz = Class.forName("com.mongodb.Block", false, classLoader);
            interfaces = new Class[1];
            interfaces[0] = blockClasszz;
            block = Proxy.newProxyInstance(classLoader, interfaces, (proxy, method, args) -> {
                switch(method.getName()) {
                    case // $NON-NLS-1$
                    "apply":
                        if (args[0] != null) {
                            // $NON-NLS-1$
                            NoSQLReflection.invokeMethod(// $NON-NLS-1$
                            args[0], // $NON-NLS-1$
                            "enabled", // $NON-NLS-1$
                            new Object[] { true }, boolean.class);
                        }
                        return null;
                    default:
                        throw new Exception(// $NON-NLS-1$
                        "MongoDBConnectionUtil.CannotFindMethod" + method.getName());
                }
            });
            clientSettingsBuilder = NoSQLReflection.invokeMethod(clientSettingsBuilder, "applyToSslSettings", new Object[] { block }, blockClasszz);
        }
        Object mongoClientSettings = NoSQLReflection.invokeMethod(clientSettingsBuilder, "build", new Object[0]);
        mongo = // $NON-NLS-1$ //$NON-NLS-2$
        NoSQLReflection.invokeStaticMethod(// $NON-NLS-1$ //$NON-NLS-2$
        "com.mongodb.client.MongoClients", // $NON-NLS-1$ //$NON-NLS-2$
        "create", new Object[] { mongoClientSettings }, classLoader, // $NON-NLS-1$
        Class.forName("com.mongodb.MongoClientSettings", true, classLoader));
        mongos.add(mongo);
    } catch (Exception e) {
        throw new NoSQLServerException(e);
    }
    return mongo;
}
Also used : X509Certificate(java.security.cert.X509Certificate) SSLContext(javax.net.ssl.SSLContext) StringUtils(org.apache.commons.lang.StringUtils) ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) CertificateFactory(java.security.cert.CertificateFactory) JSONObject(org.talend.utils.json.JSONObject) NoSQLClassLoaderFactory(org.talend.repository.nosql.factory.NoSQLClassLoaderFactory) TalendQuoteUtils(org.talend.core.utils.TalendQuoteUtils) SecureRandom(java.security.SecureRandom) Matcher(java.util.regex.Matcher) ByteArrayInputStream(java.io.ByteArrayInputStream) NoSQLReflectionException(org.talend.repository.nosql.exceptions.NoSQLReflectionException) Map(java.util.Map) IMongoConstants(org.talend.repository.nosql.db.common.mongodb.IMongoConstants) NoSQLReflection(org.talend.repository.nosql.reflection.NoSQLReflection) ASN1Object(org.bouncycastle.asn1.ASN1Object) ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) TrustManagerFactory(javax.net.ssl.TrustManagerFactory) ContextParameterUtils(org.talend.core.model.utils.ContextParameterUtils) Set(java.util.Set) KeyStore(java.security.KeyStore) NoSQLConnection(org.talend.repository.model.nosql.NoSQLConnection) KeyFactory(java.security.KeyFactory) Base64(java.util.Base64) List(java.util.List) Certificate(java.security.cert.Certificate) RSAPrivateKeyStructure(org.bouncycastle.asn1.pkcs.RSAPrivateKeyStructure) ConnectionContextHelper(org.talend.metadata.managment.ui.utils.ConnectionContextHelper) PrivateKey(java.security.PrivateKey) PluginUtil(org.talend.core.ui.utils.PluginUtil) Pattern(java.util.regex.Pattern) INoSQLCommonAttributes(org.talend.repository.nosql.constants.INoSQLCommonAttributes) Proxy(java.lang.reflect.Proxy) StudioEncryption(org.talend.utils.security.StudioEncryption) HashMap(java.util.HashMap) NoSQLServerException(org.talend.repository.nosql.exceptions.NoSQLServerException) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) StudioSSLContextProvider(org.talend.core.utils.StudioSSLContextProvider) ExceptionHandler(org.talend.commons.exception.ExceptionHandler) JSONArray(org.talend.utils.json.JSONArray) JSONException(org.talend.utils.json.JSONException) Properties(java.util.Properties) CoreRuntimePlugin(org.talend.core.runtime.CoreRuntimePlugin) PKCS8EncodedKeySpec(java.security.spec.PKCS8EncodedKeySpec) Iterator(java.util.Iterator) Files(java.nio.file.Files) KeyManagerFactory(javax.net.ssl.KeyManagerFactory) Messages(org.talend.repository.nosql.i18n.Messages) FileInputStream(java.io.FileInputStream) File(java.io.File) KeyManager(javax.net.ssl.KeyManager) RSAPrivateKeySpec(java.security.spec.RSAPrivateKeySpec) Paths(java.nio.file.Paths) IMongoDBAttributes(org.talend.repository.nosql.db.common.mongodb.IMongoDBAttributes) SSLPreferenceConstants(org.talend.core.prefs.SSLPreferenceConstants) Collections(java.util.Collections) InputStream(java.io.InputStream) NoSQLServerException(org.talend.repository.nosql.exceptions.NoSQLServerException) JSONObject(org.talend.utils.json.JSONObject) ASN1Object(org.bouncycastle.asn1.ASN1Object) SSLContext(javax.net.ssl.SSLContext) NoSQLReflectionException(org.talend.repository.nosql.exceptions.NoSQLReflectionException) NoSQLServerException(org.talend.repository.nosql.exceptions.NoSQLServerException) JSONException(org.talend.utils.json.JSONException)

Example 25 with NoSQLConnection

use of org.talend.repository.model.nosql.NoSQLConnection in project tbd-studio-se by Talend.

the class NoSQLRepositoryTypeProcessor method selectRepositoryNode.

/*
     * (non-Javadoc)
     *
     * @see
     * org.talend.repository.ui.processor.SingleTypeProcessor#selectRepositoryNode(org.eclipse.jface.viewers.Viewer,
     * org.talend.repository.model.RepositoryNode, org.talend.repository.model.RepositoryNode)
     */
@Override
protected boolean selectRepositoryNode(Viewer viewer, RepositoryNode parentNode, RepositoryNode node) {
    final String repositoryType = getRepositoryType();
    if (node == null || repositoryType == null) {
        return false;
    }
    ERepositoryObjectType repObjType = (ERepositoryObjectType) node.getProperties(EProperties.CONTENT_TYPE);
    if (repObjType == ERepositoryObjectType.REFERENCED_PROJECTS) {
        return true;
    }
    if (node.getType() == ENodeType.SYSTEM_FOLDER) {
        return true;
    }
    IRepositoryViewObject object = node.getObject();
    if (object == null || object.getProperty().getItem() == null) {
        return false;
    }
    if (object instanceof MetadataTable) {
        return false;
    }
    Item item = object.getProperty().getItem();
    if (item instanceof FolderItem) {
        return true;
    }
    if (item instanceof NoSQLConnectionItem) {
        NoSQLConnectionItem connectionItem = (NoSQLConnectionItem) item;
        NoSQLConnection connection = (NoSQLConnection) connectionItem.getConnection();
        if (repositoryType.startsWith(INoSQLConstants.NOSQL_TYPE_PREFIX)) {
            // $NON-NLS-1$
            String realDbType = repositoryType.substring(repositoryType.indexOf(":") + 1);
            if (!StringUtils.equalsIgnoreCase(realDbType, connection.getDbType())) {
                return false;
            }
        }
    }
    return true;
}
Also used : Item(org.talend.core.model.properties.Item) FolderItem(org.talend.core.model.properties.FolderItem) NoSQLConnectionItem(org.talend.repository.model.nosql.NoSQLConnectionItem) FolderItem(org.talend.core.model.properties.FolderItem) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) MetadataTable(org.talend.core.model.metadata.MetadataTable) NoSQLConnection(org.talend.repository.model.nosql.NoSQLConnection) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) NoSQLConnectionItem(org.talend.repository.model.nosql.NoSQLConnectionItem)

Aggregations

NoSQLConnection (org.talend.repository.model.nosql.NoSQLConnection)30 NoSQLConnectionItem (org.talend.repository.model.nosql.NoSQLConnectionItem)7 ArrayList (java.util.ArrayList)5 Map (java.util.Map)4 MetadataTable (org.talend.core.model.metadata.builder.connection.MetadataTable)4 EHadoopParamName (org.talend.metadata.managment.ui.utils.ExtendedNodeConnectionContextUtils.EHadoopParamName)4 JSONArray (org.talend.utils.json.JSONArray)4 JSONException (org.talend.utils.json.JSONException)4 JSONObject (org.talend.utils.json.JSONObject)4 ModifyEvent (org.eclipse.swt.events.ModifyEvent)3 ModifyListener (org.eclipse.swt.events.ModifyListener)3 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 IConnParamName (org.talend.metadata.managment.ui.model.IConnParamName)3 AbstractForm (org.talend.metadata.managment.ui.wizard.AbstractForm)3 HashMap (java.util.HashMap)2 List (java.util.List)2 Connection (org.talend.core.model.metadata.builder.connection.Connection)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1