Java 类com.datastax.driver.core.AuthProvider 实例源码

项目:cassandra-kmean    文件:CqlConfigHelper.java   
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);
    }
}
项目:datacollector    文件:CassandraTarget.java   
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);
  }
}
项目:scylla-tools-java    文件:CqlConfigHelper.java   
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);
    }
}
项目:GraphTrek    文件:CqlConfigHelper.java   
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);
    }
}
项目:stratio-cassandra    文件:CqlConfigHelper.java   
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);
    }
}
项目:cassandra    文件:CassandraConfiguration.java   
@Override
protected AuthProvider getAuthProvider() {
    if (StringUtils.hasText(this.cassandraProperties.getUsername())) {
        return new PlainTextAuthProvider(this.cassandraProperties.getUsername(),
                this.cassandraProperties.getPassword());
    }
    else {
        return null;
    }
}
项目:spring-cloud-stream-app-starters    文件:CassandraConfiguration.java   
@Override
protected AuthProvider getAuthProvider() {
    if (StringUtils.hasText(this.cassandraProperties.getUsername())) {
        return new PlainTextAuthProvider(this.cassandraProperties.getUsername(),
                this.cassandraProperties.getPassword());
    }
    else {
        return null;
    }
}
项目:cassandra-kmean    文件:CqlConfigHelper.java   
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();
}
项目:cassandra-kmean    文件:CqlConfigHelper.java   
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));
}
项目:ignite    文件:DataSource.java   
/**
 * Sets authentication provider.
 *
 * @param provider Authentication provider.
 */
@SuppressWarnings("UnusedDeclaration")
public void setAuthProvider(AuthProvider provider) {
    authProvider = provider;

    invalidate();
}
项目:ignite    文件:DataSource.java   
/** {@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);
}
项目:scylla-tools-java    文件:CqlConfigHelper.java   
public static Cluster getCluster(String[] hosts, Configuration conf, int port)
{
    Optional<AuthProvider> authProvider = getAuthProvider(conf);
    Optional<SSLOptions> sslOptions = getSSLOptions(conf);
    Optional<Integer> protocolVersion = getProtocolVersion(conf);
    LoadBalancingPolicy loadBalancingPolicy = getReadLoadBalancingPolicy(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.fromInt(protocolVersion.get()));
    }
    builder.withLoadBalancingPolicy(loadBalancingPolicy)
            .withSocketOptions(socketOptions)
            .withQueryOptions(queryOptions)
            .withPoolingOptions(poolingOptions);

    return builder.build();
}
项目:scylla-tools-java    文件:CqlConfigHelper.java   
private static Optional<AuthProvider> getDefaultAuthProvider(Configuration conf)
{
    Optional<String> username = getStringSetting(USERNAME, conf);
    Optional<String> password = getStringSetting(PASSWORD, conf);

    if (username.isPresent() && password.isPresent())
    {
        return Optional.of(new PlainTextAuthProvider(username.get(), password.get()));
    }
    else
    {
        return Optional.absent();
    }
}
项目:scylla-tools-java    文件:CqlConfigHelper.java   
private static Optional<AuthProvider> getAuthProvider(Configuration conf)
{
    Optional<String> authProvider = getInputNativeAuthProvider(conf);
    if (!authProvider.isPresent())
        return getDefaultAuthProvider(conf);

    return Optional.of(getClientAuthProvider(authProvider.get(), conf));
}
项目:scylla-tools-java    文件:BulkLoader.java   
public ExternalClient(Set<InetAddress> hosts,
                      int port,
                      AuthProvider authProvider,
                      int storagePort,
                      int sslStoragePort,
                      EncryptionOptions.ServerEncryptionOptions serverEncryptionOptions,
                      SSLOptions sslOptions)
{
    super(hosts, port, authProvider, sslOptions);
    this.storagePort = storagePort;
    this.sslStoragePort = sslStoragePort;
    this.serverEncOptions = serverEncryptionOptions;
}
项目:GraphTrek    文件:CqlConfigHelper.java   
public static Cluster getInputCluster(String[] hosts, Configuration conf)
{
    int port = getInputNativePort(conf);
    Optional<AuthProvider> authProvider = getAuthProvider(conf);
    Optional<SSLOptions> sslOptions = getSSLOptions(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());

    builder.withLoadBalancingPolicy(loadBalancingPolicy)
           .withSocketOptions(socketOptions)
           .withQueryOptions(queryOptions)
           .withPoolingOptions(poolingOptions);

    return builder.build();
}
项目:GraphTrek    文件:CqlConfigHelper.java   
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));
}
项目:stratio-cassandra    文件:CqlConfigHelper.java   
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();
}
项目:stratio-cassandra    文件:CqlConfigHelper.java   
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));
}
项目:cassandra-trunk    文件:CqlConfigHelper.java   
public static Cluster getInputCluster(String host, Configuration conf)
{
    int port = getInputNativePort(conf);
    Optional<AuthProvider> authProvider = getAuthProvider(conf);
    Optional<SSLOptions> sslOptions = getSSLOptions(conf);
    LoadBalancingPolicy loadBalancingPolicy = getReadLoadBalancingPolicy(conf, host);
    SocketOptions socketOptions = getReadSocketOptions(conf);
    QueryOptions queryOptions = getReadQueryOptions(conf);
    PoolingOptions poolingOptions = getReadPoolingOptions(conf);

    Cluster.Builder builder = Cluster.builder()
                                     .addContactPoint(host)
                                     .withPort(port)
                                     .withCompression(ProtocolOptions.Compression.NONE);

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

    builder.withLoadBalancingPolicy(loadBalancingPolicy)
           .withSocketOptions(socketOptions)
           .withQueryOptions(queryOptions)
           .withPoolingOptions(poolingOptions);

    return builder.build();
}
项目:cassandra-trunk    文件:CqlConfigHelper.java   
private static Optional<AuthProvider> getAuthProvider(Configuration conf)
{
    Optional<String> authProvider = getInputNativeAuthProvider(conf);
    if (!authProvider.isPresent())
        return Optional.absent();

    return Optional.of(getClientAuthProvider(authProvider.get()));  
}
项目:cassandra-trunk    文件:CqlConfigHelper.java   
private static AuthProvider getClientAuthProvider(String factoryClassName)
{
    try
    {
        return (AuthProvider) Class.forName(factoryClassName).newInstance();
    }
    catch (Exception e)
    {
        throw new RuntimeException("Failed to instantiate auth provider:" + factoryClassName, e);
    }
}
项目:Lagerta    文件:DataSource.java   
/**
 * Sets authentication provider.
 *
 * @param provider Authentication provider.
 */
@SuppressWarnings("UnusedDeclaration")
public void setAuthProvider(AuthProvider provider) {
    this.authProvider = provider;
    invalidate();
}
项目:Lagerta    文件:DataSource.java   
/** {@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);
}
项目:zipkin    文件:SessionFactoryTest.java   
@Test
public void authProvider_defaultsToNone() {
  assertThat(buildCluster(Cassandra3Storage.builder().build())
      .getConfiguration().getProtocolOptions().getAuthProvider())
      .isEqualTo(AuthProvider.NONE);
}
项目:zipkin    文件:SessionFactoryTest.java   
@Test
public void authProvider_defaultsToNone() {
  assertThat(buildCluster(CassandraStorage.builder().build())
      .getConfiguration().getProtocolOptions().getAuthProvider())
      .isEqualTo(AuthProvider.NONE);
}
项目:emodb    文件:CassandraConfiguration.java   
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);
}
项目:heroic    文件:DatastaxAuthenticationTest.java   
@Test
public void testNone() {
    final DatastaxAuthentication a = new DatastaxAuthentication.None();
    a.accept(builder);
    verify(builder, never()).withAuthProvider(any(AuthProvider.class));
}
项目:cf-cassandra-spring-example-app    文件:ApplicationConfiguration.java   
@Override
protected AuthProvider getAuthProvider() {
    return new PlainTextAuthProvider(cassandraConnectionFactory.getProperties().getUsername(), cassandraConnectionFactory.getProperties().getPassword());
}
项目:dropwizard-cassandra    文件:PlainTextAuthProviderFactory.java   
@Override
public AuthProvider build() {
    return new PlainTextAuthProvider(username, password);
}
项目:spring-cloud-connectors    文件:CassandraClusterCreatorTest.java   
@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));
}
项目:dropwizard-cassandra    文件:AuthProviderFactory.java   
AuthProvider build();