Database Reference
In-Depth Information
TProtocol proto = new TBinaryProtocol(tf);
Cassandra.Client client = new Cassandra.Client(proto);
tr.open();
AuthenticationRequest authRequest = new AuthenticationRequest();
Map<String, String> credentials = new HashMap<String, String>();
credentials.put("username", "jsmith");
credentials.put("password", "havebadpass");
authRequest.setCredentials(credentials);
client.set_keyspace("Keyspace1");
AccessLevel access = client.login(authRequest);
System.out.println("ACCESS LEVEL: " + access);
tr.close();
}
}
In this case, the program just prints out FULL because that's this user's access level.
There are a couple of things to note here. First, the credentials map uses username and pass-
word as keys; it's not username as the key and password as the value. Second, you need to call
set_keyspace separately, to indicate what keyspace you're trying to authenticate to.
Using MD5 Encryption
The SimpleAuthenticator class has two modes for specifying passwords: plain text and MD5
encrypted. So far, we've used the default, plain text. Let's look at how to improve security a bit
by using MD5. MD5 is a cryptographical algorithm that stands for “Message-Digest algorithm
version 5” (the “5” indicates an improvement in strength over version 4). It's a widely used one-
way hash function that generates a 128-bit hash value from an input. It's also worth noting that
MD5 is not going to be radically secure for you; it's just a little harder to break in.
You enable MD5 in the cassandra.in.shile by passing the passwd.mode switch to the JVM:
JVM_OPTS=" \
-da \
//other stuff...
-Dpasswd.mode=MD5"
Now if you try to authenticate using an unencrypted password, you'll see an error like this:
Exception during authentication to the cassandra node, verify you are using correct
credentials.
Search WWH ::




Custom Search