From 706612e300ffc039ee35c07601cb60dab0486945 Mon Sep 17 00:00:00 2001 From: Aleksey Yeschenko Date: Mon, 17 Dec 2012 18:35:31 +0300 Subject: [PATCH 1/2] Fix SimpleAuthorizer example; patch by Aleksey Yeschenko, reviewed by Jonathan Ellis for CASSANDRA-5072 --- CHANGES.txt | 1 + .../org/apache/cassandra/auth/SimpleAuthorizer.java | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 327d42795c..520cf08440 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -5,6 +5,7 @@ Merged from 1.1: * fix temporarily missing schema after upgrade from pre-1.1.5 (CASSANDRA-5061) * Fix ALTER TABLE overriding compression options with defaults (CASSANDRA-4996, CASSANDRA-5066) + * Fix SimpleAuthorizer example (CASSANDRA-5072) 1.2-rc1 diff --git a/examples/simple_authentication/src/org/apache/cassandra/auth/SimpleAuthorizer.java b/examples/simple_authentication/src/org/apache/cassandra/auth/SimpleAuthorizer.java index 2d7b6442de..df626547a6 100644 --- a/examples/simple_authentication/src/org/apache/cassandra/auth/SimpleAuthorizer.java +++ b/examples/simple_authentication/src/org/apache/cassandra/auth/SimpleAuthorizer.java @@ -41,10 +41,10 @@ public class SimpleAuthorizer extends LegacyAuthorizer public EnumSet authorize(AuthenticatedUser user, List resource) { if (resource.size() < 2 || !Resources.ROOT.equals(resource.get(0)) || !Resources.KEYSPACES.equals(resource.get(1))) - return EnumSet.copyOf(Permission.NONE); + return EnumSet.noneOf(Permission.class); String keyspace, columnFamily = null; - EnumSet authorized = EnumSet.copyOf(Permission.NONE); + EnumSet authorized = EnumSet.noneOf(Permission.class); // /cassandra/keyspaces if (resource.size() == 2) @@ -82,7 +82,7 @@ public class SimpleAuthorizer extends LegacyAuthorizer { String kspAdmins = accessProperties.getProperty(KEYSPACES_WRITE_PROPERTY); for (String admin : kspAdmins.split(",")) - if (admin.equals(user.username)) + if (admin.equals(user.getName())) return EnumSet.copyOf(Permission.ALL); } @@ -104,7 +104,7 @@ public class SimpleAuthorizer extends LegacyAuthorizer { for (String reader : readers.split(",")) { - if (reader.equals(user.username)) + if (reader.equals(user.getName())) { canRead = true; break; @@ -116,7 +116,7 @@ public class SimpleAuthorizer extends LegacyAuthorizer { for (String writer : writers.split(",")) { - if (writer.equals(user.username)) + if (writer.equals(user.getName())) { canWrite = true; break; From 63902c6d824a059d2f8901c7b3ca3bf727fb5641 Mon Sep 17 00:00:00 2001 From: Aleksey Yeschenko Date: Mon, 17 Dec 2012 18:39:18 +0300 Subject: [PATCH 2/2] cqlsh: force CL.ONE for tracing and system.schema* queries; patch by Aleksey Yeschenko, reviewed by Jonathan Ellis for CASSANDRA-5070 --- CHANGES.txt | 1 + bin/cqlsh | 12 +++++++++--- pylib/cqlshlib/tracing.py | 6 ++++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 520cf08440..26097f8d67 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -6,6 +6,7 @@ Merged from 1.1: * Fix ALTER TABLE overriding compression options with defaults (CASSANDRA-4996, CASSANDRA-5066) * Fix SimpleAuthorizer example (CASSANDRA-5072) + * cqlsh: force CL.ONE for tracing and system.schema* queries (CASSANDRA-5070) 1.2-rc1 diff --git a/bin/cqlsh b/bin/cqlsh index f74dc424f1..e234e1087f 100755 --- a/bin/cqlsh +++ b/bin/cqlsh @@ -743,7 +743,9 @@ class Shell(cmd.Cmd): else: cf_q = """select "columnfamily" from system.schema_columnfamilies where "keyspace"=:ks""" - self.cursor.execute(cf_q, {'ks': self.cql_unprotect_name(ksname)}) + self.cursor.execute(cf_q, + {'ks': self.cql_unprotect_name(ksname)}, + consistency_level='ONE') return [str(row[0]) for row in self.cursor.fetchall()] def get_columnfamily_layout(self, ksname, cfname): @@ -759,11 +761,15 @@ class Shell(cmd.Cmd): where "keyspace"=:ks and "columnfamily"=:cf""" col_q = """select * from system.schema_columns where "keyspace"=:ks and "columnfamily"=:cf""" - self.cursor.execute(cf_q, {'ks': ksname, 'cf': cfname}) + self.cursor.execute(cf_q, + {'ks': ksname, 'cf': cfname}, + consistency_level='ONE') layout = self.fetchdict() if layout is None: raise ColumnFamilyNotFound("Column family %r not found" % cfname) - self.cursor.execute(col_q, {'ks': ksname, 'cf': cfname}) + self.cursor.execute(col_q, + {'ks': ksname, 'cf': cfname}, + consistency_level='ONE') cols = self.fetchdict_all() return cql3handling.CqlTableDef.from_layout(layout, cols) diff --git a/pylib/cqlshlib/tracing.py b/pylib/cqlshlib/tracing.py index 5897c2724f..9cbea92d6c 100644 --- a/pylib/cqlshlib/tracing.py +++ b/pylib/cqlshlib/tracing.py @@ -40,12 +40,14 @@ def print_trace_session(shell, cursor, session_id): def fetch_trace_session(cursor, session_id): cursor.execute("SELECT request, coordinator, started_at, duration " "FROM %s.%s " - "WHERE session_id = '%s'" % (TRACING_KS, SESSIONS_CF, session_id)) + "WHERE session_id = '%s'" % (TRACING_KS, SESSIONS_CF, session_id), + consistency_level='ONE') (request, coordinator, started_at, duration) = cursor.fetchone() cursor.execute("SELECT activity, event_id, source, source_elapsed " "FROM %s.%s " - "WHERE session_id = '%s'" % (TRACING_KS, EVENTS_CF, session_id)) + "WHERE session_id = '%s'" % (TRACING_KS, EVENTS_CF, session_id), + consistency_level='ONE') events = cursor.fetchall() rows = []