modules/common/cassandra-auth/src/main/java/org/rhq/cassandra/auth/SimpleAuthenticator.java
| 92 ++++------
modules/common/cassandra-auth/src/main/java/org/rhq/cassandra/auth/SimpleAuthorizer.java
| 6
modules/common/cassandra-common/pom.xml
| 2
modules/common/cassandra-common/src/main/java/org/rhq/cassandra/BootstrapDeployer.java
| 2
modules/common/cassandra-common/src/main/java/org/rhq/cassandra/DeploymentOptions.java
| 24 ++
modules/common/cassandra-common/src/main/resources/.DS_Store
|binary
modules/common/cassandra-common/src/main/resources/cassandra.properties
| 2
modules/common/cassandra-common/src/main/resources/cassandra/conf/access.properties
| 2
modules/common/cassandra-common/src/main/resources/cassandra/conf/cassandra.yaml
| 10 -
modules/common/cassandra-common/src/main/resources/cassandra/conf/passwd.properties
| 2
modules/common/cassandra-schema/src/main/java/org/rhq/cassandra/schema/SchemaManager.java
| 7
pom.xml
| 2
12 files changed, 83 insertions(+), 68 deletions(-)
New commits:
commit ea986a36b4c04314156859f05f7fc99d845e5167
Author: John Sanda <jsanda(a)redhat.com>
Date: Sat Dec 15 08:08:00 2012 -0500
upgrading to cassandra 1.2.0-rc1
This commit includes some necessary authentication changes. passwd.properties
now specifies the root user, cassandra. When creating the schema, we now first
execute a CREATE USER statement to create the rhqadmin user. We need to do this
before we run liquibase.
Neither the datastax driver nor the cassandra-jdbc driver libraries have been
updated upstream yet to use RC1 so the build_deps.sh script will have to be
temporarily updated to build those libraries against RC1. I will make that
change in a subsequet commit.
diff --git
a/modules/common/cassandra-auth/src/main/java/org/rhq/cassandra/auth/SimpleAuthenticator.java
b/modules/common/cassandra-auth/src/main/java/org/rhq/cassandra/auth/SimpleAuthenticator.java
index 5a340cd..d1bfbc0 100644
---
a/modules/common/cassandra-auth/src/main/java/org/rhq/cassandra/auth/SimpleAuthenticator.java
+++
b/modules/common/cassandra-auth/src/main/java/org/rhq/cassandra/auth/SimpleAuthenticator.java
@@ -34,122 +34,108 @@ import java.util.Map;
import java.util.Properties;
import org.apache.cassandra.auth.AuthenticatedUser;
-import org.apache.cassandra.auth.IAuthenticator;
+import org.apache.cassandra.auth.LegacyAuthenticator;
+import org.apache.cassandra.exceptions.AuthenticationException;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.io.util.FileUtils;
-import org.apache.cassandra.thrift.AuthenticationException;
import org.apache.cassandra.utils.FBUtilities;
import org.apache.cassandra.utils.Hex;
/**
* @author John Sanda
*/
-public class SimpleAuthenticator implements IAuthenticator {
+public class SimpleAuthenticator extends LegacyAuthenticator {
public final static String PASSWD_FILENAME_PROPERTY = "passwd.properties";
public final static String PMODE_PROPERTY = "passwd.mode";
- public static final String USERNAME_KEY = "username";
- public static final String PASSWORD_KEY = "password";
- public enum PasswordMode {PLAIN, MD5}
+ public enum PasswordMode {
+ PLAIN, MD5,
+ }
- public AuthenticatedUser defaultUser()
- {
+ public AuthenticatedUser defaultUser() {
// users must log in
return null;
}
- public AuthenticatedUser authenticate(Map<? extends CharSequence,? extends
CharSequence> credentials) throws AuthenticationException
- {
+ public AuthenticatedUser authenticate(Map<String, String> credentials) throws
AuthenticationException {
String pmode_plain = System.getProperty(PMODE_PROPERTY);
PasswordMode mode = PasswordMode.PLAIN;
- if (pmode_plain != null)
- {
- try
- {
+ if (pmode_plain != null) {
+ try {
mode = PasswordMode.valueOf(pmode_plain);
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
// this is not worth a StringBuffer
String mode_values = "";
for (PasswordMode pm : PasswordMode.values())
mode_values += "'" + pm + "', ";
mode_values += "or leave it unspecified.";
- throw new AuthenticationException("The requested password check mode
'" + pmode_plain + "' is not a valid mode. Possible values are " +
mode_values);
+ throw new AuthenticationException(
+ "The requested password check mode '" + pmode_plain +
+ "' is not a valid mode. Possible values are " +
mode_values);
}
}
String pfilename = System.getProperty(PASSWD_FILENAME_PROPERTY);
- String username = null;
- CharSequence user = credentials.get(USERNAME_KEY);
- if (user == null)
- throw new AuthenticationException("Authentication request was missing
the required key '" + USERNAME_KEY + "'");
- else
- username = user.toString();
+ String username = credentials.get(USERNAME_KEY);
+ if (username == null)
+ throw new AuthenticationException(
+ "Authentication request was missing the required key '" +
USERNAME_KEY + "'");
- String password = null;
- CharSequence pass = credentials.get(PASSWORD_KEY);
- if (pass == null)
- throw new AuthenticationException("Authentication request was missing
the required key '" + PASSWORD_KEY + "'");
- else
- password = pass.toString();
+ String password = credentials.get(PASSWORD_KEY);
+ if (password == null)
+ throw new AuthenticationException(
+ "Authentication request was missing the required key '" +
PASSWORD_KEY + "'");
boolean authenticated = false;
InputStream in = null;
- try
- {
+ try {
in = new BufferedInputStream(new FileInputStream(pfilename));
Properties props = new Properties();
props.load(in);
// note we keep the message here and for the wrong password exactly the same
to prevent attackers from guessing what users are valid
- if (props.getProperty(username) == null) throw new
AuthenticationException(authenticationErrorMessage(mode, username));
- switch (mode)
- {
+ if (props.getProperty(username) == null) throw new AuthenticationException(
+ authenticationErrorMessage(mode, username));
+ switch (mode) {
case PLAIN:
authenticated = password.equals(props.getProperty(username));
break;
case MD5:
- authenticated =
MessageDigest.isEqual(FBUtilities.threadLocalMD5Digest().digest(password.getBytes()),
Hex.hexToBytes(props.getProperty(username)));
+ authenticated =
MessageDigest.isEqual(FBUtilities.threadLocalMD5Digest().digest(password.getBytes()),
+ Hex.hexToBytes(props.getProperty(username)));
break;
default:
throw new RuntimeException("Unknown PasswordMode " + mode);
}
- }
- catch (IOException e)
- {
- throw new RuntimeException("Authentication table file given by property
" + PASSWD_FILENAME_PROPERTY + " could not be opened: " + e.getMessage());
- }
- catch (Exception e)
- {
+ } catch (IOException e) {
+ throw new RuntimeException(
+ "Authentication table file given by property " +
PASSWD_FILENAME_PROPERTY + " could not be opened: " +
+ e.getMessage());
+ } catch (Exception e) {
throw new RuntimeException("Unexpected authentication problem",
e);
- }
- finally
- {
+ } finally {
FileUtils.closeQuietly(in);
}
- if (!authenticated) throw new
AuthenticationException(authenticationErrorMessage(mode, username));
+ if (!authenticated) throw new AuthenticationException(
+ authenticationErrorMessage(mode, username));
return new AuthenticatedUser(username);
}
- public void validateConfiguration() throws ConfigurationException
- {
+ public void validateConfiguration() throws ConfigurationException {
String pfilename =
System.getProperty(SimpleAuthenticator.PASSWD_FILENAME_PROPERTY);
- if (pfilename == null)
- {
+ if (pfilename == null) {
throw new ConfigurationException("When using " +
this.getClass().getCanonicalName() + " " +
SimpleAuthenticator.PASSWD_FILENAME_PROPERTY + " properties must be
defined.");
}
}
- static String authenticationErrorMessage(PasswordMode mode, String username)
- {
+ static String authenticationErrorMessage(PasswordMode mode, String username) {
return String.format("Given password in password mode %s could not be
validated for user %s", mode, username);
}
diff --git
a/modules/common/cassandra-auth/src/main/java/org/rhq/cassandra/auth/SimpleAuthorizer.java
b/modules/common/cassandra-auth/src/main/java/org/rhq/cassandra/auth/SimpleAuthorizer.java
index 7305660..d759a5a 100644
---
a/modules/common/cassandra-auth/src/main/java/org/rhq/cassandra/auth/SimpleAuthorizer.java
+++
b/modules/common/cassandra-auth/src/main/java/org/rhq/cassandra/auth/SimpleAuthorizer.java
@@ -87,7 +87,7 @@ public class SimpleAuthorizer extends LegacyAuthorizer {
if (keyspace == KEYSPACES_WRITE_PROPERTY) {
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 {
if (readers != null) {
for (String reader : readers.split(",")) {
- if (reader.equals(user.username)) {
+ if (reader.equals(user.getName())) {
canRead = true;
break;
}
@@ -113,7 +113,7 @@ public class SimpleAuthorizer extends LegacyAuthorizer {
if (writers != null) {
for (String writer : writers.split(",")) {
- if (writer.equals(user.username)) {
+ if (writer.equals(user.getName())) {
canWrite = true;
break;
}
diff --git a/modules/common/cassandra-common/pom.xml
b/modules/common/cassandra-common/pom.xml
index 78d25bf..7585267 100644
--- a/modules/common/cassandra-common/pom.xml
+++ b/modules/common/cassandra-common/pom.xml
@@ -13,7 +13,7 @@
<name>RHQ Cassandra Common</name>
<properties>
- <cassandra.version>1.2.0-beta3</cassandra.version>
+ <cassandra.version>1.2.0-rc1</cassandra.version>
<local.repo>${settings.localRepository}</local.repo>
</properties>
diff --git
a/modules/common/cassandra-common/src/main/java/org/rhq/cassandra/BootstrapDeployer.java
b/modules/common/cassandra-common/src/main/java/org/rhq/cassandra/BootstrapDeployer.java
index ed8e578..0ab1346 100644
---
a/modules/common/cassandra-common/src/main/java/org/rhq/cassandra/BootstrapDeployer.java
+++
b/modules/common/cassandra-common/src/main/java/org/rhq/cassandra/BootstrapDeployer.java
@@ -125,6 +125,8 @@ public class BootstrapDeployer {
}
props.put("rhq.cassandra.node.num_tokens",
deploymentOptions.getNumTokens());
+ props.put("rhq.cassandra.authenticator",
deploymentOptions.getAuthenticator());
+ props.put("rhq.cassandra.authorizer",
deploymentOptions.getAuthorizer());
doLocalDeploy(props, bundleDir);
startNode(nodeBasedir);
diff --git
a/modules/common/cassandra-common/src/main/java/org/rhq/cassandra/DeploymentOptions.java
b/modules/common/cassandra-common/src/main/java/org/rhq/cassandra/DeploymentOptions.java
index ef1e29a..96211f3 100644
---
a/modules/common/cassandra-common/src/main/java/org/rhq/cassandra/DeploymentOptions.java
+++
b/modules/common/cassandra-common/src/main/java/org/rhq/cassandra/DeploymentOptions.java
@@ -53,6 +53,8 @@ public class DeploymentOptions {
private Integer nativeTransportMaxThreads;
private String username;
private String password;
+ private String authenticator;
+ private String authorizer;
public DeploymentOptions() {
}
@@ -102,6 +104,8 @@ public class DeploymentOptions {
properties)));
setUsername(loadProperty("rhq.cassandra.username", properties));
setPassword(loadProperty("rhq.cassandra.password", properties));
+ setAuthenticator(loadProperty("rhq.cassandra.authenticator",
properties));
+ setAuthorizer(loadProperty("rhq.cassandra.authorizer", properties));
}
private String loadProperty(String key, Properties properties) {
@@ -252,4 +256,24 @@ public class DeploymentOptions {
}
}
+ public String getAuthenticator() {
+ return authenticator;
+ }
+
+ public void setAuthenticator(String authenticator) {
+ if (this.authenticator == null) {
+ this.authenticator = authenticator;
+ }
+ }
+
+ public String getAuthorizer() {
+ return authorizer;
+ }
+
+ public void setAuthorizer(String authorizer) {
+ if (this.authorizer == null) {
+ this.authorizer = authorizer;
+ }
+ }
+
}
diff --git a/modules/common/cassandra-common/src/main/resources/.DS_Store
b/modules/common/cassandra-common/src/main/resources/.DS_Store
new file mode 100644
index 0000000..856cdc6
Binary files /dev/null and b/modules/common/cassandra-common/src/main/resources/.DS_Store
differ
diff --git a/modules/common/cassandra-common/src/main/resources/cassandra.properties
b/modules/common/cassandra-common/src/main/resources/cassandra.properties
index 639894e..fb844da 100644
--- a/modules/common/cassandra-common/src/main/resources/cassandra.properties
+++ b/modules/common/cassandra-common/src/main/resources/cassandra.properties
@@ -28,10 +28,12 @@ rhq.cassandra.num-tokens=256
# A class that performs authentication. The value should be a fully qualified class name
# and implement IAuthenticator.
rhq.cassandra.authenticator=org.rhq.cassandra.auth.SimpleAuthenticator
+#rhq.cassandra.authenticator=org.apache.cassandra.auth.AllowAllAuthenticator
# A class that performs authorization. Used to limit/provide permissions. The value
should
# be a fully qualified class name and implement IAuthorizer.
rhq.cassandra.authorizer=org.rhq.cassandra.auth.SimpleAuthorizer
+#rhq.cassandra.authorizer=org.apache.cassandra.auth.AllowAllAuthorizer
# The location of the password properties file used by SimpleAuthenticator. If a
relative
# path is specified, its location is resolved relative to Cassandra's bin directory.
diff --git
a/modules/common/cassandra-common/src/main/resources/cassandra/conf/access.properties
b/modules/common/cassandra-common/src/main/resources/cassandra/conf/access.properties
index 43b74bd..4465450 100644
--- a/modules/common/cassandra-common/src/main/resources/cassandra/conf/access.properties
+++ b/modules/common/cassandra-common/src/main/resources/cassandra/conf/access.properties
@@ -29,7 +29,7 @@
# The magical '<modify-keyspaces>' property lists users who can modify the
# list of keyspaces: all users will be able to view the list of keyspaces.
-<modify-keyspaces>=rhqadmin
+<modify-keyspaces>=cassandra
# Access to Keyspace1 (add/remove column families, etc).
Keyspace1.<ro>=jsmith,Elvis Presley
diff --git
a/modules/common/cassandra-common/src/main/resources/cassandra/conf/cassandra.yaml
b/modules/common/cassandra-common/src/main/resources/cassandra/conf/cassandra.yaml
index af89647..9a5d7fd 100644
--- a/modules/common/cassandra-common/src/main/resources/cassandra/conf/cassandra.yaml
+++ b/modules/common/cassandra-common/src/main/resources/cassandra/conf/cassandra.yaml
@@ -449,18 +449,18 @@ compaction_preheat_key_cache: true
# stream_throughput_outbound_megabits_per_sec: 400
# How long the coordinator should wait for read operations to complete
-read_rpc_timeout_in_ms: 10000
+read_request_timeout_in_ms: 10000
# How long the coordinator should wait for seq or index scans to complete
-range_rpc_timeout_in_ms: 10000
+range_request_timeout_in_ms: 10000
# How long the coordinator should wait for writes to complete
-write_rpc_timeout_in_ms: 10000
+write_request_timeout_in_ms: 10000
# How long the coordinator should wait for truncates to complete
# (This can be much longer, because we need to flush all CFs
# to make sure we can clear out anythink in the commitlog that could
# cause truncated data to reappear.)
-truncate_rpc_timeout_in_ms: 300000
+truncate_request_timeout_in_ms: 60000
# The default timeout for other, miscellaneous operations
-rpc_timeout_in_ms: 10000
+request_timeout_in_ms: 10000
# Enable operation timeout information exchange between nodes to accurately
# measure request timeouts, If disabled cassandra will assuming the request
diff --git
a/modules/common/cassandra-common/src/main/resources/cassandra/conf/passwd.properties
b/modules/common/cassandra-common/src/main/resources/cassandra/conf/passwd.properties
index f8b374c..e6c3d9b 100644
--- a/modules/common/cassandra-common/src/main/resources/cassandra/conf/passwd.properties
+++ b/modules/common/cassandra-common/src/main/resources/cassandra/conf/passwd.properties
@@ -19,5 +19,5 @@
# is represented as an md5 digest, otherwise it is cleartext (keep this
# in mind when setting file mode and ownership).
-#jsmith=havebadpass
+cassandra=cassandra
@@rhq.cassandra.username@@=@@rhq.cassandra.password(a)@
diff --git
a/modules/common/cassandra-schema/src/main/java/org/rhq/cassandra/schema/SchemaManager.java
b/modules/common/cassandra-schema/src/main/java/org/rhq/cassandra/schema/SchemaManager.java
index ecc6a5f..c2fea6c 100644
---
a/modules/common/cassandra-schema/src/main/java/org/rhq/cassandra/schema/SchemaManager.java
+++
b/modules/common/cassandra-schema/src/main/java/org/rhq/cassandra/schema/SchemaManager.java
@@ -62,7 +62,7 @@ public class SchemaManager {
this.hosts = hosts;
SimpleAuthInfoProvider authInfoProvider = new SimpleAuthInfoProvider();
- authInfoProvider.add("username",
"rhqadmin").add("password", "rhqadmin");
+ authInfoProvider.add("username",
"cassandra").add("password", "cassandra");
Cluster cluster = Cluster.builder()
.addContactPoints("127.0.0.1", "127.0.0.2")
@@ -76,8 +76,9 @@ public class SchemaManager {
public void createSchema() {
try {
- String cql = "CREATE KEYSPACE rhq WITH replication = {'class':
'SimpleStrategy', 'replication_factor': 1};";
- session.execute(cql);
+ session.execute("CREATE USER rhqadmin SUPERUSER");
+ session.execute(
+ "CREATE KEYSPACE rhq WITH replication = {'class':
'SimpleStrategy', 'replication_factor': 1};");
} catch (NoHostAvailableException e) {
throw new RuntimeException(e);
}
diff --git a/pom.xml b/pom.xml
index ef4b4ed..a593cf1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -149,7 +149,7 @@
<opencsv.version>1.8</opencsv.version>
<!-- cassandra dependency versions -->
- <cassandra.version>1.2.0-beta3</cassandra.version>
+ <cassandra.version>1.2.0-rc1</cassandra.version>
<cassandra.thrift.version>0.7.0</cassandra.thrift.version>
<cassandra.jdbc.version>1.2.0-SNAPSHOT</cassandra.jdbc.version>
<!--