Search in sources :

Example 6 with Hashtable

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;
}
Also used : Hashtable(java.util.Hashtable) ObjectName(javax.management.ObjectName)

Example 7 with Hashtable

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;
}
Also used : JSchException(com.jcraft.jsch.JSchException) Hashtable(java.util.Hashtable) JSch(com.jcraft.jsch.JSch) GenericFileEndpoint(org.apache.camel.component.file.GenericFileEndpoint)

Example 8 with Hashtable

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;
}
Also used : Hashtable(java.util.Hashtable) InitialDirContext(javax.naming.directory.InitialDirContext)

Example 9 with Hashtable

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);
    }
}
Also used : InitialLdapContext(javax.naming.ldap.InitialLdapContext) InitialDirContext(javax.naming.directory.InitialDirContext) Context(javax.naming.Context) LdapContext(javax.naming.ldap.LdapContext) AuthenticationException(org.apache.hadoop.security.authentication.client.AuthenticationException) Hashtable(java.util.Hashtable) NamingException(javax.naming.NamingException) InitialDirContext(javax.naming.directory.InitialDirContext)

Example 10 with Hashtable

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"));
}
Also used : Hashtable(java.util.Hashtable) Schema(org.apache.avro.Schema) ArrayList(java.util.ArrayList) GenericData(org.apache.avro.generic.GenericData) StructField(org.apache.hadoop.hive.serde2.objectinspector.StructField) StandardStructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StandardStructObjectInspector) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

Hashtable (java.util.Hashtable)1278 Test (org.junit.Test)367 ArrayList (java.util.ArrayList)267 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)142 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)137 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)136 HashMap (java.util.HashMap)89 Bundle (org.osgi.framework.Bundle)82 BundleContext (org.osgi.framework.BundleContext)75 Configuration (org.osgi.service.cm.Configuration)75 Map (java.util.Map)73 IOException (java.io.IOException)67 ServiceRegistration (org.osgi.framework.ServiceRegistration)64 Enumeration (java.util.Enumeration)63 Dictionary (java.util.Dictionary)61 InitialContext (javax.naming.InitialContext)54 Vector (java.util.Vector)53 URL (java.net.URL)49 CUCorrectionProposal (org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal)47 File (java.io.File)45