com.datastax.driver.core.AuthProvider Java Examples

The following examples show how to use com.datastax.driver.core.AuthProvider. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CassandraTarget.java    From datacollector with Apache License 2.0 6 votes vote down vote up
private AuthProvider getAuthProvider() throws StageException {
  switch (conf.authProviderOption) {
    case NONE:
      return AuthProvider.NONE;
    case PLAINTEXT:
      return new PlainTextAuthProvider(conf.username.get(), conf.password.get());
    case DSE_PLAINTEXT:
      return new DsePlainTextAuthProvider(conf.username.get(), conf.password.get());
    case KERBEROS:
      AccessControlContext accessContext = AccessController.getContext();
      Subject subject = Subject.getSubject(accessContext);
      return DseGSSAPIAuthProvider.builder().withSubject(subject).build();
    default:
      throw new IllegalArgumentException("Unrecognized AuthProvider: " + conf.authProviderOption);
  }
}
 
Example #2
Source File: CqlConfigHelper.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
private static AuthProvider getClientAuthProvider(String factoryClassName, Configuration conf)
{
    try
    {
        Class<?> c = Class.forName(factoryClassName);
        if (PlainTextAuthProvider.class.equals(c))
        {
            String username = getStringSetting(USERNAME, conf).or("");
            String password = getStringSetting(PASSWORD, conf).or("");
            return (AuthProvider) c.getConstructor(String.class, String.class)
                    .newInstance(username, password);
        }
        else
        {
            return (AuthProvider) c.newInstance();
        }
    }
    catch (Exception e)
    {
        throw new RuntimeException("Failed to instantiate auth provider:" + factoryClassName, e);
    }
}
 
Example #3
Source File: CassandraConfiguration.java    From spring-cloud-stream-app-starters with Apache License 2.0 5 votes vote down vote up
@Override
protected AuthProvider getAuthProvider() {
	if (StringUtils.hasText(this.cassandraProperties.getUsername())) {
		return new PlainTextAuthProvider(this.cassandraProperties.getUsername(),
				this.cassandraProperties.getPassword());
	}
	else {
		return null;
	}
}
 
Example #4
Source File: DataSource.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    fetchSize = (Integer)in.readObject();
    readConsistency = (ConsistencyLevel)in.readObject();
    writeConsistency = (ConsistencyLevel)in.readObject();
    user = U.readString(in);
    pwd = U.readString(in);
    port = (Integer)in.readObject();
    contactPoints = (List<InetAddress>)in.readObject();
    contactPointsWithPorts = (List<InetSocketAddress>)in.readObject();
    maxSchemaAgreementWaitSeconds = (Integer)in.readObject();
    protoVer = (Integer)in.readObject();
    compression = U.readString(in);
    useSSL = (Boolean)in.readObject();
    collectMetrix = (Boolean)in.readObject();
    jmxReporting = (Boolean)in.readObject();
    creds = (Credentials)in.readObject();
    loadBalancingPlc = (LoadBalancingPolicy)readObject(in);
    reconnectionPlc = (ReconnectionPolicy)readObject(in);
    addrTranslator = (AddressTranslator)readObject(in);
    speculativeExecutionPlc = (SpeculativeExecutionPolicy)readObject(in);
    authProvider = (AuthProvider)readObject(in);
    sslOptions = (SSLOptions)readObject(in);
    poolingOptions = (PoolingOptions)readObject(in);
    sockOptions = (SocketOptions)readObject(in);
    nettyOptions = (NettyOptions)readObject(in);
}
 
Example #5
Source File: CqlConfigHelper.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public static Cluster getInputCluster(String[] hosts, Configuration conf)
{
    int port = getInputNativePort(conf);
    Optional<AuthProvider> authProvider = getAuthProvider(conf);
    Optional<SSLOptions> sslOptions = getSSLOptions(conf);
    Optional<Integer> protocolVersion = getProtocolVersion(conf);
    LoadBalancingPolicy loadBalancingPolicy = getReadLoadBalancingPolicy(conf, hosts);
    SocketOptions socketOptions = getReadSocketOptions(conf);
    QueryOptions queryOptions = getReadQueryOptions(conf);
    PoolingOptions poolingOptions = getReadPoolingOptions(conf);
    
    Cluster.Builder builder = Cluster.builder()
                                     .addContactPoints(hosts)
                                     .withPort(port)
                                     .withCompression(ProtocolOptions.Compression.NONE);

    if (authProvider.isPresent())
        builder.withAuthProvider(authProvider.get());
    if (sslOptions.isPresent())
        builder.withSSL(sslOptions.get());

    if (protocolVersion.isPresent()) {
        builder.withProtocolVersion(protocolVersion.get());
    }
    builder.withLoadBalancingPolicy(loadBalancingPolicy)
           .withSocketOptions(socketOptions)
           .withQueryOptions(queryOptions)
           .withPoolingOptions(poolingOptions);

    return builder.build();
}
 
Example #6
Source File: CqlConfigHelper.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
private static Optional<AuthProvider> getAuthProvider(Configuration conf)
{
    Optional<String> authProvider = getInputNativeAuthProvider(conf);
    if (!authProvider.isPresent())
        return Optional.absent();

    return Optional.of(getClientAuthProvider(authProvider.get(), conf));
}
 
Example #7
Source File: YugabyteCloudConfig.java    From yugastore-java with Apache License 2.0 4 votes vote down vote up
@Override
protected AuthProvider getAuthProvider() {
	return new PlainTextAuthProvider(cassandraUsername, cassandraPassword);
}
 
Example #8
Source File: AppConfig.java    From spring-boot-ddd with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected AuthProvider getAuthProvider() {
    return new PlainTextAuthProvider(this.cassandraProperties.getUsername(),
            this.cassandraProperties.getPassword());
}
 
Example #9
Source File: CassandraConfiguration.java    From emodb with Apache License 2.0 4 votes vote down vote up
private com.datastax.driver.core.Cluster.Builder newCqlDriverBuilder(ConnectionPoolConfiguration poolConfig,
                                                                     MetricRegistry metricRegistry) {
    performHostDiscovery(metricRegistry);

    String[] seeds = _seeds.split(",");
    List<String> contactPoints = Lists.newArrayListWithCapacity(seeds.length);

    // Each seed may be a host name or a host name and port (e.g.; "1.2.3.4" or "1.2.3.4:9160").  These need
    // to be converted into host names only.
    for (String seed : seeds) {
        HostAndPort hostAndPort = HostAndPort.fromString(seed);
        seed = hostAndPort.getHostText();
        if (hostAndPort.hasPort()) {
            if (hostAndPort.getPort() == _thriftPort) {
                _log.debug("Seed {} found using RPC port; swapping for native port {}", seed, _cqlPort);
            } else if (hostAndPort.getPort() != _cqlPort) {
                throw new IllegalArgumentException(String.format(
                        "Seed %s found with invalid port %s.  The port must match either the RPC (thrift) port %s " +
                        "or the native (CQL) port %s", seed, hostAndPort.getPort(), _thriftPort, _cqlPort));
            }
        }

        contactPoints.add(seed);
    }

    PoolingOptions poolingOptions = new PoolingOptions();
    if (poolConfig.getMaxConnectionsPerHost().or(getMaxConnectionsPerHost()).isPresent()) {
        poolingOptions.setMaxConnectionsPerHost(HostDistance.LOCAL, poolConfig.getMaxConnectionsPerHost().or(getMaxConnectionsPerHost()).get());
    }
    if (poolConfig.getCoreConnectionsPerHost().or(getCoreConnectionsPerHost()).isPresent()) {
        poolingOptions.setCoreConnectionsPerHost(HostDistance.LOCAL, poolConfig.getCoreConnectionsPerHost().or(getCoreConnectionsPerHost()).get());
    }

    SocketOptions socketOptions = new SocketOptions();
    if (poolConfig.getConnectTimeout().or(getConnectTimeout()).isPresent()) {
        socketOptions.setConnectTimeoutMillis(poolConfig.getConnectTimeout().or(getConnectTimeout()).get());
    }
    if (poolConfig.getSocketTimeout().or(getSocketTimeout()).isPresent()) {
        socketOptions.setReadTimeoutMillis(poolConfig.getSocketTimeout().or(getSocketTimeout()).get());
    }

    AuthProvider authProvider = _authenticationCredentials != null
            ? new PlainTextAuthProvider(_authenticationCredentials.getUsername(), _authenticationCredentials.getPassword())
            : AuthProvider.NONE;

    return com.datastax.driver.core.Cluster.builder()
            .addContactPoints(contactPoints.toArray(new String[contactPoints.size()]))
            .withPort(_cqlPort)
            .withPoolingOptions(poolingOptions)
            .withSocketOptions(socketOptions)
            .withRetryPolicy(Policies.defaultRetryPolicy())
            .withAuthProvider(authProvider);
}
 
Example #10
Source File: DatastaxAuthenticationTest.java    From heroic with Apache License 2.0 4 votes vote down vote up
@Test
public void testNone() {
    final DatastaxAuthentication a = new DatastaxAuthentication.None();
    a.accept(builder);
    verify(builder, never()).withAuthProvider(any(AuthProvider.class));
}
 
Example #11
Source File: DataSource.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * Sets authentication provider.
 *
 * @param provider Authentication provider.
 */
public void setAuthProvider(AuthProvider provider) {
    authProvider = provider;

    invalidate();
}
 
Example #12
Source File: PlainTextAuthProviderFactory.java    From dropwizard-cassandra with Apache License 2.0 4 votes vote down vote up
@Override
public AuthProvider build() {
    return new PlainTextAuthProvider(username, password);
}
 
Example #13
Source File: CassandraClusterCreatorTest.java    From spring-cloud-connectors with Apache License 2.0 3 votes vote down vote up
@Test
public void shouldCreateCluster() throws Exception {

	CassandraServiceInfo info = new CassandraServiceInfo("local",
			Collections.singletonList("127.0.0.1"), 9142);

	Cluster cluster = creator.create(info, null);

	Configuration configuration = cluster.getConfiguration();

	assertThat(configuration.getProtocolOptions().getAuthProvider(),
			is(AuthProvider.NONE));
}
 
Example #14
Source File: AuthProviderFactory.java    From dropwizard-cassandra with Apache License 2.0 votes vote down vote up
AuthProvider build();