private static void configureTransportFactory( ITransportFactory transportFactory, LoaderOptions opts) { Map<String, String> options = new HashMap<>(); // If the supplied factory supports the same set of options as our SSL impl, set those if (transportFactory.supportedOptions().contains(SSLTransportFactory.TRUSTSTORE)) options.put(SSLTransportFactory.TRUSTSTORE, opts.encOptions.truststore); if (transportFactory.supportedOptions().contains(SSLTransportFactory.TRUSTSTORE_PASSWORD)) options.put(SSLTransportFactory.TRUSTSTORE_PASSWORD, opts.encOptions.truststore_password); if (transportFactory.supportedOptions().contains(SSLTransportFactory.PROTOCOL)) options.put(SSLTransportFactory.PROTOCOL, opts.encOptions.protocol); if (transportFactory.supportedOptions().contains(SSLTransportFactory.CIPHER_SUITES)) options.put( SSLTransportFactory.CIPHER_SUITES, Joiner.on(',').join(opts.encOptions.cipher_suites)); if (transportFactory.supportedOptions().contains(SSLTransportFactory.KEYSTORE) && opts.encOptions.require_client_auth) options.put(SSLTransportFactory.KEYSTORE, opts.encOptions.keystore); if (transportFactory.supportedOptions().contains(SSLTransportFactory.KEYSTORE_PASSWORD) && opts.encOptions.require_client_auth) options.put(SSLTransportFactory.KEYSTORE_PASSWORD, opts.encOptions.keystore_password); // Now check if any of the factory's supported options are set as system properties for (String optionKey : transportFactory.supportedOptions()) if (System.getProperty(optionKey) != null) options.put(optionKey, System.getProperty(optionKey)); transportFactory.setOptions(options); }
private static Cassandra.Client createThriftClient( String host, int port, String user, String passwd, ITransportFactory transportFactory) throws Exception { TTransport trans = transportFactory.openTransport(host, port); TProtocol protocol = new TBinaryProtocol(trans); Cassandra.Client client = new Cassandra.Client(protocol); if (user != null && passwd != null) { Map<String, String> credentials = new HashMap<>(); credentials.put(IAuthenticator.USERNAME_KEY, user); credentials.put(IAuthenticator.PASSWORD_KEY, passwd); AuthenticationRequest authenticationRequest = new AuthenticationRequest(credentials); client.login(authenticationRequest); } return client; }