use of java.util.Hashtable in project camel by apache.
the class JMXEndpoint method buildObjectName.
private ObjectName buildObjectName() throws MalformedObjectNameException {
ObjectName objectName;
if (getObjectProperties() == null) {
StringBuilder sb = new StringBuilder(getObjectDomain()).append(':').append("name=").append(getObjectName());
objectName = new ObjectName(sb.toString());
} else {
Hashtable<String, String> ht = new Hashtable<String, String>();
ht.putAll(getObjectProperties());
objectName = new ObjectName(getObjectDomain(), ht);
}
return objectName;
}
use of java.util.Hashtable in project camel by apache.
the class ScpOperations method createSession.
private Session createSession(ScpConfiguration config) {
ObjectHelper.notNull(config, "ScpConfiguration");
try {
final JSch jsch = new JSch();
// get from configuration
if (ObjectHelper.isNotEmpty(config.getCiphers())) {
LOG.trace("Using ciphers: {}", config.getCiphers());
Hashtable<String, String> ciphers = new Hashtable<String, String>();
ciphers.put("cipher.s2c", config.getCiphers());
ciphers.put("cipher.c2s", config.getCiphers());
JSch.setConfig(ciphers);
}
if (ObjectHelper.isNotEmpty(config.getPrivateKeyFile())) {
LOG.trace("Using private keyfile: {}", config.getPrivateKeyFile());
String pkfp = config.getPrivateKeyFilePassphrase();
jsch.addIdentity(config.getPrivateKeyFile(), ObjectHelper.isNotEmpty(pkfp) ? pkfp : null);
}
String knownHostsFile = config.getKnownHostsFile();
if (knownHostsFile == null && config.isUseUserKnownHostsFile()) {
if (userKnownHostFile == null) {
userKnownHostFile = System.getProperty("user.home") + "/.ssh/known_hosts";
LOG.info("Known host file not configured, using user known host file: " + userKnownHostFile);
}
knownHostsFile = userKnownHostFile;
}
jsch.setKnownHosts(ObjectHelper.isEmpty(knownHostsFile) ? null : knownHostsFile);
session = jsch.getSession(config.getUsername(), config.getHost(), config.getPort());
session.setTimeout(config.getTimeout());
session.setUserInfo(new SessionUserInfo(config));
if (ObjectHelper.isNotEmpty(config.getStrictHostKeyChecking())) {
LOG.trace("Using StrickHostKeyChecking: {}", config.getStrictHostKeyChecking());
session.setConfig("StrictHostKeyChecking", config.getStrictHostKeyChecking());
}
if (ObjectHelper.isNotEmpty(config.getPreferredAuthentications())) {
LOG.trace("Using preferredAuthentications: {}", config.getPreferredAuthentications());
session.setConfig("PreferredAuthentications", config.getPreferredAuthentications());
}
int timeout = config.getConnectTimeout();
LOG.debug("Connecting to {} with {} timeout...", config.remoteServerInformation(), timeout > 0 ? (Integer.toString(timeout) + " ms") : "no");
if (timeout > 0) {
session.connect(timeout);
} else {
session.connect();
}
} catch (JSchException e) {
session = null;
LOG.warn("Could not create ssh session for " + config.remoteServerInformation(), e);
}
return session;
}
use of java.util.Hashtable in project hadoop by apache.
the class LdapGroupsMapping method getDirContext.
DirContext getDirContext() throws NamingException {
if (ctx == null) {
// Set up the initial environment for LDAP connectivity
Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, com.sun.jndi.ldap.LdapCtxFactory.class.getName());
env.put(Context.PROVIDER_URL, ldapUrl);
env.put(Context.SECURITY_AUTHENTICATION, "simple");
// Set up SSL security, if necessary
if (useSsl) {
env.put(Context.SECURITY_PROTOCOL, "ssl");
System.setProperty("javax.net.ssl.keyStore", keystore);
System.setProperty("javax.net.ssl.keyStorePassword", keystorePass);
}
env.put(Context.SECURITY_PRINCIPAL, bindUser);
env.put(Context.SECURITY_CREDENTIALS, bindPassword);
env.put("com.sun.jndi.ldap.connect.timeout", conf.get(CONNECTION_TIMEOUT, String.valueOf(CONNECTION_TIMEOUT_DEFAULT)));
env.put("com.sun.jndi.ldap.read.timeout", conf.get(READ_TIMEOUT, String.valueOf(READ_TIMEOUT_DEFAULT)));
ctx = new InitialDirContext(env);
}
return ctx;
}
use of java.util.Hashtable in project hadoop by apache.
the class LdapAuthenticationHandler method authenticateWithoutTlsExtension.
private void authenticateWithoutTlsExtension(String userDN, String password) throws AuthenticationException {
Hashtable<String, Object> env = new Hashtable<String, Object>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, providerUrl);
env.put(Context.SECURITY_AUTHENTICATION, SECURITY_AUTHENTICATION);
env.put(Context.SECURITY_PRINCIPAL, userDN);
env.put(Context.SECURITY_CREDENTIALS, password);
try {
// Create initial context
Context ctx = new InitialDirContext(env);
ctx.close();
logger.debug("Authentication successful for {}", userDN);
} catch (NamingException e) {
throw new AuthenticationException("Error validating LDAP user", e);
}
}
use of java.util.Hashtable in project hive by apache.
the class TestAvroDeserializer method canDeserializeMapsWithJavaLangStringKeys.
@Test
public void canDeserializeMapsWithJavaLangStringKeys() throws IOException, SerDeException {
// Ensures maps can be deserialized when avro.java.string=String.
// See http://stackoverflow.com/a/19868919/312944 for why that might be used.
String schemaString = "{\n" + " \"namespace\": \"testing\",\n" + " \"name\": \"oneMap\",\n" + " \"type\": \"record\",\n" + " \"fields\": [\n" + " {\n" + " \"name\":\"aMap\",\n" + " \"type\":{\"type\":\"map\",\n" + " \"avro.java.string\":\"String\",\n" + " \"values\":\"long\"}\n" + "\t}\n" + " ]\n" + "}";
Schema s = AvroSerdeUtils.getSchemaFor(schemaString);
GenericData.Record record = new GenericData.Record(s);
Map<String, Long> m = new Hashtable<String, Long>();
m.put("one", 1l);
m.put("two", 2l);
m.put("three", 3l);
record.put("aMap", m);
assertTrue(GENERIC_DATA.validate(s, record));
System.out.println("record = " + record);
AvroGenericRecordWritable garw = Utils.serializeAndDeserializeRecord(record);
AvroObjectInspectorGenerator aoig = new AvroObjectInspectorGenerator(s);
AvroDeserializer de = new AvroDeserializer();
ArrayList<Object> row = (ArrayList<Object>) de.deserialize(aoig.getColumnNames(), aoig.getColumnTypes(), garw, s);
assertEquals(1, row.size());
Object theMapObject = row.get(0);
assertTrue(theMapObject instanceof Map);
Map theMap = (Map) theMapObject;
// Verify the raw object that's been created
assertEquals(1l, theMap.get("one"));
assertEquals(2l, theMap.get("two"));
assertEquals(3l, theMap.get("three"));
// Verify that the provided object inspector can pull out these same values
StandardStructObjectInspector oi = (StandardStructObjectInspector) aoig.getObjectInspector();
List<Object> z = oi.getStructFieldsDataAsList(row);
assertEquals(1, z.size());
StructField fieldRef = oi.getStructFieldRef("amap");
Map theMap2 = (Map) oi.getStructFieldData(row, fieldRef);
assertEquals(1l, theMap2.get("one"));
assertEquals(2l, theMap2.get("two"));
assertEquals(3l, theMap2.get("three"));
}
Aggregations