Search in sources :

Example 1 with PlainTextAuthProvider

use of com.datastax.driver.core.PlainTextAuthProvider in project cassandra by apache.

the class CqlConfigHelper method getDefaultAuthProvider.

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();
    }
}
Also used : PlainTextAuthProvider(com.datastax.driver.core.PlainTextAuthProvider)

Example 2 with PlainTextAuthProvider

use of com.datastax.driver.core.PlainTextAuthProvider in project cassandra by apache.

the class PasswordAuthenticatorTest method testDecodeIllegalUserAndPwd.

private void testDecodeIllegalUserAndPwd(String username, String password) {
    SaslNegotiator negotiator = authenticator.newSaslNegotiator(null);
    Authenticator clientAuthenticator = (new PlainTextAuthProvider(username, password)).newAuthenticator((EndPoint) null, null);
    negotiator.evaluateResponse(clientAuthenticator.initialResponse());
    negotiator.getAuthenticatedUser();
}
Also used : SaslNegotiator(org.apache.cassandra.auth.PasswordAuthenticator.SaslNegotiator) PlainTextAuthProvider(com.datastax.driver.core.PlainTextAuthProvider) Authenticator(com.datastax.driver.core.Authenticator)

Example 3 with PlainTextAuthProvider

use of com.datastax.driver.core.PlainTextAuthProvider in project cassandra by apache.

the class InvalidateCredentialsCacheTest method setup.

@BeforeClass
public static void setup() throws Exception {
    CQLTester.setUpClass();
    CQLTester.requireAuthentication();
    IRoleManager roleManager = DatabaseDescriptor.getRoleManager();
    roleManager.createRole(AuthenticatedUser.SYSTEM_USER, ROLE_A, AuthTestUtils.getLoginRoleOptions());
    roleManager.createRole(AuthenticatedUser.SYSTEM_USER, ROLE_B, AuthTestUtils.getLoginRoleOptions());
    PasswordAuthenticator passwordAuthenticator = (PasswordAuthenticator) DatabaseDescriptor.getAuthenticator();
    roleANegotiator = passwordAuthenticator.newSaslNegotiator(null);
    roleANegotiator.evaluateResponse(new PlainTextAuthProvider(ROLE_A.getRoleName(), "ignored").newAuthenticator((EndPoint) null, null).initialResponse());
    roleBNegotiator = passwordAuthenticator.newSaslNegotiator(null);
    roleBNegotiator.evaluateResponse(new PlainTextAuthProvider(ROLE_B.getRoleName(), "ignored").newAuthenticator((EndPoint) null, null).initialResponse());
    startJMXServer();
}
Also used : PasswordAuthenticator(org.apache.cassandra.auth.PasswordAuthenticator) IRoleManager(org.apache.cassandra.auth.IRoleManager) PlainTextAuthProvider(com.datastax.driver.core.PlainTextAuthProvider) BeforeClass(org.junit.BeforeClass)

Example 4 with PlainTextAuthProvider

use of com.datastax.driver.core.PlainTextAuthProvider in project beam by apache.

the class CassandraIO method getCluster.

/**
 * Get a Cassandra cluster using hosts and port.
 */
static Cluster getCluster(ValueProvider<List<String>> hosts, ValueProvider<Integer> port, ValueProvider<String> username, ValueProvider<String> password, ValueProvider<String> localDc, ValueProvider<String> consistencyLevel, ValueProvider<Integer> connectTimeout, ValueProvider<Integer> readTimeout) {
    Cluster.Builder builder = Cluster.builder().addContactPoints(hosts.get().toArray(new String[0])).withPort(port.get());
    if (username != null) {
        builder.withAuthProvider(new PlainTextAuthProvider(username.get(), password.get()));
    }
    DCAwareRoundRobinPolicy.Builder dcAwarePolicyBuilder = new DCAwareRoundRobinPolicy.Builder();
    if (localDc != null) {
        dcAwarePolicyBuilder.withLocalDc(localDc.get());
    }
    builder.withLoadBalancingPolicy(new TokenAwarePolicy(dcAwarePolicyBuilder.build()));
    if (consistencyLevel != null) {
        builder.withQueryOptions(new QueryOptions().setConsistencyLevel(ConsistencyLevel.valueOf(consistencyLevel.get())));
    }
    SocketOptions socketOptions = new SocketOptions();
    builder.withSocketOptions(socketOptions);
    if (connectTimeout != null) {
        socketOptions.setConnectTimeoutMillis(connectTimeout.get());
    }
    if (readTimeout != null) {
        socketOptions.setReadTimeoutMillis(readTimeout.get());
    }
    return builder.build();
}
Also used : DCAwareRoundRobinPolicy(com.datastax.driver.core.policies.DCAwareRoundRobinPolicy) SocketOptions(com.datastax.driver.core.SocketOptions) Cluster(com.datastax.driver.core.Cluster) PlainTextAuthProvider(com.datastax.driver.core.PlainTextAuthProvider) TokenAwarePolicy(com.datastax.driver.core.policies.TokenAwarePolicy) QueryOptions(com.datastax.driver.core.QueryOptions)

Example 5 with PlainTextAuthProvider

use of com.datastax.driver.core.PlainTextAuthProvider in project cassandra by apache.

the class CredentialsCacheKeysTableTest method cachePermissions.

private void cachePermissions(RoleResource roleResource) {
    IAuthenticator.SaslNegotiator saslNegotiator = passwordAuthenticator.newSaslNegotiator(null);
    saslNegotiator.evaluateResponse(new PlainTextAuthProvider(roleResource.getRoleName(), "ignored").newAuthenticator((EndPoint) null, null).initialResponse());
    saslNegotiator.getAuthenticatedUser();
}
Also used : IAuthenticator(org.apache.cassandra.auth.IAuthenticator) PlainTextAuthProvider(com.datastax.driver.core.PlainTextAuthProvider)

Aggregations

PlainTextAuthProvider (com.datastax.driver.core.PlainTextAuthProvider)6 Cluster (com.datastax.driver.core.Cluster)2 QueryOptions (com.datastax.driver.core.QueryOptions)2 Authenticator (com.datastax.driver.core.Authenticator)1 PoolingOptions (com.datastax.driver.core.PoolingOptions)1 SocketOptions (com.datastax.driver.core.SocketOptions)1 DCAwareRoundRobinPolicy (com.datastax.driver.core.policies.DCAwareRoundRobinPolicy)1 ExponentialReconnectionPolicy (com.datastax.driver.core.policies.ExponentialReconnectionPolicy)1 TokenAwarePolicy (com.datastax.driver.core.policies.TokenAwarePolicy)1 IAuthenticator (org.apache.cassandra.auth.IAuthenticator)1 IRoleManager (org.apache.cassandra.auth.IRoleManager)1 PasswordAuthenticator (org.apache.cassandra.auth.PasswordAuthenticator)1 SaslNegotiator (org.apache.cassandra.auth.PasswordAuthenticator.SaslNegotiator)1 BeforeClass (org.junit.BeforeClass)1