Search in sources :

Example 66 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 67 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 68 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 69 with Hashtable

use of java.util.Hashtable in project camel by apache.

the class SftpOperations method createSession.

protected Session createSession(final RemoteFileConfiguration configuration) throws JSchException {
    final JSch jsch = new JSch();
    JSch.setLogger(new JSchLogger(endpoint.getConfiguration().getJschLoggingLevel()));
    SftpConfiguration sftpConfig = (SftpConfiguration) configuration;
    if (isNotEmpty(sftpConfig.getCiphers())) {
        LOG.debug("Using ciphers: {}", sftpConfig.getCiphers());
        Hashtable<String, String> ciphers = new Hashtable<String, String>();
        ciphers.put("cipher.s2c", sftpConfig.getCiphers());
        ciphers.put("cipher.c2s", sftpConfig.getCiphers());
        JSch.setConfig(ciphers);
    }
    if (isNotEmpty(sftpConfig.getPrivateKeyFile())) {
        LOG.debug("Using private keyfile: {}", sftpConfig.getPrivateKeyFile());
        if (isNotEmpty(sftpConfig.getPrivateKeyPassphrase())) {
            jsch.addIdentity(sftpConfig.getPrivateKeyFile(), sftpConfig.getPrivateKeyPassphrase());
        } else {
            jsch.addIdentity(sftpConfig.getPrivateKeyFile());
        }
    }
    if (sftpConfig.getPrivateKey() != null) {
        LOG.debug("Using private key information from byte array");
        byte[] passphrase = null;
        if (isNotEmpty(sftpConfig.getPrivateKeyPassphrase())) {
            try {
                passphrase = sftpConfig.getPrivateKeyPassphrase().getBytes("UTF-8");
            } catch (UnsupportedEncodingException e) {
                throw new JSchException("Cannot transform passphrase to byte[]", e);
            }
        }
        jsch.addIdentity("ID", sftpConfig.getPrivateKey(), null, passphrase);
    }
    if (sftpConfig.getPrivateKeyUri() != null) {
        LOG.debug("Using private key uri : {}", sftpConfig.getPrivateKeyUri());
        byte[] passphrase = null;
        if (isNotEmpty(sftpConfig.getPrivateKeyPassphrase())) {
            try {
                passphrase = sftpConfig.getPrivateKeyPassphrase().getBytes("UTF-8");
            } catch (UnsupportedEncodingException e) {
                throw new JSchException("Cannot transform passphrase to byte[]", e);
            }
        }
        try {
            InputStream is = ResourceHelper.resolveMandatoryResourceAsInputStream(endpoint.getCamelContext(), sftpConfig.getPrivateKeyUri());
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            IOHelper.copyAndCloseInput(is, bos);
            jsch.addIdentity("ID", bos.toByteArray(), null, passphrase);
        } catch (IOException e) {
            throw new JSchException("Cannot read resource: " + sftpConfig.getPrivateKeyUri(), e);
        }
    }
    if (sftpConfig.getKeyPair() != null) {
        LOG.debug("Using private key information from key pair");
        KeyPair keyPair = sftpConfig.getKeyPair();
        if (keyPair.getPrivate() != null && keyPair.getPublic() != null) {
            if (keyPair.getPrivate() instanceof RSAPrivateKey && keyPair.getPublic() instanceof RSAPublicKey) {
                jsch.addIdentity(new RSAKeyPairIdentity("ID", keyPair), null);
            } else if (keyPair.getPrivate() instanceof DSAPrivateKey && keyPair.getPublic() instanceof DSAPublicKey) {
                jsch.addIdentity(new DSAKeyPairIdentity("ID", keyPair), null);
            } else {
                LOG.warn("Only RSA and DSA key pairs are supported");
            }
        } else {
            LOG.warn("PrivateKey and PublicKey in the KeyPair must be filled");
        }
    }
    if (isNotEmpty(sftpConfig.getKnownHostsFile())) {
        LOG.debug("Using knownhosts file: {}", sftpConfig.getKnownHostsFile());
        jsch.setKnownHosts(sftpConfig.getKnownHostsFile());
    }
    if (isNotEmpty(sftpConfig.getKnownHostsUri())) {
        LOG.debug("Using known hosts uri: {}", sftpConfig.getKnownHostsUri());
        try {
            InputStream is = ResourceHelper.resolveMandatoryResourceAsInputStream(endpoint.getCamelContext(), sftpConfig.getKnownHostsUri());
            jsch.setKnownHosts(is);
        } catch (IOException e) {
            throw new JSchException("Cannot read resource: " + sftpConfig.getKnownHostsUri(), e);
        }
    }
    if (sftpConfig.getKnownHosts() != null) {
        LOG.debug("Using known hosts information from byte array");
        jsch.setKnownHosts(new ByteArrayInputStream(sftpConfig.getKnownHosts()));
    }
    String knownHostsFile = sftpConfig.getKnownHostsFile();
    if (knownHostsFile == null && sftpConfig.isUseUserKnownHostsFile()) {
        knownHostsFile = System.getProperty("user.home") + "/.ssh/known_hosts";
        LOG.info("Known host file not configured, using user known host file: {}", knownHostsFile);
    }
    if (ObjectHelper.isNotEmpty(knownHostsFile)) {
        LOG.debug("Using known hosts information from file: {}", knownHostsFile);
        jsch.setKnownHosts(knownHostsFile);
    }
    final Session session = jsch.getSession(configuration.getUsername(), configuration.getHost(), configuration.getPort());
    if (isNotEmpty(sftpConfig.getStrictHostKeyChecking())) {
        LOG.debug("Using StrickHostKeyChecking: {}", sftpConfig.getStrictHostKeyChecking());
        session.setConfig("StrictHostKeyChecking", sftpConfig.getStrictHostKeyChecking());
    }
    session.setServerAliveInterval(sftpConfig.getServerAliveInterval());
    session.setServerAliveCountMax(sftpConfig.getServerAliveCountMax());
    // compression
    if (sftpConfig.getCompression() > 0) {
        LOG.debug("Using compression: {}", sftpConfig.getCompression());
        session.setConfig("compression.s2c", "zlib@openssh.com,zlib,none");
        session.setConfig("compression.c2s", "zlib@openssh.com,zlib,none");
        session.setConfig("compression_level", Integer.toString(sftpConfig.getCompression()));
    }
    // set the PreferredAuthentications 
    if (sftpConfig.getPreferredAuthentications() != null) {
        LOG.debug("Using PreferredAuthentications: {}", sftpConfig.getPreferredAuthentications());
        session.setConfig("PreferredAuthentications", sftpConfig.getPreferredAuthentications());
    }
    // set user information
    session.setUserInfo(new ExtendedUserInfo() {

        public String getPassphrase() {
            return null;
        }

        public String getPassword() {
            return configuration.getPassword();
        }

        public boolean promptPassword(String s) {
            return true;
        }

        public boolean promptPassphrase(String s) {
            return true;
        }

        public boolean promptYesNo(String s) {
            LOG.warn("Server asks for confirmation (yes|no): " + s + ". Camel will answer no.");
            // Return 'false' indicating modification of the hosts file is disabled.
            return false;
        }

        public void showMessage(String s) {
            LOG.trace("Message received from Server: " + s);
        }

        public String[] promptKeyboardInteractive(String destination, String name, String instruction, String[] prompt, boolean[] echo) {
            // must return an empty array if password is null
            if (configuration.getPassword() == null) {
                return new String[0];
            } else {
                return new String[] { configuration.getPassword() };
            }
        }
    });
    // set the SO_TIMEOUT for the time after the connect phase
    if (configuration.getSoTimeout() > 0) {
        session.setTimeout(configuration.getSoTimeout());
    }
    // set proxy if configured
    if (proxy != null) {
        session.setProxy(proxy);
    }
    return session;
}
Also used : JSchException(com.jcraft.jsch.JSchException) KeyPair(java.security.KeyPair) Hashtable(java.util.Hashtable) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) JSch(com.jcraft.jsch.JSch) DSAPublicKey(java.security.interfaces.DSAPublicKey) RSAPublicKey(java.security.interfaces.RSAPublicKey) ByteArrayInputStream(java.io.ByteArrayInputStream) DSAPrivateKey(java.security.interfaces.DSAPrivateKey) RSAPrivateKey(java.security.interfaces.RSAPrivateKey) Session(com.jcraft.jsch.Session)

Example 70 with Hashtable

use of java.util.Hashtable in project camel by apache.

the class ComponentFoundInRegistryTest method testGuice.

@Test
public void testGuice() throws Exception {
    Hashtable<String, Object> env = new Hashtable<String, Object>();
    env.put(Context.PROVIDER_URL, GuiceInitialContextFactory.class.getName());
    env.put(Injectors.MODULE_CLASS_NAMES, MyModule.class.getName());
    InitialContext context = new InitialContext(env);
    Injector injector = (Injector) context.lookup(Injector.class.getName());
    assertNotNull("Found injector", injector);
    Object value = context.lookup("foo");
    assertNotNull("Should have found a value for foo!", value);
    CamelContext camelContext = injector.getInstance(CamelContext.class);
    Component component = camelContext.getComponent("foo");
    assertThat(component, is(MockComponent.class));
    Endpoint endpoint = camelContext.getEndpoint("foo:cheese");
    assertThat(endpoint, is(MockEndpoint.class));
}
Also used : CamelContext(org.apache.camel.CamelContext) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Hashtable(java.util.Hashtable) MockComponent(org.apache.camel.component.mock.MockComponent) InitialContext(javax.naming.InitialContext) Endpoint(org.apache.camel.Endpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Injector(com.google.inject.Injector) MockComponent(org.apache.camel.component.mock.MockComponent) Component(org.apache.camel.Component) GuiceInitialContextFactory(org.apache.camel.guice.jndi.GuiceInitialContextFactory) Test(org.junit.Test)

Aggregations

Hashtable (java.util.Hashtable)1752 Test (org.junit.Test)374 ArrayList (java.util.ArrayList)355 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)219 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)104 IOException (java.io.IOException)91 Dictionary (java.util.Dictionary)91 Vector (java.util.Vector)88 File (java.io.File)86 Map (java.util.Map)84 Bundle (org.osgi.framework.Bundle)84 BundleContext (org.osgi.framework.BundleContext)78 Configuration (org.osgi.service.cm.Configuration)75 Enumeration (java.util.Enumeration)70 BundleDescription (org.eclipse.osgi.service.resolver.BundleDescription)70 State (org.eclipse.osgi.service.resolver.State)70 ServiceRegistration (org.osgi.framework.ServiceRegistration)65