public void Authenticator_InitialResponse_With_DseAuthenticator_Should_Return_Mechanism()
        {
            var authProvider = new DsePlainTextAuthProvider("u", "p");

            authProvider.SetName(DsePlainTextAuthProviderTests.DseAuthenticatorName);
            var authenticator = authProvider.NewAuthenticator(null);

            CollectionAssert.AreEqual(Encoding.UTF8.GetBytes("PLAIN"), authenticator.InitialResponse());
        }
        public void Authenticator_InitialResponse_With_Other_Authenticator_Should_Return_Credentials()
        {
            var authProvider = new DsePlainTextAuthProvider("u", "p");

            authProvider.SetName("org.other.authenticator");
            var authenticator = authProvider.NewAuthenticator(null);

            CollectionAssert.AreEqual(
                new byte[] { 0, Encoding.UTF8.GetBytes("u")[0], 0, Encoding.UTF8.GetBytes("p")[0] },
                authenticator.InitialResponse());
        }
        public void Should_Authenticate_Against_Dse_Daemon_With_PasswordAuthenticator()
        {
            CcmHelper.Start(
                1,
                cassYamlOptions: new[] { "authenticator: PasswordAuthenticator" },
                jvmArgs: new[] { "-Dcassandra.superuser_setup_delay_ms=0" });
            Trace.TraceInformation("Waiting additional time for test Cluster to be ready");
            Thread.Sleep(15000);
            var authProvider = new DsePlainTextAuthProvider("cassandra", "cassandra");

            using (var cluster = Cluster.Builder()
                                 .AddContactPoint(CcmHelper.InitialContactPoint)
                                 .WithAuthProvider(authProvider)
                                 .Build())
            {
                var session = cluster.Connect();
                AssertCanQuery(session);
            }
        }
        public void Should_Authenticate_Against_Dse_5_DseAuthenticator()
        {
            CcmHelper.Start(
                1,
                new[] { "authentication_options.default_scheme: internal" },
                new[] { "authenticator: com.datastax.bdp.cassandra.auth.DseAuthenticator" },
                new[] { "-Dcassandra.superuser_setup_delay_ms=0" });
            Trace.TraceInformation("Waiting additional time for test Cluster to be ready");
            Thread.Sleep(15000);
            var authProvider = new DsePlainTextAuthProvider("cassandra", "cassandra");

            using (var cluster = Cluster.Builder()
                                 .AddContactPoint(CcmHelper.InitialContactPoint)
                                 .WithAuthProvider(authProvider)
                                 .Build())
            {
                var session = cluster.Connect();
                AssertCanQuery(session);
            }
        }
Exemplo n.º 5
0
        public void OneTimeSetUp()
        {
            _testCluster = TestClusterManager.CreateNew(1, new TestClusterOptions
            {
                CassandraYaml = new[]
                {
                    "authenticator: com.datastax.bdp.cassandra.auth.DseAuthenticator",
                    "authorizer:com.datastax.bdp.cassandra.auth.DseAuthorizer"
                },
                DseYaml = new []
                {
                    "authentication_options.default_scheme: internal",
                    "authorization_options.enabled:true",
                    "authentication_options.enabled:true",
                    "audit_logging_options.enabled:true"
                },
                JvmArgs = new[] { "-Dcassandra.superuser_setup_delay_ms=0" }
            });
            var authProvider = new DsePlainTextAuthProvider("cassandra", "cassandra");

            using (var cluster = Cluster.Builder()
                                 .AddContactPoint(_testCluster.InitialContactPoint)
                                 .WithAuthProvider(authProvider)
                                 .Build())
            {
                var session = cluster.Connect();
                var queries = new[]
                {
                    "CREATE ROLE IF NOT EXISTS alice WITH PASSWORD = '******' AND LOGIN = FALSE",
                    "CREATE ROLE IF NOT EXISTS ben WITH PASSWORD = '******' AND LOGIN = TRUE",
                    "CREATE ROLE IF NOT EXISTS '*****@*****.**' WITH LOGIN = TRUE",
                    "CREATE ROLE IF NOT EXISTS '*****@*****.**' WITH PASSWORD = '******' AND LOGIN = TRUE",
                    "CREATE ROLE IF NOT EXISTS steve WITH PASSWORD = '******' AND LOGIN = TRUE",
                    "CREATE ROLE IF NOT EXISTS paul WITH PASSWORD = '******' AND LOGIN = TRUE",
                    "CREATE ROLE IF NOT EXISTS aliceselect WITH PASSWORD = '******' AND LOGIN = FALSE",
                    "CREATE KEYSPACE IF NOT EXISTS aliceks " +
                    "WITH REPLICATION = {'class':'SimpleStrategy', 'replication_factor':'1'}",
                    "CREATE TABLE IF NOT EXISTS aliceks.alicetable (key text PRIMARY KEY, value text)",
                    "INSERT INTO aliceks.alicetable (key, value) VALUES ('hello', 'world')",
                    "GRANT ALL ON KEYSPACE aliceks TO alice",
                    "GRANT SELECT ON KEYSPACE aliceks TO aliceselect",
                    "GRANT EXECUTE ON ALL AUTHENTICATION SCHEMES TO 'ben'",
                    "GRANT EXECUTE ON ALL AUTHENTICATION SCHEMES TO '*****@*****.**'",
                    "GRANT EXECUTE ON ALL AUTHENTICATION SCHEMES TO 'steve'",
                    "GRANT EXECUTE ON ALL AUTHENTICATION SCHEMES TO '*****@*****.**'",
                    "GRANT EXECUTE ON ALL AUTHENTICATION SCHEMES TO 'aliceselect'",
                    "GRANT PROXY.LOGIN ON ROLE 'alice' TO 'ben'",
                    "GRANT PROXY.LOGIN ON ROLE 'alice' TO '*****@*****.**'",
                    "GRANT PROXY.LOGIN ON ROLE 'alice' TO 'paul'",
                    "GRANT PROXY.EXECUTE ON ROLE 'alice' TO 'steve'",
                    "GRANT PROXY.EXECUTE ON ROLE 'alice' TO '*****@*****.**'",
                    "GRANT PROXY.EXECUTE ON ROLE 'alice' TO 'paul'",
                    "GRANT PROXY.EXECUTE ON ROLE 'aliceselect' TO 'ben'",
                    "GRANT PROXY.EXECUTE ON ROLE 'aliceselect' TO 'steve'",
                };
                foreach (var q in queries)
                {
                    session.Execute(q);
                }
            }
        }