use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tbd-studio-se by Talend.
the class GoogleDataprocInfoForm method initCommonProperties.
private void initCommonProperties(HadoopServiceProperties properties) {
HadoopClusterConnection connection = getConnection();
ContextType contextType = null;
if (getConnection().isContextMode()) {
contextType = ConnectionContextHelper.getContextTypeForContextMode(connection, connection.getContextName(), false);
}
properties.setContextType(contextType);
properties.setRelativeHadoopClusterId(connectionItem.getProperty().getId());
properties.setRelativeHadoopClusterLabel(connectionItem.getProperty().getLabel());
properties.setDistribution(connection.getDistribution());
properties.setVersion(connection.getDfVersion());
properties.setUseKrb(connection.isEnableKerberos());
}
use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tbd-studio-se by Talend.
the class KnoxInfoForm method initCommonProperties.
private void initCommonProperties(HadoopServiceProperties properties) {
HadoopClusterConnection connection = getConnection();
ContextType contextType = null;
if (getConnection().isContextMode()) {
contextType = ConnectionContextHelper.getContextTypeForContextMode(connection, connection.getContextName(), false);
}
properties.setContextType(contextType);
properties.setRelativeHadoopClusterId(connectionItem.getProperty().getId());
properties.setRelativeHadoopClusterLabel(connectionItem.getProperty().getLabel());
properties.setDistribution(connection.getDistribution());
properties.setVersion(connection.getDfVersion());
properties.setUseKrb(connection.isEnableKerberos());
}
use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tbd-studio-se by Talend.
the class MongoDBConnectionUtil method extractFromContext.
private static String extractFromContext(NoSQLConnection connection, String attr) {
String attrVal = connection.getAttributes().get(attr);
if (connection.isContextMode()) {
ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(connection);
attrVal = ContextParameterUtils.getOriginalValue(contextType, attrVal);
}
return attrVal;
}
use of org.talend.designer.core.model.utils.emf.talendfile.ContextType 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;
}
use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tbd-studio-se by Talend.
the class MongoDBConnectionUtil method getDB.
public static synchronized Object getDB(NoSQLConnection connection, String dbName, Object mongoClient) throws NoSQLServerException {
Object db = null;
if (StringUtils.isEmpty(dbName)) {
return db;
}
try {
String requireAuthAttr = connection.getAttributes().get(IMongoDBAttributes.REQUIRED_AUTHENTICATION);
boolean requireAuth = requireAuthAttr == null ? false : Boolean.valueOf(requireAuthAttr);
//
String requireEncryptionAttr = connection.getAttributes().get(IMongoDBAttributes.REQUIRED_ENCRYPTION);
boolean requireEncryption = requireEncryptionAttr == null ? false : Boolean.valueOf(requireEncryptionAttr);
updateConfigProperties(requireEncryption);
if (isUpgradeLatestVersion(connection)) {
if (mongoClient == null) {
mongoClient = getMongo(connection, requireAuth, requireEncryption);
}
db = // $NON-NLS-1$
NoSQLReflection.invokeMethod(// $NON-NLS-1$
mongoClient, // $NON-NLS-1$
"getDatabase", new Object[] { dbName });
} else if (isUpgradeVersion(connection)) {
if (mongoClient == null) {
mongoClient = getMongo(connection, requireAuth, requireEncryption);
}
db = // $NON-NLS-1$
NoSQLReflection.invokeMethod(// $NON-NLS-1$
mongoClient, // $NON-NLS-1$
"getDB", new Object[] { dbName });
} else {
if (mongoClient == null) {
mongoClient = getMongo(connection);
}
// $NON-NLS-1$
db = NoSQLReflection.invokeMethod(mongoClient, "getDB", new Object[] { dbName });
// Do authenticate
if (requireAuth) {
String userName = connection.getAttributes().get(IMongoDBAttributes.USERNAME);
String password = connection.getValue(connection.getAttributes().get(IMongoDBAttributes.PASSWORD), false);
if (connection.isContextMode()) {
ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(connection);
userName = ContextParameterUtils.getOriginalValue(contextType, userName);
password = ContextParameterUtils.getOriginalValue(contextType, password);
}
if (userName != null && password != null) {
boolean authorized = (Boolean) NoSQLReflection.invokeMethod(db, "authenticate", // $NON-NLS-1$
new Object[] { userName, password.toCharArray() });
if (!authorized) {
// $NON-NLS-1$
throw new NoSQLServerException(Messages.getString("MongoDBConnectionUtil.ConnotLogon", dbName));
}
}
}
}
} catch (NoSQLReflectionException e) {
throw new NoSQLServerException(e);
}
return db;
}
Aggregations